Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PRDP-242] Defined integration tests #27

Merged
merged 42 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e88f9bd
[PRDP-242] Updated int test env
svariant Dec 7, 2023
6d703d1
[PRDP-242] Update git ignore
svariant Dec 7, 2023
ddefada
[PRDP-242] Defined first integration steps
svariant Dec 7, 2023
e984f11
[PRDP-242] Implemented api & blob client and updated other clients
svariant Dec 7, 2023
e88ae15
[PRDP-242] Defined test methods
svariant Dec 7, 2023
ded22f0
[PRDP-242] Fixed APIs endpoints
svariant Dec 7, 2023
871579e
[PRDP-242] Added AES encryption envs to readme
svariant Dec 7, 2023
9c909ae
Merge remote-tracking branch 'origin/fix-schedule-env-vars' into PRDP…
svariant Dec 7, 2023
b7049f8
[PRDP-242] Fixed getReceiptError test
svariant Dec 7, 2023
624a6f8
[PRDP-242] ReceiptToReviewed test
svariant Dec 7, 2023
8b3a784
[PRDP-243] RecoverFailedReceipt tests - defined all api methods
svariant Dec 7, 2023
84b1036
[PRDP-242] RecoverFailedMassive test
svariant Dec 7, 2023
2390eb6
[PRDP-242] RecoverNotNotifedReceipt test
svariant Dec 7, 2023
5708d27
[PRDP-242] RecoverNotNotifedMassive test
svariant Dec 7, 2023
05f1c8c
[PRDP-242] Improved steps
svariant Dec 7, 2023
f644627
[PRDP-242] Removed sleep
svariant Dec 7, 2023
17ab40b
[PRDP-242] Added teardown script to clean up after 5minutes from test
svariant Dec 7, 2023
4a8cb8b
[PRDP-242] Fix typo
svariant Dec 7, 2023
3a3a3c0
Merge remote-tracking branch 'origin/main' into PRDP-242-integration-…
svariant Dec 7, 2023
1569f0c
[PRDP-242] RecoverReceiptPdf integration test
svariant Dec 11, 2023
96a5f39
[PRDP-242] Fix env docker int test
svariant Dec 11, 2023
f9ba147
[PRDP-242] Moved int test teardown to github workflows
svariant Dec 11, 2023
20ed12f
[PRDP-242] Moved teardown to own step
svariant Dec 11, 2023
252341b
[PRDP-242] Code review teardown condition
svariant Dec 11, 2023
2731f82
[PRDP-242] Added always condition to teardown
svariant Dec 11, 2023
02d2720
[PRDP-242] Improved worflows conditions
svariant Dec 11, 2023
4d36670
[PRDP-242] Added login&checkout steps to workflows
svariant Dec 11, 2023
cfc3b1b
[PRDP-242] Updated helpdesk url int test local
svariant Dec 11, 2023
b0da4f6
[PRDP-242] Fixed teardown shell
svariant Dec 11, 2023
3813b50
[PRDP-242] Changed blobStorage client connection
svariant Dec 11, 2023
db2d761
[PRDP-242] Changed storage conn string env
svariant Dec 11, 2023
9d26032
[PRDP-242] Modified teardown step
svariant Dec 11, 2023
31b6e1f
[PRDP-242] Added storage conn string to identity
svariant Dec 11, 2023
dc04f89
[PRDP-242] Moved teardown step in integration test action
svariant Dec 12, 2023
4304c36
[PRDP-242] Lowered sleep
svariant Dec 12, 2023
efff054
[PRDP-242] Commented teardown
svariant Dec 12, 2023
659a8c2
[PRDP-242] Fix feature step regenerate description
svariant Dec 12, 2023
d80d48c
[PRDP-242] Added storage conn string to integration test action
svariant Dec 12, 2023
f5a35b7
Merge branch 'fix-schedule-env-vars' into PRDP-242-integration-tests
svariant Dec 12, 2023
9fb3b1e
Merge remote-tracking branch 'origin/main' into PRDP-242-integration-…
svariant Dec 12, 2023
e54db86
[PRDP-242] Added template.zip
svariant Dec 12, 2023
8ccd3c2
[PRDP-242] Fixed filename extension + int test
svariant Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ hs_err_pid*
local.settings.json
bin/
obj/
**/.identity
**/.identity
.azure/

