Skip to content

Commit

Permalink
Merge pull request #50 from pagopa/PRDP-291-add-integration-tests-for…
Browse files Browse the repository at this point in the history
…-cart-api

[PRDP-291] feat: Add integration test for cart API
  • Loading branch information
pasqualespica authored Jan 10, 2024
2 parents 8ae2f7c + 2861070 commit 569a201
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 178 deletions.
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopareceiptpdfhelpdesk
description: Microservice description
type: application
version: 0.141.0
appVersion: 0.9.2
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
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
tag: "0.9.2"
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:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
tag: "0.9.2"
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:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: ""
image:
repository: ghcr.io/pagopa/pagopa-receipt-pdf-helpdesk
tag: "0.9.2"
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:
Expand Down
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
}
48 changes: 41 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 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, 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();
let currentDate = new Date();
let receipt =
{
"eventId": id,
Expand Down Expand Up @@ -182,12 +201,27 @@ function createReceiptMessage(eventId, messageId) {
}
}

function createCart(id, bizEventIds, status) {
let currentDate = new Date();
return {
"id": id,
"cartPaymentId": bizEventIds,
"totalNotice": 2,
"status": status,
"inserted_at": currentDate.getTime() - 360000,
}
}

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

0 comments on commit 569a201

Please sign in to comment.