diff --git a/helm/Chart.yaml b/helm/Chart.yaml index e72170bd..4e4476ce 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-biz-events-service description: Microservice for exposing REST APIs about payment receipts. type: application -version: 0.20.0 -appVersion: 0.1.1 +version: 0.22.0 +appVersion: 0.1.1-2-PAGOPA-1404-sviluppo-modifiche-get-organization-receipt dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 60a5494c..0930ef62 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-biz-events-service - tag: "0.1.1" + tag: "0.1.1-2-PAGOPA-1404-sviluppo-modifiche-get-organization-receipt" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 52b660a2..fd1a27b6 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-biz-events-service - tag: "0.1.1" + tag: "0.1.1-2-PAGOPA-1404-sviluppo-modifiche-get-organization-receipt" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 63289ffe..c059695c 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-biz-events-service - tag: "0.1.1" + tag: "0.1.1-2-PAGOPA-1404-sviluppo-modifiche-get-organization-receipt" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi.json b/openapi/openapi.json index 67a67f39..4cf63c25 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "title": "Biz-Events Service", "description": "Microservice for exposing REST APIs about payment receipts.", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.1.1" + "version": "0.1.1-2-PAGOPA-1404-sviluppo-modifiche-get-organization-receipt" }, "servers": [ { @@ -622,13 +622,153 @@ } ] }, + "/organizations/{organizationfiscalcode}/receipts/{iur}": { + "get": { + "tags": [ + "Payment Receipts REST APIs" + ], + "summary": "The organization get the receipt for the creditor institution using IUR.", + "operationId": "getOrganizationReceiptIur", + "parameters": [ + { + "name": "organizationfiscalcode", + "in": "path", + "description": "The fiscal code of the Organization.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "iur", + "in": "path", + "description": "The unique reference of the operation assigned to the payment (Payment Token).", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "Obtained receipt.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CtReceiptModelResponse" + } + } + } + }, + "401": { + "description": "Wrong or missing function key.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + } + }, + "404": { + "description": "Not found the receipt.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemJson" + } + } + } + }, + "422": { + "description": "Unable to process the request.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemJson" + } + } + } + }, + "429": { + "description": "Too many requests.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + } + }, + "500": { + "description": "Service unavailable.", + "headers": { + "X-Request-Id": { + "description": "This header identifies the call", + "schema": { + "type": "string" + } + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ProblemJson" + } + } + } + } + }, + "security": [ + { + "ApiKey": [] + } + ] + }, + "parameters": [ + { + "name": "X-Request-Id", + "in": "header", + "description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.", + "schema": { + "type": "string" + } + } + ] + }, "/organizations/{organizationfiscalcode}/receipts/{iur}/paymentoptions/{iuv}": { "get": { "tags": [ "Payment Receipts REST APIs" ], - "summary": "The organization get the receipt for the creditor institution.", - "operationId": "getOrganizationReceipt", + "summary": "The organization get the receipt for the creditor institution using IUV and IUR.", + "operationId": "getOrganizationReceiptIuvIur", "parameters": [ { "name": "organizationfiscalcode", @@ -908,24 +1048,15 @@ } }, "Debtor": { - "required": [ - "entityUniqueIdentifierType", - "entityUniqueIdentifierValue", - "fullName" - ], "type": "object", "properties": { - "entityUniqueIdentifierType": { - "type": "string", - "enum": [ - "F", - "G" - ] + "fullName": { + "type": "string" }, - "entityUniqueIdentifierValue": { + "entityUniqueIdentifierType": { "type": "string" }, - "fullName": { + "entityUniqueIdentifierValue": { "type": "string" }, "streetName": { @@ -946,7 +1077,7 @@ "country": { "type": "string" }, - "email": { + "eMail": { "type": "string" } } @@ -963,24 +1094,15 @@ } }, "Payer": { - "required": [ - "entityUniqueIdentifierType", - "entityUniqueIdentifierValue", - "fullName" - ], "type": "object", "properties": { - "entityUniqueIdentifierType": { - "type": "string", - "enum": [ - "F", - "G" - ] + "fullName": { + "type": "string" }, - "entityUniqueIdentifierValue": { + "entityUniqueIdentifierType": { "type": "string" }, - "fullName": { + "entityUniqueIdentifierValue": { "type": "string" }, "streetName": { @@ -1001,7 +1123,7 @@ "country": { "type": "string" }, - "email": { + "eMail": { "type": "string" } } diff --git a/pom.xml b/pom.xml index 3bebdb67..6c70fe17 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa bizeventsservice - 0.1.1 + 0.1.1-2-PAGOPA-1404-sviluppo-modifiche-get-organization-receipt Biz-Events Service Microservice for exposing REST APIs about payment receipts. diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaymentsController.java b/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaymentsController.java index 94ec9cc2..def83f76 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaymentsController.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/controller/IPaymentsController.java @@ -25,8 +25,13 @@ @RequestMapping @Validated public interface IPaymentsController { - - @Operation(summary = "The organization get the receipt for the creditor institution.", security = {@SecurityRequirement(name = "ApiKey")}, operationId = "getOrganizationReceipt") + + // TODO: this API is included in the one using the path /organizations/{organizationfiscalcode}/receipts/{iur}, will be removed + @Deprecated + /** + * @deprecated (API to be removed after the next SANP release) + */ + @Operation(summary = "The organization get the receipt for the creditor institution using IUV and IUR.", security = {@SecurityRequirement(name = "ApiKey")}, operationId = "getOrganizationReceiptIuvIur") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Obtained receipt.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(name = "CtReceipt", implementation = CtReceiptModelResponse.class))), @ApiResponse(responseCode = "401", description = "Wrong or missing function key.", content = @Content(schema = @Schema())), @@ -43,4 +48,20 @@ ResponseEntity getOrganizationReceipt( @NotBlank @PathVariable("iur") String iur, @Parameter(description = "The unique payment identification. Alphanumeric code that uniquely associates and identifies three key elements of a payment: reason, payer, amount", required = true) @NotBlank @PathVariable("iuv") String iuv); + + @Operation(summary = "The organization get the receipt for the creditor institution using IUR.", security = {@SecurityRequirement(name = "ApiKey")}, operationId = "getOrganizationReceiptIur") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Obtained receipt.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(name = "CtReceipt", implementation = CtReceiptModelResponse.class))), + @ApiResponse(responseCode = "401", description = "Wrong or missing function key.", content = @Content(schema = @Schema())), + @ApiResponse(responseCode = "404", description = "Not found the receipt.", content = @Content(schema = @Schema(implementation = ProblemJson.class))), + @ApiResponse(responseCode = "422", description = "Unable to process the request.", content = @Content(schema = @Schema(implementation = ProblemJson.class))), + @ApiResponse(responseCode = "429", description = "Too many requests.", content = @Content(schema = @Schema())), + @ApiResponse(responseCode = "500", description = "Service unavailable.", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))}) + @GetMapping(value = "/organizations/{organizationfiscalcode}/receipts/{iur}", + produces = MediaType.APPLICATION_JSON_VALUE) + ResponseEntity getOrganizationReceipt( + @Parameter(description = "The fiscal code of the Organization.", required = true) + @NotBlank @PathVariable("organizationfiscalcode") String organizationFiscalCode, + @Parameter(description = "The unique reference of the operation assigned to the payment (Payment Token).", required = true) + @NotBlank @PathVariable("iur") String iur); } diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaymentsController.java b/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaymentsController.java index 6bf7a636..2666d226 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaymentsController.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/controller/impl/PaymentsController.java @@ -26,4 +26,12 @@ public ResponseEntity getOrganizationReceipt(@NotBlank S HttpStatus.OK); } + @Override + public ResponseEntity getOrganizationReceipt(@NotBlank String organizationFiscalCode, + @NotBlank String iur) { + return new ResponseEntity<>( + bizEventsService.getOrganizationReceipt(organizationFiscalCode, iur), + HttpStatus.OK); + } + } diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/exception/AppError.java b/src/main/java/it/gov/pagopa/bizeventsservice/exception/AppError.java index fcf51a58..0cd61f5b 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/exception/AppError.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/exception/AppError.java @@ -3,14 +3,19 @@ import lombok.Getter; import org.springframework.http.HttpStatus; +import static it.gov.pagopa.bizeventsservice.util.Constants.BIZ_NOT_FOUND_HEADER; +import static it.gov.pagopa.bizeventsservice.util.Constants.BIZ_NOT_UNIQUE_HEADER; + @Getter public enum AppError { - BIZ_EVENT_NOT_FOUND(HttpStatus.NOT_FOUND, "Biz Event not found", "Not found a biz event for the Organization Fiscal Code %s and IUR %s and IUV %s"), - BIZ_EVENT_NOT_FOUND_WITH_ID(HttpStatus.NOT_FOUND, "Biz Event not found", "Not found a biz event with id %s"), - BIZ_EVENT_NOT_FOUND_WITH_ORG_CF_AND_IUV(HttpStatus.NOT_FOUND, "Biz Event not found", "Not found a biz event for the Organization Fiscal Code %s and IUV %s"), - BIZ_EVENT_NOT_UNIQUE(HttpStatus.UNPROCESSABLE_ENTITY, "Biz Event is not unique", "More than one biz event was found for the Organization Fiscal Code %s and IUR %s and IUV %s"), - BIZ_EVENT_NOT_UNIQUE_WITH_ORG_CF_AND_IUV(HttpStatus.UNPROCESSABLE_ENTITY, "Biz Event is not unique", "More than one biz event was found for the Organization Fiscal Code %s and IUV %s"), + BIZ_EVENT_NOT_FOUND_IUV_IUR(HttpStatus.NOT_FOUND, BIZ_NOT_FOUND_HEADER, "Not found a biz event for the Organization Fiscal Code %s and IUR %s and IUV %s"), + BIZ_EVENT_NOT_FOUND_IUR(HttpStatus.NOT_FOUND, BIZ_NOT_FOUND_HEADER, "Not found a biz event for the Organization Fiscal Code %s and IUR %s"), + BIZ_EVENT_NOT_FOUND_WITH_ID(HttpStatus.NOT_FOUND, BIZ_NOT_FOUND_HEADER, "Not found a biz event with id %s"), + BIZ_EVENT_NOT_FOUND_WITH_ORG_CF_AND_IUV(HttpStatus.NOT_FOUND, BIZ_NOT_FOUND_HEADER, "Not found a biz event for the Organization Fiscal Code %s and IUV %s"), + BIZ_EVENT_NOT_UNIQUE_IUV_IUR(HttpStatus.UNPROCESSABLE_ENTITY, BIZ_NOT_UNIQUE_HEADER, "More than one biz event was found for the Organization Fiscal Code %s and IUR %s and IUV %s"), + BIZ_EVENT_NOT_UNIQUE_IUR(HttpStatus.UNPROCESSABLE_ENTITY, BIZ_NOT_UNIQUE_HEADER, "More than one biz event was found for the Organization Fiscal Code %s and IUR %s"), + BIZ_EVENT_NOT_UNIQUE_WITH_ORG_CF_AND_IUV(HttpStatus.UNPROCESSABLE_ENTITY, BIZ_NOT_UNIQUE_HEADER, "More than one biz event was found for the Organization Fiscal Code %s and IUV %s"), INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", "Something was wrong"); public final HttpStatus httpStatus; diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/repository/BizEventsRepository.java b/src/main/java/it/gov/pagopa/bizeventsservice/repository/BizEventsRepository.java index 4666896c..bc3f606a 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/repository/BizEventsRepository.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/repository/BizEventsRepository.java @@ -15,10 +15,15 @@ public interface BizEventsRepository extends CosmosRepository // TODO when available replace idPa with the paFiscalCode field @Query("select * from c where c.creditor.idPA = @organizationFiscalCode and c.paymentInfo.paymentToken = @iur and c.debtorPosition.iuv = @iuv and StringToNumber(c.debtorPosition.modelType) > 1") - List getBizEventByOrgFiscCodeAndIur(@Param("organizationFiscalCode") String organizationFiscalCode, - @Param("iur") String iur, @Param("iuv") String iuv); + List getBizEventByOrgFiscCodeIuvAndIur(@Param("organizationFiscalCode") String organizationFiscalCode, + @Param("iur") String iur, @Param("iuv") String iuv); @Query("select * from c where c.creditor.idPA = @organizationFiscalCode and c.debtorPosition.iuv = @iuv") List getBizEventByOrgFiscalCodeAndIuv(@Param("organizationFiscalCode") String organizationFiscalCode, @Param("iuv") String iuv); + + @Query("select distinct value c from c JOIN t IN c.transferList where t.fiscalCodePA = @organizationFiscalCode and c.paymentInfo.paymentToken = @iur and StringToNumber(c.debtorPosition.modelType) > 1") + List getBizEventByOrgFiscCodeAndIur(@Param("organizationFiscalCode") String organizationFiscalCode, + @Param("iur") String iur); + } diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/service/IBizEventsService.java b/src/main/java/it/gov/pagopa/bizeventsservice/service/IBizEventsService.java index 6a908948..ea7d7b69 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/service/IBizEventsService.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/service/IBizEventsService.java @@ -12,5 +12,7 @@ CtReceiptModelResponse getOrganizationReceipt(String organizationFiscalCode, BizEvent getBizEventByOrgFiscalCodeAndIuv(String organizationFiscalCode, String iuv); + CtReceiptModelResponse getOrganizationReceipt(String organizationFiscalCode, + String iur); } \ No newline at end of file diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/BizEventsService.java b/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/BizEventsService.java index b1cb0411..b4d86816 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/BizEventsService.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/service/impl/BizEventsService.java @@ -31,15 +31,15 @@ public BizEventsService(BizEventsRepository bizEventsRepository, ModelMapper mod public CtReceiptModelResponse getOrganizationReceipt(String organizationFiscalCode, String iur, String iuv) { // get biz event - List bizEventEntityList = bizEventsRepository.getBizEventByOrgFiscCodeAndIur(organizationFiscalCode, + List bizEventEntityList = bizEventsRepository.getBizEventByOrgFiscCodeIuvAndIur(organizationFiscalCode, iur, iuv); if (bizEventEntityList.isEmpty()) { - throw new AppException(AppError.BIZ_EVENT_NOT_FOUND, organizationFiscalCode, iur, iuv); + throw new AppException(AppError.BIZ_EVENT_NOT_FOUND_IUV_IUR, organizationFiscalCode, iur, iuv); } // the query should always return only one element else if (bizEventEntityList.size() > 1) { - throw new AppException(AppError.BIZ_EVENT_NOT_UNIQUE, organizationFiscalCode, iur, iuv); + throw new AppException(AppError.BIZ_EVENT_NOT_UNIQUE_IUV_IUR, organizationFiscalCode, iur, iuv); } // the bizEventEntityList has only one element @@ -72,4 +72,25 @@ else if (bizEventEntityList.size() > 1) { } return bizEventEntityList.get(0); } + + @Override + public CtReceiptModelResponse getOrganizationReceipt(String organizationFiscalCode, + String iur) { + // get biz event + List bizEventEntityList = bizEventsRepository.getBizEventByOrgFiscCodeAndIur(organizationFiscalCode, + iur); + + if (bizEventEntityList.isEmpty()) { + throw new AppException(AppError.BIZ_EVENT_NOT_FOUND_IUR, organizationFiscalCode, iur); + } + + // the query should always return only one element + else if (bizEventEntityList.size() > 1) { + throw new AppException(AppError.BIZ_EVENT_NOT_UNIQUE_IUR, organizationFiscalCode, iur); + } + + // the bizEventEntityList has only one element + return modelMapper.map(bizEventEntityList.get(0), CtReceiptModelResponse.class); + } + } diff --git a/src/main/java/it/gov/pagopa/bizeventsservice/util/Constants.java b/src/main/java/it/gov/pagopa/bizeventsservice/util/Constants.java index 4f33fd2e..16d3d112 100644 --- a/src/main/java/it/gov/pagopa/bizeventsservice/util/Constants.java +++ b/src/main/java/it/gov/pagopa/bizeventsservice/util/Constants.java @@ -7,5 +7,7 @@ public class Constants { public static final String HEADER_REQUEST_ID = "X-Request-Id"; + public static final String BIZ_NOT_FOUND_HEADER = "Biz Event not found"; + public static final String BIZ_NOT_UNIQUE_HEADER = "Biz Event is not unique"; } diff --git a/src/test/java/it/gov/pagopa/bizeventsservice/controller/PaymentsControllerTest.java b/src/test/java/it/gov/pagopa/bizeventsservice/controller/PaymentsControllerTest.java index 4dd86783..e26a313f 100644 --- a/src/test/java/it/gov/pagopa/bizeventsservice/controller/PaymentsControllerTest.java +++ b/src/test/java/it/gov/pagopa/bizeventsservice/controller/PaymentsControllerTest.java @@ -12,6 +12,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -39,11 +41,15 @@ void setUp() throws IOException { // precondition CtReceiptModelResponse ctReceiptModel = TestUtil.readModelFromFile("receipts/getOrganizationReceipt.json", CtReceiptModelResponse.class); when(bizEventsService.getOrganizationReceipt(anyString(), anyString(), anyString())).thenReturn(ctReceiptModel); + when(bizEventsService.getOrganizationReceipt(anyString(), anyString())).thenReturn(ctReceiptModel); } - @Test - void getOrganizationReceipt() throws Exception { - String url = "/organizations/mock_organizationfiscalcode/receipts/mock_iur/paymentoptions/mock_iuv"; + @ParameterizedTest + @CsvSource({ + "/organizations/mock_organizationfiscalcode/receipts/mock_iur/paymentoptions/mock_iuv", + "/organizations/mock_organizationfiscalcode/receipts/mock_iur" + }) + void getOrganizationReceipt(String url) throws Exception { MvcResult result = mvc.perform(get(url).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) diff --git a/src/test/java/it/gov/pagopa/bizeventsservice/service/BizEventsServiceTest.java b/src/test/java/it/gov/pagopa/bizeventsservice/service/BizEventsServiceTest.java index 9ebfe15e..7fa9e5b6 100644 --- a/src/test/java/it/gov/pagopa/bizeventsservice/service/BizEventsServiceTest.java +++ b/src/test/java/it/gov/pagopa/bizeventsservice/service/BizEventsServiceTest.java @@ -64,8 +64,8 @@ void setUp() { } @Test - void getOrganizationReceipt() { - when(bizEventsRepository.getBizEventByOrgFiscCodeAndIur(ORGANIZATION_FISCAL_CODE, IUR, IUV)) + void getOrganizationReceiptIuvIur() { + when(bizEventsRepository.getBizEventByOrgFiscCodeIuvAndIur(ORGANIZATION_FISCAL_CODE, IUR, IUV)) .thenReturn(List.of(bizEventEntity)); CtReceiptModelResponse ctReceipt = bizEventsService.getOrganizationReceipt(ORGANIZATION_FISCAL_CODE, IUR, @@ -75,8 +75,8 @@ void getOrganizationReceipt() { } @Test - void getOrganizationReceipt_404() throws IOException { - when(bizEventsRepository.getBizEventByOrgFiscCodeAndIur(ORGANIZATION_FISCAL_CODE, IUR, IUV)) + void getOrganizationReceiptIuvIur_404() throws IOException { + when(bizEventsRepository.getBizEventByOrgFiscCodeIuvAndIur(ORGANIZATION_FISCAL_CODE, IUR, IUV)) .thenReturn(List.of(bizEventEntity)); AppException e = assertThrows(AppException.class, () -> bizEventsService.getOrganizationReceipt(ORGANIZATION_FISCAL_CODE, IUR, "fake_iuv")); @@ -84,15 +84,44 @@ void getOrganizationReceipt_404() throws IOException { } @Test - void getOrganizationReceipt_422() throws IOException { + void getOrganizationReceiptIuvIur_422() throws IOException { // mocking a fake save for duplicated entity - when(bizEventsRepository.getBizEventByOrgFiscCodeAndIur(ORGANIZATION_FISCAL_CODE, IUR, IUV)) + when(bizEventsRepository.getBizEventByOrgFiscCodeIuvAndIur(ORGANIZATION_FISCAL_CODE, IUR, IUV)) .thenReturn(List.of(bizEventEntity, bizEventEntityDuplicated)); AppException e = assertThrows(AppException.class, () -> bizEventsService.getOrganizationReceipt(ORGANIZATION_FISCAL_CODE, IUR, IUV)); assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, e.getHttpStatus()); } + @Test + void getOrganizationReceiptIur() { + when(bizEventsRepository.getBizEventByOrgFiscCodeAndIur(ORGANIZATION_FISCAL_CODE, IUR)) + .thenReturn(List.of(bizEventEntity)); + + CtReceiptModelResponse ctReceipt = bizEventsService.getOrganizationReceipt(ORGANIZATION_FISCAL_CODE, IUR); + assertEquals("85570ffebb13411b80d79f415641ec55", ctReceipt.getReceiptId()); + assertEquals("cash", ctReceipt.getPaymentMethod()); + } + + @Test + void getOrganizationReceiptIur_404() throws IOException { + when(bizEventsRepository.getBizEventByOrgFiscCodeAndIur(ORGANIZATION_FISCAL_CODE, IUR)) + .thenReturn(List.of(bizEventEntity)); + + AppException e = assertThrows(AppException.class, () -> bizEventsService.getOrganizationReceipt(ORGANIZATION_FISCAL_CODE,"fake_iur")); + assertEquals(HttpStatus.NOT_FOUND, e.getHttpStatus()); + } + + @Test + void getOrganizationReceiptIur_422() throws IOException { + // mocking a fake save for duplicated entity + when(bizEventsRepository.getBizEventByOrgFiscCodeAndIur(ORGANIZATION_FISCAL_CODE, IUR)) + .thenReturn(List.of(bizEventEntity, bizEventEntityDuplicated)); + + AppException e = assertThrows(AppException.class, () -> bizEventsService.getOrganizationReceipt(ORGANIZATION_FISCAL_CODE, IUR)); + assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, e.getHttpStatus()); + } + @Test void getBizEventSuccess() { when(bizEventsRepository.findById(BIZ_EVENT_ID, new PartitionKey(BIZ_EVENT_ID)))