From 54f55e0f34e7f9834413ec1fe885980102b08281 Mon Sep 17 00:00:00 2001 From: giomella Date: Tue, 9 Jan 2024 10:23:39 +0100 Subject: [PATCH 01/14] [PRDP-291] added integration test for cart apis --- integration-test/src/config/.env.dev | 1 + integration-test/src/config/.env.local | 1 + integration-test/src/config/.env.uat | 1 + .../src/features/receipt_pdf_helpdesk.feature | 21 +++- .../step_definitions/api_helpdesk_client.js | 30 ++++- .../biz_events_datastore_client.js | 31 ++++- .../src/step_definitions/common.js | 46 +++++-- .../receipt_pdf_helpdesk_step.js | 114 +++++++++++++++++- .../receipts_datastore_client.js | 38 +++++- 9 files changed, 262 insertions(+), 21 deletions(-) diff --git a/integration-test/src/config/.env.dev b/integration-test/src/config/.env.dev index 9ab01ef5..e12853bb 100644 --- a/integration-test/src/config/.env.dev +++ b/integration-test/src/config/.env.dev @@ -7,6 +7,7 @@ RECEIPT_COSMOS_DB_NAME=db RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts RECEIPT_ERROR_COSMOS_DB_CONTAINER_NAME=receipts-message-errors RECEIPT_MESSAGE_COSMOS_DB_CONTAINER_NAME=receipts-io-messages +CART_COSMOS_DB_CONTAINER_NAME=cart-for-receipts RECEIPTS_STORAGE_CONN_STRING= BLOB_STORAGE_CONTAINER_NAME=pagopa-d-weu-receipts-azure-blob-receipt-st-attach diff --git a/integration-test/src/config/.env.local b/integration-test/src/config/.env.local index daddf0e8..467bcd0c 100644 --- a/integration-test/src/config/.env.local +++ b/integration-test/src/config/.env.local @@ -7,6 +7,7 @@ RECEIPT_COSMOS_DB_NAME=db RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts RECEIPT_ERROR_COSMOS_DB_CONTAINER_NAME=receipts-message-errors RECEIPT_MESSAGE_COSMOS_DB_CONTAINER_NAME=receipts-io-messages +CART_COSMOS_DB_CONTAINER_NAME=cart-for-receipts RECEIPTS_STORAGE_CONN_STRING= BLOB_STORAGE_CONTAINER_NAME=pagopa-d-weu-receipts-azure-blob-receipt-st-attach diff --git a/integration-test/src/config/.env.uat b/integration-test/src/config/.env.uat index c2decbf0..8a838759 100644 --- a/integration-test/src/config/.env.uat +++ b/integration-test/src/config/.env.uat @@ -7,6 +7,7 @@ RECEIPT_COSMOS_DB_NAME=db RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts RECEIPT_ERROR_COSMOS_DB_CONTAINER_NAME=receipts-message-errors RECEIPT_MESSAGE_COSMOS_DB_CONTAINER_NAME=receipts-io-messages +CART_COSMOS_DB_CONTAINER_NAME=cart-for-receipts RECEIPTS_STORAGE_CONN_STRING= BLOB_STORAGE_CONTAINER_NAME=pagopa-u-weu-receipts-azure-blob-receipt-st-attach diff --git a/integration-test/src/features/receipt_pdf_helpdesk.feature b/integration-test/src/features/receipt_pdf_helpdesk.feature index 78bae37e..5f795e11 100644 --- a/integration-test/src/features/receipt_pdf_helpdesk.feature +++ b/integration-test/src/features/receipt_pdf_helpdesk.feature @@ -76,4 +76,23 @@ Feature: All about payment events to recover managed by Azure functions receipt- Then the api response has a 200 Http status And the receipt with eventId "receipt-helpdesk-int-test-id-10" is recovered from datastore And the receipt has attachment metadata - And the PDF is present on blob storage \ No newline at end of file + And the PDF is present on blob storage + + Scenario: recoverFailedCart API retrieve a cart in status FAILED and updates its status + Given a biz event with transactionId "receipt-helpdesk-int-test-id-11" and status "DONE" stored on biz-events datastore + And a biz event with transactionId "receipt-helpdesk-int-test-id-11" and status "DONE" stored on biz-events datastore + And a cart with id "receipt-helpdesk-int-test-id-11" and status "FAILED" stored into cart datastore + When recoverFailedCart API is called with cartId "receipt-helpdesk-int-test-id-11" + Then the api response has a 200 Http status + And the cart with id "receipt-helpdesk-int-test-id-11" is retrieved from datastore + And the cart has not status "FAILED" + And the receipt with eventId "receipt-helpdesk-int-test-id-11" is recovered from datastore + And the receipt has not status "FAILED" + + Scenario: recoverFailedCartMassive API retrieve all the receipts in status FAILED and updates their status + Given a list of 5 carts in status "FAILED" stored into cart datastore starting from id "receipt-helpdesk-int-test-id-12" + And a list of 10 biz events in status "DONE" stored into biz-events datastore + When recoverFailedCartMassive API is called with status "FAILED" as query param + Then the api response has a 200 Http status + And the list of cart is retrieved from datastore and no cart in the list has status "FAILED" + And the list of receipt is retrieved from datastore and no receipt in the list has status "FAILED" \ No newline at end of file diff --git a/integration-test/src/step_definitions/api_helpdesk_client.js b/integration-test/src/step_definitions/api_helpdesk_client.js index c81b0e0f..c4bf1cfd 100644 --- a/integration-test/src/step_definitions/api_helpdesk_client.js +++ b/integration-test/src/step_definitions/api_helpdesk_client.js @@ -151,6 +151,32 @@ async function postRegenerateReceiptPdf(eventId) { }); } +async function postRecoverFailedCart(cartId) { + let endpoint = process.env.RECOVER_FAILED_CART_ENDPOINT || "carts/{cart-id}/recover-failed"; + endpoint = endpoint.replace("{cart-id}", cartId); + + return await axios.post(helpdesk_url + endpoint, {}) + .then(res => { + return res; + }) + .catch(error => { + return error.response; + }); +} + +async function postRecoverFailedCartMassive(status) { + let endpoint = process.env.RECOVER_FAILED_CART_MASSIVE_ENDPOINT || "carts/recover-failed?status={STATUS}"; + endpoint = endpoint.replace("{STATUS}", status); + + return await axios.post(helpdesk_url + endpoint, {}) + .then(res => { + return res; + }) + .catch(error => { + return error.response; + }); +} + module.exports = { getReceipt, getReceiptByOrganizationFiscalCodeAndIUV, @@ -162,5 +188,7 @@ module.exports = { postRecoverFailedReceiptMassive, postRecoverNotNotifiedReceipt, postRecoverNotNotifiedReceiptMassive, - postRegenerateReceiptPdf + postRegenerateReceiptPdf, + postRecoverFailedCart, + postRecoverFailedCartMassive } \ No newline at end of file diff --git a/integration-test/src/step_definitions/biz_events_datastore_client.js b/integration-test/src/step_definitions/biz_events_datastore_client.js index c553f9ce..8c086fe6 100644 --- a/integration-test/src/step_definitions/biz_events_datastore_client.js +++ b/integration-test/src/step_definitions/biz_events_datastore_client.js @@ -1,5 +1,5 @@ const { CosmosClient } = require("@azure/cosmos"); -const { createEvent } = require("./common"); +const { createEvent, createEventCart, createEventWithIUVAndOrgCode } = require("./common"); const cosmos_db_conn_string = process.env.BIZEVENTS_COSMOS_CONN_STRING; const databaseId = process.env.BIZ_EVENT_COSMOS_DB_NAME; // es. db @@ -17,8 +17,26 @@ async function getDocumentByIdFromBizEventsDatastore(id) { .fetchAll(); } -async function createDocumentInBizEventsDatastore(id, status, orgCode, iuv) { - let event = createEvent(id, status, orgCode, iuv); +async function createDocumentInBizEventsDatastore(id, status) { + let event = createEvent(id, status); + try { + return await container.items.create(event); + } catch (err) { + console.log(err); + } +} + +async function createDocumentInBizEventsDatastoreWithIUVAndOrgCode(id, status, orgCode, iuv) { + let event = createEventWithIUVAndOrgCode(id, status, orgCode, iuv); + try { + return await container.items.create(event); + } catch (err) { + console.log(err); + } +} + +async function createDocumentInBizEventsDatastoreIsCartEvent(id, transactionId, status, totalNotice) { + let event = createEventCart(id, transactionId, status, totalNotice); try { return await container.items.create(event); } catch (err) { @@ -52,5 +70,10 @@ async function deleteAllTestBizEvents() { } module.exports = { - getDocumentByIdFromBizEventsDatastore, createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore, deleteAllTestBizEvents + getDocumentByIdFromBizEventsDatastore, + createDocumentInBizEventsDatastore, + createDocumentInBizEventsDatastoreIsCartEvent, + createDocumentInBizEventsDatastoreWithIUVAndOrgCode, + deleteDocumentFromBizEventsDatastore, + deleteAllTestBizEvents } \ No newline at end of file diff --git a/integration-test/src/step_definitions/common.js b/integration-test/src/step_definitions/common.js index 3e58679c..dbaedfa0 100644 --- a/integration-test/src/step_definitions/common.js +++ b/integration-test/src/step_definitions/common.js @@ -9,10 +9,29 @@ function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive - } - +} + +function makeid(length) { + let result = ''; + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + const charactersLength = characters.length; + let counter = 0; + while (counter < length) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + counter += 1; + } + return result; +} -function createEvent(id, status, orgCode, iuv) { +function createEventCart(id, transactionId, status, totalNotice) { + return createEvent(id, status, transactionId, totalNotice); +} + +function createEventWithIUVAndOrgCode(id, status, orgCode, iuv) { + return createEvent(id, status, "123456", "1", orgCode, iuv); +} + +function createEvent(id, status, transactionId, totalNotice, orgCode, iuv) { let json_event = { "id": id, "version": "2", @@ -77,7 +96,7 @@ function createEvent(id, status, orgCode, iuv) { "paymentToken": "9851395f09544a04b288202299193ca6", "amount": "10.0", "fee": "2.0", - "totalNotice": "1", + "totalNotice": totalNotice || "1", "paymentMethod": "creditCard", "touchpoint": "app", "remittanceInformation": "TARI 2021", @@ -111,7 +130,7 @@ function createEvent(id, status, orgCode, iuv) { }, "transaction": { "idTransaction": "123456", - "transactionId": "123456", + "transactionId": transactionId || "123456", "grandTotal": 0, "amount": 0, "fee": 0 @@ -129,7 +148,7 @@ function createEvent(id, status, orgCode, iuv) { } function createReceipt(id, status) { - currentDate = new Date(); + currentDate = new Date(); let receipt = { "eventId": id, @@ -182,6 +201,15 @@ function createReceiptMessage(eventId, messageId) { } } +function createCart(id, bizEventIds, status) { + return { + "id": id, + "cartPaymentId": bizEventIds, + "totalNotice": 2, + "status": status + } +} + module.exports = { TOKENIZED_FISCAL_CODE, createEvent, @@ -189,5 +217,9 @@ module.exports = { createReceipt, createReceiptError, createReceiptMessage, - getRandomInt + getRandomInt, + createCart, + makeid, + createEventCart, + createEventWithIUVAndOrgCode } \ No newline at end of file diff --git a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js index 6a22f82a..f43ff64f 100644 --- a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js @@ -1,8 +1,12 @@ const assert = require('assert'); const { After, Given, When, Then, setDefaultTimeout } = require('@cucumber/cucumber'); let fs = require('fs'); -const { sleep } = require("./common"); -const { createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore } = require("./biz_events_datastore_client"); +const { sleep, makeid, createCart } = require("./common"); +const { + createDocumentInBizEventsDatastore, + createDocumentInBizEventsDatastoreIsCartEvent, + createDocumentInBizEventsDatastoreWithIUVAndOrgCode, + deleteDocumentFromBizEventsDatastore } = require("./biz_events_datastore_client"); const { deleteDocumentFromReceiptsDatastore, createDocumentInReceiptsDatastore, @@ -13,7 +17,10 @@ const { getDocumentFromReceiptsDatastoreByEventId, deleteMultipleDocumentFromReceiptErrorDatastoreByEventId, deleteDocumentFromReceiptMessageDatastore, - createDocumentInReceiptIoMessageDatastore + createDocumentInReceiptIoMessageDatastore, + createDocumentInCartDatastore, + deleteDocumentFromCartDatastore, + getDocumentFromCartDatastoreById } = require("./receipts_datastore_client"); const { getReceipt, @@ -26,7 +33,9 @@ const { postRecoverFailedReceiptMassive, postRecoverNotNotifiedReceipt, postRecoverNotNotifiedReceiptMassive, - postRegenerateReceiptPdf + postRegenerateReceiptPdf, + postRecoverFailedCart, + postRecoverFailedCartMassive } = require("./api_helpdesk_client"); const { uploadBlobFromLocalPath, deleteBlob, receiptPDFExist } = require("./blob_storage_client"); @@ -42,6 +51,9 @@ let receiptError = null; let receiptMessage = null; let receiptPdfFileName = null; let listOfReceipts = []; +let bizEventIds = []; +let cart = null; +let cartList = []; // After each Scenario After(async function () { @@ -63,6 +75,20 @@ After(async function () { await deleteDocumentFromBizEventsDatastore(receipt.eventId); } } + if (cart != null) { + for (let id of cart.cartPaymentId) { + await deleteDocumentFromBizEventsDatastore(id); + } + await deleteDocumentFromCartDatastore(cart.id); + } + if(cartList.length > 0){ + for(let cart of cartList){ + for (let id of cart.cartPaymentId) { + await deleteDocumentFromBizEventsDatastore(id); + } + await deleteDocumentFromCartDatastore(cart.id); + } + } eventId = null; responseAPI = null; @@ -70,6 +96,9 @@ After(async function () { receiptError = null; receiptPdfFileName = null; listOfReceipts = []; + bizEventIds = []; + cart = null; + cartList = []; }); //Given @@ -87,7 +116,7 @@ Given('a biz event with id {string} and status {string} and organizationFiscalCo // prior cancellation to avoid dirty cases await deleteDocumentFromBizEventsDatastore(eventId); - let bizEventStoreResponse = await createDocumentInBizEventsDatastore(id, status, orgCode, iuv); + let bizEventStoreResponse = await createDocumentInBizEventsDatastoreWithIUVAndOrgCode(id, status, orgCode, iuv); assert.strictEqual(bizEventStoreResponse.statusCode, 201); }); @@ -190,7 +219,7 @@ When('regenerateReceiptPdf API is called with bizEventId {string} as query param //Then Then('the api response has a {int} Http status', function (expectedStatus) { - assert.strictEqual(responseAPI.status, expectedStatus); + assert.strictEqual(responseAPI.status, expectedStatus); }); Then('the receipt has eventId {string}', function (targetId) { @@ -271,5 +300,78 @@ Then("the receipt-message has messageId {string}", async function (id) { }); +Given('a biz event with transactionId {string} and status {string} stored on biz-events datastore', async function (transactionId, status) { + let id = transactionId + makeid(5); + + let bizEventStoreResponse = await createDocumentInBizEventsDatastoreIsCartEvent(id, transactionId, status, "2"); + assert.strictEqual(bizEventStoreResponse.statusCode, 201); + bizEventIds.push(id); +}); + +Given('a cart with id {string} and status {string} stored into cart datastore', async function (id, status) { + // prior cancellation to avoid dirty cases + await deleteDocumentFromCartDatastore(id); + + let cartStoreResponse = await createDocumentInCartDatastore(id, bizEventIds, status); + assert.strictEqual(cartStoreResponse.statusCode, 201); + cart = cartStoreResponse.resource; +}); + +When("recoverFailedCart API is called with cartId {string}", async function (id) { + responseAPI = await postRecoverFailedCart(id); +}); + +Then("the cart with id {string} is retrieved from datastore", async function (id) { + let responseCosmos = await getDocumentFromCartDatastoreById(id); + assert.strictEqual(responseCosmos.resources.length > 0, true); +}); + +Then('the cart has not status {string}', function (targetStatus) { + assert.notStrictEqual(cart.status, targetStatus); +}); + +Given("a list of {int} carts in status {string} stored into cart datastore starting from id {string}", async function (numberOfCarts, status, startingId) { + cartList = []; + for (let i = 0; i < numberOfCarts; i++) { + let nextTransactionId = startingId + i; + let id = nextTransactionId + makeid(5); + let id2 = nextTransactionId + makeid(5); + let cartStoreResponse = await createDocumentInCartDatastore(nextTransactionId, [id, id2], status); + assert.strictEqual(cartStoreResponse.statusCode, 201); + cartList.push(cartStoreResponse.resource); + } +}); + +Given("a list of {int} biz events in status {string} stored into biz-events datastore", async function (numberOfEvents, status) { + assert.strictEqual(numberOfEvents / 2, cartList.length); + for (let cart of cartList) { + let transactionId = cart.id; + for (let bizEventId of cart.cartPaymentId) { + let bizEventStoreResponse = await createDocumentInBizEventsDatastoreIsCartEvent(bizEventId, transactionId, status, "2"); + assert.strictEqual(bizEventStoreResponse.statusCode, 201); + } + } +}); + +When("recoverFailedCartMassive API is called with status {string} as query param", async function (status) { + responseAPI = await postRecoverFailedCartMassive(status); +}); +Then('the list of cart is retrieved from datastore and no cart in the list has status {string}', async function (status) { + for (let cart of cartList) { + let responseCosmos = await getDocumentFromCartDatastoreById(cart.id); + assert.strictEqual(responseCosmos.resources.length > 0, true); + assert.notStrictEqual(responseCosmos.resources[0].status, status); + } +}) + +Then('the list of receipt is retrieved from datastore and no receipt in the list has status {string}', async function (status) { + listOfReceipts = []; + for (let cart of cartList) { + let responseCosmos = await getDocumentFromReceiptsDatastoreByEventId(cart.id); + assert.strictEqual(responseCosmos.resources.length > 0, true); + assert.notStrictEqual(responseCosmos.resources[0].status, status); + listOfReceipts.push(responseCosmos.resource[0]); + } +}) diff --git a/integration-test/src/step_definitions/receipts_datastore_client.js b/integration-test/src/step_definitions/receipts_datastore_client.js index 5936f777..f8af7a86 100644 --- a/integration-test/src/step_definitions/receipts_datastore_client.js +++ b/integration-test/src/step_definitions/receipts_datastore_client.js @@ -1,16 +1,18 @@ const { CosmosClient } = require("@azure/cosmos"); -const { createReceipt, createReceiptError, createReceiptMessage } = require("./common"); +const { createReceipt, createReceiptError, createReceiptMessage, createCart } = require("./common"); const cosmos_db_conn_string = process.env.RECEIPTS_COSMOS_CONN_STRING || ""; const databaseId = process.env.RECEIPT_COSMOS_DB_NAME; const receiptContainerId = process.env.RECEIPT_COSMOS_DB_CONTAINER_NAME; const receiptErrorContainerId = process.env.RECEIPT_ERROR_COSMOS_DB_CONTAINER_NAME; const receiptMessageContainerId = process.env.RECEIPT_MESSAGE_COSMOS_DB_CONTAINER_NAME; +const cartContainerId = process.env.CART_COSMOS_DB_CONTAINER_NAME; const client = new CosmosClient(cosmos_db_conn_string); const receiptContainer = client.database(databaseId).container(receiptContainerId); const receiptErrorContainer = client.database(databaseId).container(receiptErrorContainerId); const receiptMessageContainer = client.database(databaseId).container(receiptMessageContainerId); +const cartContainer = client.database(databaseId).container(cartContainerId); //RECEIPT async function createDocumentInReceiptsDatastore(id, status) { @@ -122,6 +124,34 @@ async function updateReceiptToFailed(id) { } } +// CART +async function createDocumentInCartDatastore(id, bizEventIds, status) { + let cart = createCart(id, bizEventIds, status); + try { + return await cartContainer.items.create(cart); + } catch (err) { + console.log(err); + } +} + +async function deleteDocumentFromCartDatastore(id) { + try { + return await cartContainer.item(id, id).delete(); + } catch (error) { + if (error.code !== 404) { + console.log(error) + } + } +} + +async function getDocumentFromCartDatastoreById(id) { + return await receiptErrorContainer.items + .query({ + query: "SELECT * from c WHERE c.id=@cartId", + parameters: [{ name: "@cartId", value: id }] + }) + .fetchNext(); +} async function deleteAllTestReceipts() { let response = await receiptContainer.items.query({ query: 'SELECT * from c WHERE c.id LIKE @id', @@ -183,5 +213,9 @@ module.exports = { deleteMultipleDocumentFromReceiptErrorDatastoreByEventId, createDocumentInReceiptErrorDatastore, getDocumentFromReceiptsErrorDatastoreByBizEventId, - deleteAllTestReceiptsError + deleteAllTestReceiptsError, + + createDocumentInCartDatastore, + deleteDocumentFromCartDatastore, + getDocumentFromCartDatastoreById } \ No newline at end of file From c49d51b9137e5001506160a4b8866b6092ea1976 Mon Sep 17 00:00:00 2001 From: giomella Date: Tue, 9 Jan 2024 14:54:35 +0100 Subject: [PATCH 02/14] [PRDP-307] fix recover failed cart API endpoint --- .../it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java index f660850c..4310e36d 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java @@ -67,7 +67,7 @@ public RecoverFailedCart(){ public HttpResponseMessage run ( @HttpTrigger(name = "RecoverFailedCartTrigger", methods = {HttpMethod.POST}, - route = "cart/{cart-id}/recover-failed", + route = "carts/{cart-id}/recover-failed", authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request, @BindingName("cart-id") String cartId, From 89cdf10c87c0f395a4bfdff7f39fe3335d950517 Mon Sep 17 00:00:00 2001 From: giomella Date: Tue, 9 Jan 2024 15:31:40 +0100 Subject: [PATCH 03/14] [PRDP-291] fix cart model --- integration-test/src/step_definitions/common.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integration-test/src/step_definitions/common.js b/integration-test/src/step_definitions/common.js index dbaedfa0..f1516032 100644 --- a/integration-test/src/step_definitions/common.js +++ b/integration-test/src/step_definitions/common.js @@ -206,7 +206,8 @@ function createCart(id, bizEventIds, status) { "id": id, "cartPaymentId": bizEventIds, "totalNotice": 2, - "status": status + "status": status, + "_ts": currentDate.getTime() - 360000, } } From 34c5f6724c20356567e7c628eb09a37466ad427c Mon Sep 17 00:00:00 2001 From: giomella Date: Tue, 9 Jan 2024 16:05:25 +0100 Subject: [PATCH 04/14] [PRDP-307] add inserted_at field in cart --- integration-test/src/step_definitions/common.js | 9 +++++---- .../src/step_definitions/receipt_pdf_helpdesk_step.js | 8 ++++---- .../client/impl/CartReceiptsCosmosClientImpl.java | 6 +++--- .../receipt/pdf/helpdesk/entity/cart/CartForReceipt.java | 3 +++ 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/integration-test/src/step_definitions/common.js b/integration-test/src/step_definitions/common.js index f1516032..6091abd5 100644 --- a/integration-test/src/step_definitions/common.js +++ b/integration-test/src/step_definitions/common.js @@ -11,7 +11,7 @@ function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive } -function makeid(length) { +function makeId(length) { let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; @@ -148,7 +148,7 @@ function createEvent(id, status, transactionId, totalNotice, orgCode, iuv) { } function createReceipt(id, status) { - currentDate = new Date(); + let currentDate = new Date(); let receipt = { "eventId": id, @@ -202,12 +202,13 @@ function createReceiptMessage(eventId, messageId) { } function createCart(id, bizEventIds, status) { + let currentDate = new Date(); return { "id": id, "cartPaymentId": bizEventIds, "totalNotice": 2, "status": status, - "_ts": currentDate.getTime() - 360000, + "inserted_at": currentDate.getTime() - 360000, } } @@ -220,7 +221,7 @@ module.exports = { createReceiptMessage, getRandomInt, createCart, - makeid, + makeId, createEventCart, createEventWithIUVAndOrgCode } \ No newline at end of file diff --git a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js index f43ff64f..74e6837e 100644 --- a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js @@ -1,7 +1,7 @@ const assert = require('assert'); const { After, Given, When, Then, setDefaultTimeout } = require('@cucumber/cucumber'); let fs = require('fs'); -const { sleep, makeid, createCart } = require("./common"); +const { sleep, makeId } = require("./common"); const { createDocumentInBizEventsDatastore, createDocumentInBizEventsDatastoreIsCartEvent, @@ -301,7 +301,7 @@ Then("the receipt-message has messageId {string}", async function (id) { Given('a biz event with transactionId {string} and status {string} stored on biz-events datastore', async function (transactionId, status) { - let id = transactionId + makeid(5); + let id = transactionId + makeId(5); let bizEventStoreResponse = await createDocumentInBizEventsDatastoreIsCartEvent(id, transactionId, status, "2"); assert.strictEqual(bizEventStoreResponse.statusCode, 201); @@ -335,8 +335,8 @@ Given("a list of {int} carts in status {string} stored into cart datastore start for (let i = 0; i < numberOfCarts; i++) { let nextTransactionId = startingId + i; - let id = nextTransactionId + makeid(5); - let id2 = nextTransactionId + makeid(5); + let id = nextTransactionId + makeId(5); + let id2 = nextTransactionId + makeId(5); let cartStoreResponse = await createDocumentInCartDatastore(nextTransactionId, [id, id2], status); assert.strictEqual(cartStoreResponse.statusCode, 201); cartList.push(cartStoreResponse.resource); diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java index 0f1be3a9..a4b56516 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java @@ -98,7 +98,7 @@ public Iterable> getFailedCarts(String continuation CosmosContainer cosmosContainer = cosmosDatabase.getContainer(cartForReceiptContainerName); //Build query - String query = String.format("SELECT * FROM c WHERE (c.status = '%s') AND c._ts >= %s", + String query = String.format("SELECT * FROM c WHERE (c.status = '%s') AND c.inserted_at >= %s", CartStatusType.FAILED, OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays( Long.parseLong(numDaysCartNotSent)).toInstant().toEpochMilli()); @@ -115,8 +115,8 @@ public Iterable> getInsertedCarts(String continuati CosmosContainer cosmosContainer = cosmosDatabase.getContainer(cartForReceiptContainerName); //Build query - String query = String.format("SELECT * FROM c WHERE (c.status = '%s' AND c._ts >= %s " + - "AND ( %s - c._ts) >= %s)", + String query = String.format("SELECT * FROM c WHERE (c.status = '%s' AND c.inserted_at >= %s " + + "AND ( %s - c.inserted_at) >= %s)", ReceiptStatusType.INSERTED, OffsetDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays( Long.parseLong(numDaysCartNotSent)).toInstant().toEpochMilli(), diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java index 78c4c496..44ed7e43 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java @@ -1,5 +1,6 @@ package it.gov.pagopa.receipt.pdf.helpdesk.entity.cart; +import com.fasterxml.jackson.annotation.JsonProperty; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReasonError; import lombok.AllArgsConstructor; import lombok.Builder; @@ -17,5 +18,7 @@ public class CartForReceipt { private Set cartPaymentId; private Integer totalNotice; private CartStatusType status; + @JsonProperty("inserted_at") + private long insertedAt; private ReasonError reasonError; } From 0ed89e4f794528ee886b758fc51763f1c4f34cba Mon Sep 17 00:00:00 2001 From: giomella Date: Tue, 9 Jan 2024 17:08:50 +0100 Subject: [PATCH 05/14] [PRDP-291] fix amount format --- .../pdf/helpdesk/utils/BizEventToReceiptUtils.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java index c14b0840..96c468d2 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/utils/BizEventToReceiptUtils.java @@ -3,7 +3,6 @@ import com.azure.cosmos.models.FeedResponse; import com.fasterxml.jackson.core.JsonProcessingException; import com.microsoft.azure.functions.ExecutionContext; -import com.microsoft.azure.functions.HttpStatus; import it.gov.pagopa.receipt.pdf.helpdesk.client.BizEventCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.client.CartReceiptsCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; @@ -20,7 +19,6 @@ import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.model.MassiveRecoverCartResult; import it.gov.pagopa.receipt.pdf.helpdesk.model.MassiveRecoverResult; -import it.gov.pagopa.receipt.pdf.helpdesk.model.ProblemJson; import it.gov.pagopa.receipt.pdf.helpdesk.service.BizEventToReceiptService; import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; import org.slf4j.Logger; @@ -189,12 +187,8 @@ public static Receipt createReceipt(BizEvent bizEvent, BizEventToReceiptService eventData.setTransactionCreationDate( service.getTransactionCreationDate(bizEvent)); - eventData.setAmount( - bizEvent.getTransactionDetails() != null && bizEvent - .getTransactionDetails().getTransaction() != null ? - String.valueOf(bizEvent.getTransactionDetails().getTransaction().getGrandTotal()) : - bizEvent.getPaymentInfo() != null ? bizEvent.getPaymentInfo().getAmount() : null - ); + BigDecimal amount = getAmount(bizEvent); + eventData.setAmount(!amount.equals(BigDecimal.ZERO) ? amount.toString() : null); CartItem item = new CartItem(); item.setPayeeName(bizEvent.getCreditor() != null ? bizEvent.getCreditor().getCompanyName() : null); From dc9db0c66bbdfb32471bc2adac985cd4cb9db71a Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 10 Jan 2024 09:16:02 +0100 Subject: [PATCH 06/14] [PRDP-291] removed duplicated code and fixed cart container name env --- .../client/CartReceiptsCosmosClient.java | 10 +++- .../helpdesk/client/ReceiptCosmosClient.java | 11 ---- .../impl/CartReceiptsCosmosClientImpl.java | 25 ++++----- .../client/impl/ReceiptCosmosClientImpl.java | 20 -------- .../impl/ReceiptCosmosServiceImpl.java | 9 +++- .../impl/ReceiptCosmosClientImplTest.java | 51 ------------------- .../impl/ReceiptCosmosServiceImplTest.java | 11 ++-- 7 files changed, 32 insertions(+), 105 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/CartReceiptsCosmosClient.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/CartReceiptsCosmosClient.java index 69489ec1..8bb49c12 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/CartReceiptsCosmosClient.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/CartReceiptsCosmosClient.java @@ -3,12 +3,18 @@ import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.FeedResponse; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; -import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartStatusType; import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; public interface CartReceiptsCosmosClient { - CartForReceipt getCartItem(String eventId) throws CartNotFoundException; + /** + * Retrieve the cart with the provided id from Cosmos + * + * @param cartId the cart id + * @return the cart + * @throws CartNotFoundException if no cart was found in the container + */ + CartForReceipt getCartItem(String cartId) throws CartNotFoundException; CosmosItemResponse saveCart(CartForReceipt receipt); diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java index 948d8174..cae8c3c8 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/ReceiptCosmosClient.java @@ -2,12 +2,10 @@ import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.FeedResponse; -import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReceiptError; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; -import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; @@ -58,13 +56,4 @@ public interface ReceiptCosmosClient { Iterable> getIOErrorToNotifyReceiptDocuments(String continuationToken, Integer pageSize); IOMessage getIoMessage(String messageId) throws IoMessageNotFoundException; - - /** - * Retrieve the cart with the provided id from Cosmos - * - * @param cartId the cart id - * @return the cart - * @throws CartNotFoundException if no cart was found in the container - */ - CartForReceipt getCartDocument(String cartId) throws CartNotFoundException; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java index a4b56516..843b5398 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/CartReceiptsCosmosClientImpl.java @@ -1,6 +1,10 @@ package it.gov.pagopa.receipt.pdf.helpdesk.client.impl; -import com.azure.cosmos.*; +import com.azure.cosmos.ConsistencyLevel; +import com.azure.cosmos.CosmosClient; +import com.azure.cosmos.CosmosClientBuilder; +import com.azure.cosmos.CosmosContainer; +import com.azure.cosmos.CosmosDatabase; import com.azure.cosmos.models.CosmosItemResponse; import com.azure.cosmos.models.CosmosQueryRequestOptions; import com.azure.cosmos.models.FeedResponse; @@ -10,7 +14,6 @@ import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartStatusType; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; -import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import java.time.OffsetDateTime; import java.time.temporal.ChronoUnit; @@ -19,13 +22,12 @@ public class CartReceiptsCosmosClientImpl implements CartReceiptsCosmosClient { private static CartReceiptsCosmosClientImpl instance; private final String databaseId = System.getenv("COSMOS_RECEIPT_DB_NAME"); - private final String cartForReceiptContainerName = System.getenv("CART_FOR_RECEIPT_CONTAINER_NAME"); + private final String cartForReceiptContainerName = System.getenv("COSMOS_RECEIPT_CART_CONTAINER_NAME"); private final String millisDiff = System.getenv("MAX_DATE_DIFF_CART_MILLIS"); private final String numDaysCartNotSent = System.getenv().getOrDefault("RECOVER_CART_MASSIVE_MAX_DAYS", "0"); - private final CosmosClient cosmosClient; private CartReceiptsCosmosClientImpl() { @@ -52,20 +54,15 @@ public static CartReceiptsCosmosClientImpl getInstance() { } /** - * Retrieve receipt document from CosmosDB database - * - * @param eventId Biz-event id - * @return receipt document - * @throws ReceiptNotFoundException in case no receipt has been found with the given idEvent + * {@inheritDoc} */ @Override - public CartForReceipt getCartItem(String eventId) throws CartNotFoundException { + public CartForReceipt getCartItem(String cartId) throws CartNotFoundException { CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId); - CosmosContainer cosmosContainer = cosmosDatabase.getContainer(cartForReceiptContainerName); //Build query - String query = "SELECT * FROM c WHERE c.id = " + "'" + eventId + "'"; + String query = String.format("SELECT * FROM c WHERE c.id = '%s'", cartId); //Query the container CosmosPagedIterable queryResponse = cosmosContainer @@ -73,10 +70,8 @@ public CartForReceipt getCartItem(String eventId) throws CartNotFoundException { if (queryResponse.iterator().hasNext()) { return queryResponse.iterator().next(); - } else { - throw new CartNotFoundException("Document not found in the defined container"); } - + throw new CartNotFoundException("Document not found in the defined container"); } /** diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java index ba46ab5f..99c00147 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImpl.java @@ -9,13 +9,11 @@ import com.azure.cosmos.models.FeedResponse; import com.azure.cosmos.util.CosmosPagedIterable; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; -import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.ReceiptError; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptErrorStatusType; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; -import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; @@ -31,7 +29,6 @@ public class ReceiptCosmosClientImpl implements ReceiptCosmosClient { private final String databaseId = System.getenv().getOrDefault("COSMOS_RECEIPT_DB_NAME", "db"); private final String containerId = System.getenv().getOrDefault("COSMOS_RECEIPT_CONTAINER_NAME", "receipt"); - private final String containerCartId = System.getenv().getOrDefault("COSMOS_RECEIPT_CART_CONTAINER_NAME", "cart-for-receipts"); private final String containerMessageId = System.getenv().getOrDefault("COSMOS_RECEIPT_MESSAGE_CONTAINER_NAME", "receipts-io-messages"); private final String containerReceiptErrorId = System.getenv().getOrDefault("COSMOS_RECEIPT_ERROR_CONTAINER_NAME", "receipts-message-errors"); @@ -264,21 +261,4 @@ public IOMessage getIoMessage(String messageId) throws IoMessageNotFoundExceptio throw new IoMessageNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG); } - @Override - public CartForReceipt getCartDocument(String cartId) throws CartNotFoundException { - CosmosDatabase cosmosDatabase = this.cosmosClient.getDatabase(databaseId); - CosmosContainer cosmosContainer = cosmosDatabase.getContainer(containerCartId); - - //Build query - String query = String.format("SELECT * FROM c WHERE c.id = '%s'", cartId); - - //Query the container - CosmosPagedIterable queryResponse = cosmosContainer - .queryItems(query, new CosmosQueryRequestOptions(), CartForReceipt.class); - - if (queryResponse.iterator().hasNext()) { - return queryResponse.iterator().next(); - } - throw new CartNotFoundException(DOCUMENT_NOT_FOUND_ERR_MSG); - } } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java index 6f91bb79..06f325e6 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImpl.java @@ -1,7 +1,9 @@ package it.gov.pagopa.receipt.pdf.helpdesk.service.impl; import com.azure.cosmos.models.FeedResponse; +import it.gov.pagopa.receipt.pdf.helpdesk.client.CartReceiptsCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; +import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.CartReceiptsCosmosClientImpl; import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.ReceiptCosmosClientImpl; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; @@ -15,13 +17,16 @@ public class ReceiptCosmosServiceImpl implements ReceiptCosmosService { private final ReceiptCosmosClient receiptCosmosClient; + private final CartReceiptsCosmosClient cartReceiptsCosmosClient; public ReceiptCosmosServiceImpl() { this.receiptCosmosClient = ReceiptCosmosClientImpl.getInstance(); + this.cartReceiptsCosmosClient = CartReceiptsCosmosClientImpl.getInstance(); } - ReceiptCosmosServiceImpl(ReceiptCosmosClient receiptCosmosClient) { + ReceiptCosmosServiceImpl(ReceiptCosmosClient receiptCosmosClient, CartReceiptsCosmosClient cartReceiptsCosmosClient) { this.receiptCosmosClient = receiptCosmosClient; + this.cartReceiptsCosmosClient = cartReceiptsCosmosClient; } /** @@ -109,7 +114,7 @@ public IOMessage getReceiptMessage(String messageId) throws IoMessageNotFoundExc public CartForReceipt getCart(String cartId) throws CartNotFoundException { CartForReceipt cartForReceipt; try { - cartForReceipt = this.receiptCosmosClient.getCartDocument(cartId); + cartForReceipt = this.cartReceiptsCosmosClient.getCartItem(cartId); } catch (CartNotFoundException e) { String errorMsg = String.format("Receipt not found with the biz-event id %s", cartId); throw new CartNotFoundException(errorMsg, e); diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java index 9a8777b7..537fcf76 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/client/impl/ReceiptCosmosClientImplTest.java @@ -4,10 +4,8 @@ import com.azure.cosmos.CosmosContainer; import com.azure.cosmos.CosmosDatabase; import com.azure.cosmos.util.CosmosPagedIterable; -import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; -import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.IoMessageNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.ReceiptNotFoundException; import org.junit.jupiter.api.BeforeEach; @@ -28,7 +26,6 @@ class ReceiptCosmosClientImplTest { private static final String RECEIPT_ID = "a valid receipt id"; - private static final String CART_ID = "a valid cart id"; private CosmosClient mockClient; @@ -245,52 +242,4 @@ void getIoMessageReceiptDocumentFail() { assertThrows(IoMessageNotFoundException.class, () -> client.getIoMessage("an invalid receipt id")); } - - - @Test - void getCartDocumentSuccess() { - CosmosDatabase mockDatabase = mock(CosmosDatabase.class); - CosmosContainer mockContainer = mock(CosmosContainer.class); - - CosmosPagedIterable mockIterable = mock(CosmosPagedIterable.class); - - Iterator mockIterator = mock(Iterator.class); - CartForReceipt cart = new CartForReceipt(); - cart.setId(CART_ID); - - when(mockIterator.hasNext()).thenReturn(true); - when(mockIterator.next()).thenReturn(cart); - - when(mockIterable.iterator()).thenReturn(mockIterator); - - when(mockContainer.queryItems(anyString(), any(), eq(CartForReceipt.class))) - .thenReturn(mockIterable); - when(mockDatabase.getContainer(any())).thenReturn(mockContainer); - when(mockClient.getDatabase(any())).thenReturn(mockDatabase); - - CartForReceipt cartForReceipt = assertDoesNotThrow(() -> client.getCartDocument(CART_ID)); - - assertEquals(CART_ID, cartForReceipt.getId()); - } - - @Test - void getCartDocumentFail() { - CosmosDatabase mockDatabase = mock(CosmosDatabase.class); - CosmosContainer mockContainer = mock(CosmosContainer.class); - - CosmosPagedIterable mockIterable = mock(CosmosPagedIterable.class); - - Iterator mockIterator = mock(Iterator.class); - - when(mockIterator.hasNext()).thenReturn(false); - - when(mockIterable.iterator()).thenReturn(mockIterator); - - when(mockContainer.queryItems(anyString(), any(), eq(CartForReceipt.class))) - .thenReturn(mockIterable); - when(mockDatabase.getContainer(any())).thenReturn(mockContainer); - when(mockClient.getDatabase(any())).thenReturn(mockDatabase); - - assertThrows(CartNotFoundException.class, () -> client.getCartDocument("an invalid receipt id")); - } } \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java index 622278a7..1a2b36c5 100644 --- a/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java +++ b/src/test/java/it/gov/pagopa/receipt/pdf/helpdesk/service/impl/ReceiptCosmosServiceImplTest.java @@ -1,6 +1,7 @@ package it.gov.pagopa.receipt.pdf.helpdesk.service.impl; import com.azure.cosmos.models.FeedResponse; +import it.gov.pagopa.receipt.pdf.helpdesk.client.CartReceiptsCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.client.ReceiptCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.IOMessage; @@ -29,14 +30,16 @@ class ReceiptCosmosServiceImplTest { private ReceiptCosmosClient receiptCosmosClientMock; + private CartReceiptsCosmosClient cartReceiptsCosmosClientMock; private ReceiptCosmosService sut; @BeforeEach void setUp() { receiptCosmosClientMock = mock(ReceiptCosmosClient.class); + cartReceiptsCosmosClientMock = mock(CartReceiptsCosmosClient.class); - sut = spy(new ReceiptCosmosServiceImpl(receiptCosmosClientMock)); + sut = spy(new ReceiptCosmosServiceImpl(receiptCosmosClientMock, cartReceiptsCosmosClientMock)); } @Test @@ -204,7 +207,7 @@ void getReceiptMessageFailClientReturnNull() throws IoMessageNotFoundException { @Test void getCartSuccess() throws CartNotFoundException { - when(receiptCosmosClientMock.getCartDocument(anyString())).thenReturn(new CartForReceipt()); + when(cartReceiptsCosmosClientMock.getCartItem(anyString())).thenReturn(new CartForReceipt()); CartForReceipt cart = assertDoesNotThrow(() -> sut.getCart(anyString())); @@ -213,14 +216,14 @@ void getCartSuccess() throws CartNotFoundException { @Test void getCartFailClientThrowsCartNotFoundException() throws CartNotFoundException { - when(receiptCosmosClientMock.getCartDocument(anyString())).thenThrow(CartNotFoundException.class); + when(cartReceiptsCosmosClientMock.getCartItem(anyString())).thenThrow(CartNotFoundException.class); assertThrows(CartNotFoundException.class, () -> sut.getCart(anyString())); } @Test void getCartFailClientReturnNull() throws CartNotFoundException { - when(receiptCosmosClientMock.getCartDocument(anyString())).thenReturn(null); + when(cartReceiptsCosmosClientMock.getCartItem(anyString())).thenReturn(null); assertThrows(CartNotFoundException.class, () -> sut.getCart(anyString())); } From 85001015f2e421add4418b81599ce3fba2012d02 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Wed, 10 Jan 2024 08:35:21 +0000 Subject: [PATCH 07/14] Bump to version 0.9.2-1-PRDP-291-add-integration-tests-for-cart-api [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 4db9fc8e..0c153613 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopareceiptpdfhelpdesk description: Microservice description type: application -version: 0.141.0 -appVersion: 0.9.2 +version: 0.142.0 +appVersion: 0.9.2-1-PRDP-291-add-integration-tests-for-cart-api dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 7cf4cd66..99bc5e24 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk - tag: "0.9.2" + tag: "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" pullPolicy: Always # https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs livenessProbe: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 8332c30c..de860998 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk - tag: "0.9.2" + tag: "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" pullPolicy: Always # https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs livenessProbe: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index c3e28f9a..dc14f808 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk - tag: "0.9.2" + tag: "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" pullPolicy: Always # https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs livenessProbe: diff --git a/openapi/openapi.json b/openapi/openapi.json index 97f29992..4a69463f 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "title": "Receipts Helpdesk", "description": "Microservice for exposing REST APIs about receipts helpdesk.", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.9.2" + "version": "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 61354b03..98dabd08 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ it.gov.pagopa.receipt receipt-pdf-helpdesk - 0.9.2 + 0.9.2-1-PRDP-291-add-integration-tests-for-cart-api jar pagopa-receipt-pdf-helpdesk From 914f9b6e6be4469cd5813e9444d110fe6640a6dc Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 10 Jan 2024 09:50:15 +0100 Subject: [PATCH 08/14] [PRDP-291] fixed cart output binding collection name --- .../pdf/helpdesk/RecoverFailedCart.java | 23 ++++++++++--------- .../helpdesk/RecoverFailedCartMassive.java | 10 +++++--- .../helpdesk/RecoverFailedCartScheduled.java | 11 +-------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java index 4310e36d..0be69afc 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCart.java @@ -1,26 +1,27 @@ package it.gov.pagopa.receipt.pdf.helpdesk; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.microsoft.azure.functions.*; -import com.microsoft.azure.functions.annotation.*; -import it.gov.pagopa.receipt.pdf.helpdesk.client.BizEventCosmosClient; +import com.microsoft.azure.functions.ExecutionContext; +import com.microsoft.azure.functions.HttpMethod; +import com.microsoft.azure.functions.HttpRequestMessage; +import com.microsoft.azure.functions.HttpResponseMessage; +import com.microsoft.azure.functions.HttpStatus; +import com.microsoft.azure.functions.OutputBinding; +import com.microsoft.azure.functions.annotation.AuthorizationLevel; +import com.microsoft.azure.functions.annotation.BindingName; +import com.microsoft.azure.functions.annotation.CosmosDBOutput; +import com.microsoft.azure.functions.annotation.FunctionName; +import com.microsoft.azure.functions.annotation.HttpTrigger; import it.gov.pagopa.receipt.pdf.helpdesk.client.CartReceiptsCosmosClient; -import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.BizEventCosmosClientImpl; import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.CartReceiptsCosmosClientImpl; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartStatusType; import it.gov.pagopa.receipt.pdf.helpdesk.entity.event.BizEvent; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; -import it.gov.pagopa.receipt.pdf.helpdesk.exception.BizEventNotFoundException; import it.gov.pagopa.receipt.pdf.helpdesk.exception.CartNotFoundException; -import it.gov.pagopa.receipt.pdf.helpdesk.exception.PDVTokenizerException; import it.gov.pagopa.receipt.pdf.helpdesk.model.ProblemJson; import it.gov.pagopa.receipt.pdf.helpdesk.service.BizEventToReceiptService; -import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; import it.gov.pagopa.receipt.pdf.helpdesk.service.impl.BizEventToReceiptServiceImpl; -import it.gov.pagopa.receipt.pdf.helpdesk.service.impl.ReceiptCosmosServiceImpl; -import it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,7 +75,7 @@ public HttpResponseMessage run ( @CosmosDBOutput( name = "CartReceiptDatastore", databaseName = "db", - collectionName = "cart-for-receipt", + collectionName = "cart-for-receipts", connectionStringSetting = "COSMOS_RECEIPTS_CONN_STRING") OutputBinding cartForReceiptDocumentdb, final ExecutionContext context) { diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartMassive.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartMassive.java index 08eb9465..3e8bf45f 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartMassive.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartMassive.java @@ -1,6 +1,11 @@ package it.gov.pagopa.receipt.pdf.helpdesk; -import com.microsoft.azure.functions.*; +import com.microsoft.azure.functions.ExecutionContext; +import com.microsoft.azure.functions.HttpMethod; +import com.microsoft.azure.functions.HttpRequestMessage; +import com.microsoft.azure.functions.HttpResponseMessage; +import com.microsoft.azure.functions.HttpStatus; +import com.microsoft.azure.functions.OutputBinding; import com.microsoft.azure.functions.annotation.AuthorizationLevel; import com.microsoft.azure.functions.annotation.CosmosDBOutput; import com.microsoft.azure.functions.annotation.FunctionName; @@ -18,7 +23,6 @@ import java.time.LocalDateTime; import java.util.List; -import java.util.NoSuchElementException; import java.util.Optional; import static it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils.massiveRecoverCartByStatus; @@ -65,7 +69,7 @@ public HttpResponseMessage run( @CosmosDBOutput( name = "CartReceiptDatastore", databaseName = "db", - collectionName = "cart-for-receipt", + collectionName = "cart-for-receipts", connectionStringSetting = "COSMOS_RECEIPTS_CONN_STRING") OutputBinding> cartForReceiptDocumentdb, final ExecutionContext context) { diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartScheduled.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartScheduled.java index e55686f6..467b1d01 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartScheduled.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/RecoverFailedCartScheduled.java @@ -5,20 +5,13 @@ import com.microsoft.azure.functions.annotation.CosmosDBOutput; import com.microsoft.azure.functions.annotation.FunctionName; import com.microsoft.azure.functions.annotation.TimerTrigger; -import it.gov.pagopa.receipt.pdf.helpdesk.client.BizEventCosmosClient; import it.gov.pagopa.receipt.pdf.helpdesk.client.CartReceiptsCosmosClient; -import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.BizEventCosmosClientImpl; import it.gov.pagopa.receipt.pdf.helpdesk.client.impl.CartReceiptsCosmosClientImpl; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartForReceipt; import it.gov.pagopa.receipt.pdf.helpdesk.entity.cart.CartStatusType; -import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.Receipt; -import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; import it.gov.pagopa.receipt.pdf.helpdesk.model.MassiveRecoverCartResult; -import it.gov.pagopa.receipt.pdf.helpdesk.model.MassiveRecoverResult; import it.gov.pagopa.receipt.pdf.helpdesk.service.BizEventToReceiptService; -import it.gov.pagopa.receipt.pdf.helpdesk.service.ReceiptCosmosService; import it.gov.pagopa.receipt.pdf.helpdesk.service.impl.BizEventToReceiptServiceImpl; -import it.gov.pagopa.receipt.pdf.helpdesk.service.impl.ReceiptCosmosServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,9 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.NoSuchElementException; -import static it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils.massiveRecoverByStatus; import static it.gov.pagopa.receipt.pdf.helpdesk.utils.BizEventToReceiptUtils.massiveRecoverCartByStatus; /** @@ -70,7 +61,7 @@ public void run( @CosmosDBOutput( name = "CartReceiptDatastore", databaseName = "db", - collectionName = "cart-for-receipt", + collectionName = "cart-for-receipts", connectionStringSetting = "COSMOS_RECEIPTS_CONN_STRING") OutputBinding> cartForReceiptDocumentdb, final ExecutionContext context From d155be2d1c715b44da43a2e44b8615dd795df868 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Wed, 10 Jan 2024 08:53:58 +0000 Subject: [PATCH 09/14] Bump to version 0.9.2-2-PRDP-291-add-integration-tests-for-cart-api [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi.json | 2 +- pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 0c153613..e5162d55 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopareceiptpdfhelpdesk description: Microservice description type: application -version: 0.142.0 -appVersion: 0.9.2-1-PRDP-291-add-integration-tests-for-cart-api +version: 0.143.0 +appVersion: 0.9.2-2-PRDP-291-add-integration-tests-for-cart-api dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 99bc5e24..c5df44a0 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk - tag: "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" + tag: "0.9.2-2-PRDP-291-add-integration-tests-for-cart-api" pullPolicy: Always # https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs livenessProbe: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index de860998..09c07742 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk - tag: "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" + tag: "0.9.2-2-PRDP-291-add-integration-tests-for-cart-api" pullPolicy: Always # https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs livenessProbe: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index dc14f808..2c530fee 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk - tag: "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" + tag: "0.9.2-2-PRDP-291-add-integration-tests-for-cart-api" pullPolicy: Always # https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs livenessProbe: diff --git a/openapi/openapi.json b/openapi/openapi.json index 4a69463f..733cb5b3 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -4,7 +4,7 @@ "title": "Receipts Helpdesk", "description": "Microservice for exposing REST APIs about receipts helpdesk.", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.9.2-1-PRDP-291-add-integration-tests-for-cart-api" + "version": "0.9.2-2-PRDP-291-add-integration-tests-for-cart-api" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 98dabd08..34ca8d29 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ it.gov.pagopa.receipt receipt-pdf-helpdesk - 0.9.2-1-PRDP-291-add-integration-tests-for-cart-api + 0.9.2-2-PRDP-291-add-integration-tests-for-cart-api jar pagopa-receipt-pdf-helpdesk From b61593ce03dd47523bf80397e03f7cc3db9051dc Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 10 Jan 2024 10:01:54 +0100 Subject: [PATCH 10/14] [PRDP-291] added missing cleanup --- .../src/step_definitions/receipt_pdf_helpdesk_step.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js index 74e6837e..fc4e0bde 100644 --- a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js @@ -89,6 +89,9 @@ After(async function () { await deleteDocumentFromCartDatastore(cart.id); } } + if (receipt != null) { + await deleteDocumentFromReceiptsDatastore(receipt.id); + } eventId = null; responseAPI = null; From 345f73a7ddcce9438e7f46e2b5da836b0a55992d Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 10 Jan 2024 10:08:49 +0100 Subject: [PATCH 11/14] [PRDP-291] added missing cleanup --- .../src/step_definitions/receipt_pdf_helpdesk_step.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js index fc4e0bde..22449ed7 100644 --- a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js @@ -79,6 +79,7 @@ After(async function () { for (let id of cart.cartPaymentId) { await deleteDocumentFromBizEventsDatastore(id); } + await deleteMultipleDocumentsFromReceiptsDatastoreByEventId(cart.id); await deleteDocumentFromCartDatastore(cart.id); } if(cartList.length > 0){ @@ -86,6 +87,7 @@ After(async function () { for (let id of cart.cartPaymentId) { await deleteDocumentFromBizEventsDatastore(id); } + await deleteMultipleDocumentsFromReceiptsDatastoreByEventId(cart.id); await deleteDocumentFromCartDatastore(cart.id); } } From 6033037f7817edcc8d41cc6aad40dba38c1dc9ed Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 10 Jan 2024 10:18:19 +0100 Subject: [PATCH 12/14] [PRDP-291] fix tests --- .../src/step_definitions/receipts_datastore_client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test/src/step_definitions/receipts_datastore_client.js b/integration-test/src/step_definitions/receipts_datastore_client.js index f8af7a86..4e2ff640 100644 --- a/integration-test/src/step_definitions/receipts_datastore_client.js +++ b/integration-test/src/step_definitions/receipts_datastore_client.js @@ -145,7 +145,7 @@ async function deleteDocumentFromCartDatastore(id) { } async function getDocumentFromCartDatastoreById(id) { - return await receiptErrorContainer.items + return await cartContainer.items .query({ query: "SELECT * from c WHERE c.id=@cartId", parameters: [{ name: "@cartId", value: id }] From 64eb7ec9f26a2596ada5416d0c0d521eb9b23ff2 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 10 Jan 2024 11:09:53 +0100 Subject: [PATCH 13/14] [PRDP-291] fixed tests --- .../src/step_definitions/receipt_pdf_helpdesk_step.js | 3 ++- .../src/step_definitions/receipts_datastore_client.js | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js index 22449ed7..2064b5d3 100644 --- a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js @@ -329,6 +329,7 @@ When("recoverFailedCart API is called with cartId {string}", async function (id) Then("the cart with id {string} is retrieved from datastore", async function (id) { let responseCosmos = await getDocumentFromCartDatastoreById(id); assert.strictEqual(responseCosmos.resources.length > 0, true); + cart = responseCosmos.resources[0]; }); Then('the cart has not status {string}', function (targetStatus) { @@ -377,6 +378,6 @@ Then('the list of receipt is retrieved from datastore and no receipt in the list let responseCosmos = await getDocumentFromReceiptsDatastoreByEventId(cart.id); assert.strictEqual(responseCosmos.resources.length > 0, true); assert.notStrictEqual(responseCosmos.resources[0].status, status); - listOfReceipts.push(responseCosmos.resource[0]); + listOfReceipts.push(responseCosmos.resources[0]); } }) diff --git a/integration-test/src/step_definitions/receipts_datastore_client.js b/integration-test/src/step_definitions/receipts_datastore_client.js index 4e2ff640..24169ba1 100644 --- a/integration-test/src/step_definitions/receipts_datastore_client.js +++ b/integration-test/src/step_definitions/receipts_datastore_client.js @@ -158,8 +158,15 @@ async function deleteAllTestReceipts() { parameters: [{ name: "@id", value: "%receipt-helpdesk-int-test%" }] }).fetchNext(); + let response2 = await receiptContainer.items + .query({ + query: "SELECT * from c WHERE c.eventId=@eventId", + parameters: [{ name: "@eventId", value: "%receipt-helpdesk-int-test%" }] + }) + .fetchNext(); + - let receiptList = response.resources; + let receiptList = response.resources.concat(response2.resources); if (receiptList.length > 0) { receiptList.forEach((receipt) => { console.log("\n Deleting receipt with id " + id); From 2861070f92820a9f8ae2c474d899ce15a5b828e3 Mon Sep 17 00:00:00 2001 From: giomella Date: Wed, 10 Jan 2024 11:41:49 +0100 Subject: [PATCH 14/14] [PRDP-291] fix entity model --- .../pdf/helpdesk/entity/cart/CartForReceipt.java | 3 +-- .../pdf/helpdesk/entity/receipt/Receipt.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java index 44ed7e43..5a3afea3 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/cart/CartForReceipt.java @@ -18,7 +18,6 @@ public class CartForReceipt { private Set cartPaymentId; private Integer totalNotice; private CartStatusType status; - @JsonProperty("inserted_at") - private long insertedAt; + private long inserted_at; private ReasonError reasonError; } diff --git a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/receipt/Receipt.java b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/receipt/Receipt.java index c2bdc319..ce31acf6 100644 --- a/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/receipt/Receipt.java +++ b/src/main/java/it/gov/pagopa/receipt/pdf/helpdesk/entity/receipt/Receipt.java @@ -1,8 +1,11 @@ package it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt; -import com.fasterxml.jackson.annotation.JsonProperty; import it.gov.pagopa.receipt.pdf.helpdesk.entity.receipt.enumeration.ReceiptStatusType; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; @Getter @Setter @@ -23,11 +26,8 @@ public class Receipt { private ReasonError reasonErr; private ReasonError reasonErrPayer; private int notificationNumRetry; - @JsonProperty("inserted_at") - private long insertedAt; - @JsonProperty("generated_at") - private long generatedAt; - @JsonProperty("notified_at") - private long notifiedAt; + private long inserted_at; + private long generated_at; + private long notified_at; private Boolean isCart; }