Skip to content

Commit

Permalink
[PRDP-242] RecoverReceiptPdf integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
svariant committed Dec 11, 2023
1 parent 3a3a3c0 commit 1569f0c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
11 changes: 10 additions & 1 deletion integration-test/src/features/receipt_pdf_helpdesk.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ Feature: All about payment events to recover managed by Azure functions receipt-
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
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"

Scenario: regenerateReceiptPdf API retrieve the receipt with the given eventId and regenerate its pdf updating receipt's metadata
Given a receipt with eventId "receipt-helpdesk-int-test-id-10" and status "IO_NOTIFIED" stored into receipt datastore
And a biz event with id "receipt-helpdesk-int-test-id-10" and status "DONE" stored on biz-events datastore
When recoverNotNotifiedReceiptMassive API is called with bizEventId "receipt-helpdesk-int-test-id-10" as query param
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
13 changes: 12 additions & 1 deletion integration-test/src/step_definitions/blob_storage_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ async function deleteBlob(blobName) {
await blockBlobClient.deleteIfExists(options);
}

async function receiptPDFExist(blobName) {
let blobs = containerClient.listBlobsFlat();
for await (const blob of blobs) {
if (blob.name === blobName) {
return true;
}
}
return false;
}

module.exports = {
uploadBlobFromLocalPath,
deleteBlob
deleteBlob,
receiptPDFExist
}
6 changes: 3 additions & 3 deletions integration-test/src/step_definitions/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function createEvent(id, status, orgCode, iuv) {
return json_event
}

function createReceipt(id, status, pdfName) {
function createReceipt(id, status) {
let receipt =
{
"eventId": id,
Expand All @@ -147,8 +147,8 @@ function createReceipt(id, status, pdfName) {
"numRetry": 0,
"id": id
}
if (status === "NOTIFIED" || status === "GENERATED") {
receipt.mdAttach = { "name": pdfName, "url": pdfName };
if (status === "IO_NOTIFIED" || status === "GENERATED") {
receipt.mdAttach = { "name": "helpdesk-pdf-p.pdf", "url": "helpdesk-pdf-p.pdf" };
}
return receipt
}
Expand Down
39 changes: 25 additions & 14 deletions integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require('assert');
const { After, Given, When, Then, setDefaultTimeout } = require('@cucumber/cucumber');
let fs = require('fs');
const { sleep } = require("./common");
const { createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore, deleteAllTestBizEvents } = require("./biz_events_datastore_client");
const { createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore } = require("./biz_events_datastore_client");
const {
deleteDocumentFromReceiptsDatastore,
createDocumentInReceiptsDatastore,
Expand All @@ -11,9 +11,7 @@ const {
deleteDocumentFromReceiptErrorDatastore,
getDocumentFromReceiptsErrorDatastoreByBizEventId,
getDocumentFromReceiptsDatastoreByEventId,
deleteMultipleDocumentFromReceiptErrorDatastoreByEventId,
deleteAllTestReceipts,
deleteAllTestReceiptsError
deleteMultipleDocumentFromReceiptErrorDatastoreByEventId
} = require("./receipts_datastore_client");
const {
getReceipt,
Expand All @@ -27,7 +25,7 @@ const {
postRecoverNotNotifiedReceiptMassive,
postRegenerateReceiptPdf
} = require("./api_helpdesk_client");
const { uploadBlobFromLocalPath, deleteBlob } = require("./blob_storage_client");
const { uploadBlobFromLocalPath, deleteBlob, receiptPDFExist } = require("./blob_storage_client");

// set timeout for Hooks function, it allows to wait for long task
setDefaultTimeout(360 * 1000);
Expand Down Expand Up @@ -79,15 +77,6 @@ Given('a biz event with id {string} and status {string} stored on biz-events dat
assert.strictEqual(bizEventStoreResponse.statusCode, 201);
});

Given('a receipt with eventId {string} and status {string} stored into receipt datastore', async function (id, status) {
eventId = id;
// prior cancellation to avoid dirty cases
await deleteDocumentFromReceiptsDatastore(id);

let receiptsStoreResponse = await createDocumentInReceiptsDatastore(id, status);
assert.strictEqual(receiptsStoreResponse.statusCode, 201);
});

Given('a biz event with id {string} and status {string} and organizationFiscalCode {string} and IUV {string} stored on biz-events datastore', async function (id, status, orgCode, iuv) {
eventId = id;
// prior cancellation to avoid dirty cases
Expand All @@ -97,6 +86,15 @@ Given('a biz event with id {string} and status {string} and organizationFiscalCo
assert.strictEqual(bizEventStoreResponse.statusCode, 201);
});

Given('a receipt with eventId {string} and status {string} stored into receipt datastore', async function (id, status) {
eventId = id;
// prior cancellation to avoid dirty cases
await deleteDocumentFromReceiptsDatastore(id);

let receiptsStoreResponse = await createDocumentInReceiptsDatastore(id, status);
assert.strictEqual(receiptsStoreResponse.statusCode, 201);
});

Given('a receipt-error with bizEventId {string} and status {string} stored into receipt-error datastore', async function (id, status) {
eventId = id;
// prior cancellation to avoid dirty cases
Expand Down Expand Up @@ -181,6 +179,10 @@ When("recoverNotNotifiedReceiptMassive API is called with status {string} as que
responseAPI = await postRecoverNotNotifiedReceiptMassive(status);
});

When('recoverNotNotifiedReceiptMassive API is called with bizEventId {string} as query param', async function (id) {
responseAPI = await postRegenerateReceiptPdf(id);
});

//Then
Then('the api response has a {int} Http status', function (expectedStatus) {
assert.strictEqual(responseAPI.status, expectedStatus);
Expand Down Expand Up @@ -227,6 +229,15 @@ Then("the list of receipt is recovered from datastore and no receipt in the list
}
});

Then('the receipt has attachment metadata', function () {
assert.strictEqual(receipt.mdAttachment != null || receipt.mdAttachment != "", true);
});

Then('the PDF is present on blob storage', async function () {
let blobExist = await receiptPDFExist(receiptPdfFileName);
assert.strictEqual(true, blobExist);
});

Then("wait {int} ms", async function (milliSec) {
sleep(milliSec)
});
Expand Down

0 comments on commit 1569f0c

Please sign in to comment.