Skip to content

Commit

Permalink
fix: add tests for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pietro-tota committed Aug 10, 2023
1 parent 5c3ff34 commit a480343
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import it.pagopa.generated.ecommerce.helpdesk.model.ProductDto
import org.springframework.http.HttpStatus

class InvalidSearchCriteriaException(searchCriteriaType: String, productDto: ProductDto) :
ApiError("Invalid search criteria with type: $searchCriteriaType for product :$productDto") {
ApiError("Invalid search criteria with type: $searchCriteriaType for product: $productDto") {

override fun toRestException() =
RestApiException(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package it.pagopa.ecommerce.helpdesk.dataproviders.oracle

import it.pagopa.ecommerce.helpdesk.dataproviders.TransactionDataProvider
import it.pagopa.generated.ecommerce.helpdesk.model.*
import java.util.stream.Stream
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource

class TransactionDataProviderTest {

companion object {
@JvmStatic
private fun searchCriteriaMappingTestSource() =
Stream.of(
Arguments.of(SearchTransactionRequestPaymentTokenDto::class.java, "PAYMENT_TOKEN"),
Arguments.of(SearchTransactionRequestRptIdDto::class.java, "RPT_ID"),
Arguments.of(
SearchTransactionRequestTransactionIdDto::class.java,
"TRANSACTION_ID"
),
Arguments.of(SearchTransactionRequestEmailDto::class.java, "USER_EMAIL"),
Arguments.of(SearchTransactionRequestFiscalCodeDto::class.java, "USER_FISCAL_CODE"),
)
}

@ParameterizedTest
@MethodSource("searchCriteriaMappingTestSource")
fun shouldMapSearchCriteriaType(clazz: Class<*>, searchType: String) {
assertEquals(searchType, TransactionDataProvider.SearchTypeMapping.getSearchType(clazz))
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package it.pagopa.ecommerce.helpdesk.exceptionhandler

import it.pagopa.ecommerce.helpdesk.HelpdeskTestUtils
import it.pagopa.ecommerce.helpdesk.exceptions.InvalidSearchCriteriaException
import it.pagopa.ecommerce.helpdesk.exceptions.NoResultFoundException
import it.pagopa.ecommerce.helpdesk.exceptions.RestApiException
import it.pagopa.generated.ecommerce.helpdesk.model.ProductDto
import jakarta.xml.bind.ValidationException
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -34,7 +36,7 @@ class ExceptionHandlerTest {
}

@Test
fun `Should handle ApiError`() {
fun `Should handle NoResultFoundException`() {
val searchCriteria = "searchCriteria"
val exception = NoResultFoundException(searchCriteria)
val response = exceptionHandler.handleException(exception)
Expand Down Expand Up @@ -78,4 +80,21 @@ class ExceptionHandlerTest {
)
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.statusCode)
}

@Test
fun `Should handle InvalidSearchCriteriaException`() {
val searchCriteria = "searchCriteria"
val exception = InvalidSearchCriteriaException(searchCriteria, ProductDto.PM)
val response = exceptionHandler.handleException(exception)
assertEquals(
HelpdeskTestUtils.buildProblemJson(
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR,
title = "Invalid search criteria",
description =
"Invalid search criteria with type: $searchCriteria for product: ${ProductDto.PM}"
),
response.body
)
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.statusCode)
}
}

0 comments on commit a480343

Please sign in to comment.