Skip to content

Commit

Permalink
[PRDP-291] added integration test for cart apis
Browse files Browse the repository at this point in the history
  • Loading branch information
giomella committed Jan 9, 2024
1 parent 4e8dd2a commit 78b888e
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 21 deletions.
1 change: 1 addition & 0 deletions integration-test/src/config/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -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=<storage-account-connection-string>
BLOB_STORAGE_CONTAINER_NAME=pagopa-d-weu-receipts-azure-blob-receipt-st-attach
Expand Down
1 change: 1 addition & 0 deletions integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -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=<storage-account-connection-string>
BLOB_STORAGE_CONTAINER_NAME=pagopa-d-weu-receipts-azure-blob-receipt-st-attach
Expand Down
1 change: 1 addition & 0 deletions integration-test/src/config/.env.uat
Original file line number Diff line number Diff line change
Expand Up @@ -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=<storage-account-connection-string>
BLOB_STORAGE_CONTAINER_NAME=pagopa-u-weu-receipts-azure-blob-receipt-st-attach
Expand Down
21 changes: 20 additions & 1 deletion integration-test/src/features/receipt_pdf_helpdesk.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
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"
30 changes: 29 additions & 1 deletion integration-test/src/step_definitions/api_helpdesk_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -162,5 +188,7 @@ module.exports = {
postRecoverFailedReceiptMassive,
postRecoverNotNotifiedReceipt,
postRecoverNotNotifiedReceiptMassive,
postRegenerateReceiptPdf
postRegenerateReceiptPdf,
postRecoverFailedCart,
postRecoverFailedCartMassive
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -52,5 +70,10 @@ async function deleteAllTestBizEvents() {
}

module.exports = {
getDocumentByIdFromBizEventsDatastore, createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore, deleteAllTestBizEvents
getDocumentByIdFromBizEventsDatastore,
createDocumentInBizEventsDatastore,
createDocumentInBizEventsDatastoreIsCartEvent,
createDocumentInBizEventsDatastoreWithIUVAndOrgCode,
deleteDocumentFromBizEventsDatastore,
deleteAllTestBizEvents
}
46 changes: 39 additions & 7 deletions integration-test/src/step_definitions/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -111,7 +130,7 @@ function createEvent(id, status, orgCode, iuv) {
},
"transaction": {
"idTransaction": "123456",
"transactionId": "123456",
"transactionId": transactionId || "123456",
"grandTotal": 0,
"amount": 0,
"fee": 0
Expand All @@ -129,7 +148,7 @@ function createEvent(id, status, orgCode, iuv) {
}

function createReceipt(id, status) {
currentDate = new Date();
currentDate = new Date();
let receipt =
{
"eventId": id,
Expand Down Expand Up @@ -182,12 +201,25 @@ function createReceiptMessage(eventId, messageId) {
}
}

function createCart(id, bizEventIds, status) {
return {
"id": id,
"cartPaymentId": bizEventIds,
"totalNotice": 2,
"status": status
}
}

module.exports = {
TOKENIZED_FISCAL_CODE,
createEvent,
sleep,
createReceipt,
createReceiptError,
createReceiptMessage,
getRandomInt
getRandomInt,
createCart,
makeid,
createEventCart,
createEventWithIUVAndOrgCode
}
Loading

0 comments on commit 78b888e

Please sign in to comment.