package-lock.json
yarn.lock
.env
node_modules/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ then replace env variables with correct values
| `MAX_DATE_DIFF_NOTIFY_MILLIS` | Difference in millis between the current time and the date from witch the<br/> receipts to notify will be fetched in massive recover operation | 360000 |
| `RECOVER_FAILED_CRON` | CRON expression for timer trigger function that recover failed receipt | |
| `TRIGGER_GEN_SCHEDULE` | CRON expression for timer trigger function that recover nor notified generater receipt | |
| `AES_SECRET_KEY` | AES encryption secret key | |
| `AES_SALT` | AES encryption salt | |

> to doc details about AZ fn config
> see [here](https://stackoverflow.com/questions/62669672/azure-functions-what-is-the-purpose-of-having-host-json-and-local-settings-jso)
Expand Down
2 changes: 1 addition & 1 deletion helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: pagopareceiptpdfhelpdesk
description: Microservice description
type: application
version: 0.105.0
appVersion: 0.6.4-fix-schedule-env-vars
appVersion: 0.6.4
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.6.4-fix-schedule-env-vars"
tag: "0.6.4"
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.6.4-fix-schedule-env-vars"
tag: "0.6.4"
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.6.4-fix-schedule-env-vars"
tag: "0.6.4"
pullPolicy: Always
# https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Controllers/HostController.cs
livenessProbe:
Expand Down
7 changes: 4 additions & 3 deletions integration-test/run_integration_test.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# example: sh ./run_integration_test.sh <local|dev|uat|prod>
set -e

# run integration tests
cd ./src || exit
yarn install
yarn test:"$1"
yarn test:"$1" || true
echo "Sleeping for 300 seconds (5 minutes) before running teardown"
sleep 300
yarn teardown:"$1"
9 changes: 8 additions & 1 deletion integration-test/src/config/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events
RECEIPTS_COSMOS_CONN_STRING=<cosmos-connection-string>
RECEIPT_COSMOS_DB_NAME=db
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
RECEIPT_ERROR_COSMOS_DB_CONTAINER_NAME=receipts-message-errors

HELPDESK_URL=https://api.dev.platform.pagopa.it/receipts/helpdesk/v1/recoverFailed
BLOB_STORAGE_ACCOUNT_KEY=<storage-account-key>
BLOB_STORAGE_ACCOUNT_NAME=pagopadweureceiptsfnsa
BLOB_STORAGE_CONTAINER_NAME=pagopa-d-weu-receipts-azure-blob-receipt-st-attach

ENVIRONMENT=dev

HELPDESK_URL=https://api.dev.platform.pagopa.it/receipts/helpdesk/v1/
11 changes: 10 additions & 1 deletion integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events

RECEIPTS_COSMOS_CONN_STRING=<cosmos-connection-string>
RECEIPT_COSMOS_DB_NAME=db
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
RECEIPT_ERROR_COSMOS_DB_CONTAINER_NAME=receipts-message-errors

BLOB_STORAGE_ACCOUNT_KEY=<storage-account-key>
BLOB_STORAGE_ACCOUNT_NAME=pagopadweureceiptsfnsa
BLOB_STORAGE_CONTAINER_NAME=pagopa-d-weu-receipts-azure-blob-receipt-st-attach

ENVIRONMENT=local

HELPDESK_URL=http://localhost:53488/
9 changes: 8 additions & 1 deletion integration-test/src/config/.env.uat
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events
RECEIPTS_COSMOS_CONN_STRING=<cosmos-connection-string>
RECEIPT_COSMOS_DB_NAME=db
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
RECEIPT_ERROR_COSMOS_DB_CONTAINER_NAME=receipts-message-errors

HELPDESK_URL=https://api.uat.platform.pagopa.it/receipts/helpdesk/v1/recoverFailed
BLOB_STORAGE_ACCOUNT_KEY=<storage-account-key>
BLOB_STORAGE_ACCOUNT_NAME=pagopauweureceiptsfnsa
BLOB_STORAGE_CONTAINER_NAME=pagopa-u-weu-receipts-azure-blob-receipt-st-attach

ENVIRONMENT=uat

HELPDESK_URL=https://api.uat.platform.pagopa.it/receipts/helpdesk/v1/
79 changes: 59 additions & 20 deletions integration-test/src/features/receipt_pdf_helpdesk.feature
Original file line number Diff line number Diff line change
@@ -1,24 +1,63 @@
Feature: All about payment events to recover managed by Azure functions receipt-pdf-helpdesk

Scenario: a biz event stored on biz-events datastore is stored into receipts datastore
Given a random biz event with id "receipt-helpdesk-int-test-id-1" stored on biz-events datastore with status DONE
When biz event has been properly stored into receipt datastore after 10000 ms with eventId "receipt-helpdesk-int-test-id-1"
Then the receipts datastore returns the receipt
Scenario: getReceipt API return receipt stored on datastore
Given a receipt with eventId "receipt-helpdesk-int-test-id-1" and status "TO_REVIEW" stored into receipt datastore
When getReceipt API is called with eventId "receipt-helpdesk-int-test-id-1"
Then the api response has a 200 Http status
And the receipt has eventId "receipt-helpdesk-int-test-id-1"

Given a random receipt with id "receipt-helpdesk-int-test-id-1" stored with status FAILED
When HTTP recovery request is called
Then response has a 200 Http status
And the receipt has not the status "helpdesk" after 10000 ms

Given a random receipt with id "receipt-helpdesk-int-test-id-1" stored with status FAILED
When HTTP recovery request is called without eventId
Then response has a 200 Http status
And the receipt has not the status "FAILED" after 10000 ms

Scenario: a receipt stored on datastore with wrong or missing attachment requires regeneration
Given a receipt with id "receipt-helpdesk-int-test-id-5" stored into receipt datastore
And a biz-event id "receipt-helpdesk-int-test-id-5" stored into biz-event datastore
When HTTP regenerate request is called
Then response has a 200 Http status
And the receipt has the attachment
Scenario: getReceiptByOrganizationFiscalCodeAndIUV API return receipt stored on datastore
Given a receipt with eventId "receipt-helpdesk-int-test-id-2" and status "TO_REVIEW" stored into receipt datastore
And a biz event with id "receipt-helpdesk-int-test-id-2" and status "DONE" and organizationFiscalCode "intTestOrgCode" and IUV "intTestIuv" stored on biz-events datastore
When getReceiptByOrganizationFiscalCodeAndIUV API is called with organizationFiscalCode "intTestOrgCode" and IUV "intTestIuv"
Then the api response has a 200 Http status
And the receipt has eventId "receipt-helpdesk-int-test-id-2"

Scenario: getReceiptError API return receipt-error stored on datastore
Given a receipt-error with bizEventId "receipt-helpdesk-int-test-id-3" and status "TO_REVIEW" stored into receipt-error datastore
When getReceiptError API is called with bizEventId "receipt-helpdesk-int-test-id-3"
Then the api response has a 200 Http status
And the receipt-error has bizEventId "receipt-helpdesk-int-test-id-3"
And the receipt-error payload has bizEvent decrypted with eventId "receipt-generator-int-test-id-4"

Scenario: getReceiptPdf API return receipt pdf store on blob storage
Given a receipt pdf with filename "int-test-helpdesk-receipt.pdf" stored into blob storage
When getReceiptPdf API is called with filename "int-test-helpdesk-receipt.pdf"
Then the api response has a 200 Http status

Scenario: receiptToReviewed API retrieve a receipt error and updates its status to REVIEWED
Given a receipt-error with bizEventId "receipt-helpdesk-int-test-id-5" and status "TO_REVIEW" stored into receipt-error datastore
When receiptToReviewed API is called with bizEventId "receipt-helpdesk-int-test-id-5"
Then the api response has a 200 Http status
And the receipt-error with bizEventId "receipt-helpdesk-int-test-id-5" is recovered from datastore
And the receipt-error has not status "TO_REVIEW"

Scenario: recoverFailedReceipt API retrieve a receipt in status FAILED and updates its status
Given a receipt with eventId "receipt-helpdesk-int-test-id-6" and status "FAILED" stored into receipt datastore
And a biz event with id "receipt-helpdesk-int-test-id-6" and status "DONE" stored on biz-events datastore
When recoverFailedReceipt API is called with eventId "receipt-helpdesk-int-test-id-6"
Then the api response has a 200 Http status
And the receipt with eventId "receipt-helpdesk-int-test-id-6" is recovered from datastore
And the receipt has not status "FAILED"

Scenario: recoverFailedReceiptMassive API retrieve all the receipts in status FAILED and updates their status
Given a list of 5 receipts in status "FAILED" stored into receipt datastore starting from eventId "receipt-helpdesk-int-test-id-7"
And a list of 5 biz events in status "DONE" stored into biz-events datastore starting from eventId "receipt-helpdesk-int-test-id-7"
When recoverFailedReceiptMassive API is called with status "FAILED" as query param
Then the api response has a 200 Http status
And the list of receipt is recovered from datastore and no receipt in the list has status "FAILED"

Scenario: recoverNotNotifiedReceipt API retrieve a receipt in status IO_ERROR_TO_NOTIFY and updates its status
Given a receipt with eventId "receipt-helpdesk-int-test-id-8" and status "IO_ERROR_TO_NOTIFY" stored into receipt datastore
And a biz event with id "receipt-helpdesk-int-test-id-8" and status "DONE" stored on biz-events datastore
When recoverNotNotifiedReceipt API is called with eventId "receipt-helpdesk-int-test-id-8"
Then the api response has a 200 Http status
And the receipt with eventId "receipt-helpdesk-int-test-id-8" is recovered from datastore
And the receipt has not status "IO_ERROR_TO_NOTIFY"

Scenario: recoverNotNotifiedReceiptMassive API retrieve all the receipts in status IO_ERROR_TO_NOTIFY and updates their status
Given a list of 5 receipts in status "IO_ERROR_TO_NOTIFY" stored into receipt datastore starting from eventId "receipt-helpdesk-int-test-id-9"
And a list of 5 biz events in status "DONE" stored into biz-events datastore starting from eventId "receipt-helpdesk-int-test-id-9"
When recoverNotNotifiedReceiptMassive API is called with status "IO_ERROR_TO_NOTIFY" as query param
Then the api response has a 200 Http status
And the list of receipt is recovered from datastore and no receipt in the list has status "IO_ERROR_TO_NOTIFY"
4 changes: 4 additions & 0 deletions integration-test/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"test:local": "dotenv -e ./config/.env.local yarn cucumber",
"test:dev": "dotenv -e ./config/.env.dev yarn cucumber",
"test:uat": "dotenv -e ./config/.env.uat yarn cucumber",
"teardown": "dotenv -e ./config/.env.local node script/teardown_script.js",
"teardown:local": "dotenv -e ./config/.env.local node script/teardown_script.js",
"teardown:dev": "dotenv -e ./config/.env.dev node script/teardown_script.js",
"teardown:uat": "dotenv -e ./config/.env.uat node script/teardown_script.js",
"cucumber": "npx cucumber-js --publish -r step_definitions"
},
"devDependencies": {
Expand Down
109 changes: 109 additions & 0 deletions integration-test/src/script/teardown_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const { CosmosClient } = require("@azure/cosmos");
const { BlobServiceClient, StorageSharedKeyCredential } = require('@azure/storage-blob');
const { TOKENIZED_FISCAL_CODE } = require("../step_definitions/common");

//COSMOS RECEIPT
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 client = new CosmosClient(cosmos_db_conn_string);
const receiptContainer = client.database(databaseId).container(receiptContainerId);
const receiptErrorContainer = client.database(databaseId).container(receiptErrorContainerId);

//COSMOS BIZEVENT
const biz_cosmos_db_conn_string = process.env.BIZEVENTS_COSMOS_CONN_STRING;
const bizDatabaseId = process.env.BIZ_EVENT_COSMOS_DB_NAME; // es. db
const bizContainerId = process.env.BIZ_EVENT_COSMOS_DB_CONTAINER_NAME; // es. biz-events

const bizClient = new CosmosClient(biz_cosmos_db_conn_string);
const bizContainer = bizClient.database(bizDatabaseId).container(bizContainerId);

//BLOB
const blobStorageContainerName = process.env.BLOB_STORAGE_CONTAINER_NAME;

const accountName = process.env.BLOB_STORAGE_ACCOUNT_NAME;
if (!accountName) throw Error("Azure Storage accountName not found");

const accountKey = process.env.BLOB_STORAGE_ACCOUNT_KEY;
if (!accountKey) throw Error("Azure Storage accountKey not found");

const sharedKeyCredential = new StorageSharedKeyCredential(
accountName,
accountKey
);

const blobServiceClient = new BlobServiceClient(`https://${accountName}.blob.core.windows.net`, sharedKeyCredential);
const containerClient = blobServiceClient.getContainerClient(blobStorageContainerName);


const deleteDocumentFromAllDatabases = async () => {
let { resources } = await receiptContainer.items.query({
query: "SELECT * from c WHERE c.eventData.debtorFiscalCode = @fiscalCode",
parameters: [{ name: "@fiscalCode", value: TOKENIZED_FISCAL_CODE }]
}).fetchAll();

console.info(`Found n. ${resources?.length} receipts in the database`);

for (const el of resources) {
console.log("Cleaning documents linked to receipts with id: " + el.id);

//Delete PDF from Blob Storage
if (el?.mdAttach?.name?.length > 1) {
let response = await containerClient.getBlockBlobClient(el.mdAttach.name).deleteIfExists();
if (response._response.status !== 202) {
console.error(`Error deleting PDF ${el.id}`);
}
console.log("RESPONSE DELETE PDF STATUS", response._response.status);
}
if (el?.mdAttachPayer?.name?.length > 1) {
let response = await containerClient.getBlockBlobClient(el.mdAttachPayer.name).deleteIfExists();
if (response._response.status !== 202) {
console.error(`Error deleting PDF ${el.id}`);
}
console.log("RESPONSE DELETE PDF STATUS", response._response.status);
}

//Delete Receipt from CosmosDB
try {
await receiptContainer.item(el.id, el.id).delete();
} catch (error) {
if (error.code !== 404) {
console.error(`Error deleting receipt ${el.id}`);
}
}

//Delete Receipt error from CosmosDB
try {
let response = await receiptErrorContainer.items.query({
query: "SELECT * from c WHERE c.bizEventId = @bizEventId",
parameters: [{ name: "@bizEventId", value: el.eventId }]
}).fetchAll();

let resourcesError = response.resources;

for (let error of resourcesError) {
await receiptErrorContainer.item(error.id, error.id).delete();
}
} catch (error) {
if (error.code !== 404) {
console.error(`Error deleting receipt error ${el.eventId}`);
}
}

//Delete BizEvent from CosmosDB
try {
await bizContainer.item(el.eventId, el.eventId).delete();
} catch (error) {
if (error.code !== 404) {
console.error(`Error deleting bizevent ${el.eventId}`);
}
}

console.log(`DONE ${el.id}`)
}

};

deleteDocumentFromAllDatabases();
Loading
Loading