diff --git a/integration-test/src/features/receipt_pdf_helpdesk.feature b/integration-test/src/features/receipt_pdf_helpdesk.feature index ef29405..66b5d2e 100644 --- a/integration-test/src/features/receipt_pdf_helpdesk.feature +++ b/integration-test/src/features/receipt_pdf_helpdesk.feature @@ -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 \ No newline at end of file diff --git a/integration-test/src/step_definitions/blob_storage_client.js b/integration-test/src/step_definitions/blob_storage_client.js index cd1dfdd..7edf5f3 100644 --- a/integration-test/src/step_definitions/blob_storage_client.js +++ b/integration-test/src/step_definitions/blob_storage_client.js @@ -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 } \ 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 5aa7012..5a199b1 100644 --- a/integration-test/src/step_definitions/common.js +++ b/integration-test/src/step_definitions/common.js @@ -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, @@ -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 } 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 a53f234..2e6d535 100644 --- a/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js +++ b/integration-test/src/step_definitions/receipt_pdf_helpdesk_step.js @@ -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, @@ -11,9 +11,7 @@ const { deleteDocumentFromReceiptErrorDatastore, getDocumentFromReceiptsErrorDatastoreByBizEventId, getDocumentFromReceiptsDatastoreByEventId, - deleteMultipleDocumentFromReceiptErrorDatastoreByEventId, - deleteAllTestReceipts, - deleteAllTestReceiptsError + deleteMultipleDocumentFromReceiptErrorDatastoreByEventId } = require("./receipts_datastore_client"); const { getReceipt, @@ -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); @@ -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 @@ -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 @@ -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); @@ -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) });