From 1e026998c5cfa111e9236ec703653e01e834149c Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 25 Apr 2024 11:01:55 +0100 Subject: [PATCH 1/3] Use new image for OMIS tests --- docker-compose.backend.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.backend.yml b/docker-compose.backend.yml index f26ee72..a4cfdbb 100644 --- a/docker-compose.backend.yml +++ b/docker-compose.backend.yml @@ -5,7 +5,7 @@ services: - api api: - image: gcr.io/sre-docker-registry/github.com/uktrade/data-hub-api:main + image: gcr.io/sre-docker-registry/data-hub-api:latest env_file: .env environment: DEBUG: "False" @@ -37,7 +37,7 @@ services: command: /app/setup-uat.sh || echo "all good" rq: - image: gcr.io/sre-docker-registry/github.com/uktrade/data-hub-api:main + image: gcr.io/sre-docker-registry/data-hub-api:latest env_file: .env depends_on: - postgres From 50193bb2cda4e0a654eeacee995cedfec66a1d28 Mon Sep 17 00:00:00 2001 From: Richard Pentecost Date: Wed, 24 Apr 2024 11:48:11 +0100 Subject: [PATCH 2/3] create test data, add cypress tests for the receipt page --- cypress.config.js | 2 +- src/app/views/_includes/cost-table.njk | 2 +- src/app/views/_layouts/invoice.njk | 4 +- src/app/views/receipt.njk | 32 ++++---- test/end-to-end/cypress/receipt-spec.cy.js | 95 ++++++++++++++++++++++ test/end-to-end/test-data.js | 68 ++++++++++++++++ 6 files changed, 184 insertions(+), 19 deletions(-) create mode 100644 test/end-to-end/cypress/receipt-spec.cy.js create mode 100644 test/end-to-end/test-data.js diff --git a/cypress.config.js b/cypress.config.js index a817c24..a7e9ca6 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,7 +1,7 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ - projectId: "some-id", + // projectId: "some-id", e2e: { setupNodeEvents(on, config) { // implement node event listeners here diff --git a/src/app/views/_includes/cost-table.njk b/src/app/views/_includes/cost-table.njk index 09e913a..79c8c64 100644 --- a/src/app/views/_includes/cost-table.njk +++ b/src/app/views/_includes/cost-table.njk @@ -1,4 +1,4 @@ - +
diff --git a/src/app/views/_layouts/invoice.njk b/src/app/views/_layouts/invoice.njk index 293708d..cae2a69 100644 --- a/src/app/views/_layouts/invoice.njk +++ b/src/app/views/_layouts/invoice.njk @@ -23,12 +23,12 @@ {% block body_main_content %}

- View your order history + View your order history


-

{{ heading | default('Invoice') }}

+

{{ heading | default('Invoice') }}

diff --git a/src/app/views/receipt.njk b/src/app/views/receipt.njk index 8015ab8..3eb3028 100644 --- a/src/app/views/receipt.njk +++ b/src/app/views/receipt.njk @@ -5,27 +5,29 @@ {% set creationDateValue = order.paid_on %} {% block invoice_payment_information %} -

+

Payment details {% if payments.length > 1 %} - ({{ payments.length }} {{ ' payment' | pluralise(payments.length) }}) + ({{ payments.length }} payments) {% endif %}

{% for payment in payments %} - {% if payments.length > 1 %} -

Payment {{ loop.index }}

- {% endif %} +
+ {% if payments.length > 1 %} +

Payment {{ loop.index }}

+ {% endif %} - {{ MetaList({ - items: [ - { label: 'Method', value: payment.method | sentenceCase }, - { label: 'Amount received', value: payment.amount | formatCurrency }, - { label: 'Received on', value: payment.received_on, type: 'date' }, - { label: 'Transaction reference', value: payment.transaction_reference } - ], - modifier: 'stacked', - itemModifier: 'stacked' - }) }} + {{ MetaList({ + items: [ + { label: 'Method', value: payment.method | sentenceCase }, + { label: 'Amount received', value: payment.amount | formatCurrency }, + { label: 'Received on', value: payment.received_on, type: 'date' }, + { label: 'Transaction reference', value: payment.transaction_reference } + ], + modifier: 'stacked', + itemModifier: 'stacked' + }) }} +
{% endfor %} {% endblock %} diff --git a/test/end-to-end/cypress/receipt-spec.cy.js b/test/end-to-end/cypress/receipt-spec.cy.js new file mode 100644 index 0000000..8eb24d8 --- /dev/null +++ b/test/end-to-end/cypress/receipt-spec.cy.js @@ -0,0 +1,95 @@ +const { paidQuote } = require("../test-data"); + +describe("reciept spec", () => { + const order = paidQuote; + + describe("clicking on the 'View your payment receipt' in the order page", () => { + it("should take you to the reciept page", () => { + cy.visit(`http://localhost:4000/${order.public_token}`); + cy.contains("View your payment receipt").click(); + cy.get('[data-test="heading"]') + .should("exist") + .and("have.text", "Receipt"); + }); + }); + + describe("receipt page", () => { + beforeEach(() => { + cy.visit(`http://localhost:4000/${order.public_token}/receipt`); + }); + + it("should show the address of the company the receipt is for", () => { + cy.contains("To") + .should("exist") + .parent() + .and("contain", order.billing_company_name) + .and("contain", order.billing_address_town) + .and("contain", order.billing_address_1) + .and("contain", order.billing_address_postcode) + .and("contain", order.billing_address_country); + }); + + it("should show the invoice number and a receipt date", () => { + cy.contains("Invoice number") + .should("exist") + .parent() + .and("contain", order.invoice_number); + cy.contains("Receipt date").should("exist"); + }); + + it("should show the invoice adderss and VAT number", () => { + cy.contains("From").should("exist"); + cy.contains("VAT number").should("exist"); + }); + + it("should show a table with the order number, the description and the amount", () => { + cy.get('[data-test="cost-table"]') + .should("exist") + .and("contain", order.reference) + .and("contain", `UK Government support in ${order.primaryMarket.name}`) + .and("contain", order.subtotal_cost); + }); + + it("should show the payments heading with the number of payments that were made", () => { + cy.get('[data-test="payments-heading"]') + .should("exist") + .and("contain", "Payment details") + .children() + .and("contain", `(${order.payments.length} payments)`); + }); + + it("should show the information for each payment", () => { + cy.get('[data-test="payment-1"]') + .should("exist") + .and("contain", "Payment 1") + .and("contain", "Method") + .and("contain", order.payments[0].method) + .and("contain", "Amount received") + .and("contain", order.payments[0].amount) + .and("contain", "Received on"); + + cy.get('[data-test="payment-2"]') + .should("exist") + .and("contain", "Payment 2") + .and("contain", "Method") + .and("contain", order.payments[1].method) + .and("contain", "Amount received") + .and("contain", order.payments[1].amount) + .and("contain", "Received on"); + }); + + it("should take you to the order history page when clicking 'View you order history' link", () => { + cy.get('[data-test="view-order-history-link"]') + .should("exist") + .click() + .location("pathname") + .should("eq", `/${order.public_token}`); + + cy.contains("Your order").should("exist"); + }); + + it("should have a 'Print this page' link", () => { + cy.contains("Print this page").should("exist"); + }); + }); +}); diff --git a/test/end-to-end/test-data.js b/test/end-to-end/test-data.js new file mode 100644 index 0000000..f569c93 --- /dev/null +++ b/test/end-to-end/test-data.js @@ -0,0 +1,68 @@ +export const quoteAwaitingAcceptance = { + reference: "WHY589/23", + created_on: "2024-03-08T13:56:12.108209Z", + company: "fc3530bc-383c-4b18-94c8-8fbe918bee31", + contact: "9b1138ab-ec7b-497f-b8c3-27fed21694ef", + primary_market: "5daf72a6-5d95-e211-a939-e4115bead28a ", + sector: "355f977b-8ac3-e211-a646-e4115bead28a", + service_types: ["22fc9edd-41a5-4182-ba4e-baacc681d5f7"], + description: "test order", + public_token: "7AGZC7uaAIV-5L34J5lnZXHvFG9J1xnbBQnieAUCn-LRJpr-QA", + delivery_date: "2030-05-07", + discount_value: 0, + vat_status: "outside_eu", + net_cost: 500000, + subtotal_cost: 500000, + vat_cost: 0, + total_cost: 500000, + billing_company_name: "Motorleaf", + billing_address_1: "5000 Rue Saint-Patrick,", + billing_address_town: "Montréal", + billing_address_postcode: "H4E 1A8", + billing_address_country: "Canada", +}; + +export const acceptedQuote = { + reference: "RYM547/24", + created_on: "2024-03-08T13:56:12.108209Z", + company: "fc3530bc-383c-4b18-94c8-8fbe918bee31", + contact: "9b1138ab-ec7b-497f-b8c3-27fed21694ef", + primary_market: "5daf72a6-5d95-e211-a939-e4115bead28a", + sector: "355f977b-8ac3-e211-a646-e4115bead28a", + service_types: ["22fc9edd-41a5-4182-ba4e-baacc681d5f7"], + description: "test order", + public_token: "XXMPH3b2185a7Vpe2f3RiI5HXT0Nshrck_6xGJuRp4UAsA6vkQ", + delivery_date: "2030-05-07", + discount_value: 0, + vat_status: "outside_eu", + net_cost: 500000, + subtotal_cost: 500000, + vat_cost: 0, + total_cost: 500000, + billing_company_name: "Motorleaf", + billing_address_1: "5000 Rue Saint-Patrick,", + billing_address_town: "Montréal", + billing_address_postcode: "H4E 1A8", + billing_address_country: "Canada", +}; + +export const paidQuote = { + reference: "CJC167/23", + status: "draft", + description: "test order paid", + public_token: "h93Dn7DKvMLbUB5Yz2h5z7dL1mXXGUa_UiPNBkVoyKLmBE29YQ", + primaryMarket: { name: "Canada" }, + delivery_date: "2030-05-07", + vat_status: "outside_eu", + subtotal_cost: "£1,000.00", + billing_company_name: "Motorleaf", + billing_address_1: "5000 Rue Saint-Patrick,", + billing_address_town: "Montréal", + billing_address_postcode: "H4E 1A8", + billing_address_country: "Canada", + invoice_number: "202404230002", + payments: [ + { method: "Bacs", amount: "£500" }, + { method: "Manual", amount: "£500" }, + ], +}; From 1724138de2023bc483654c2428318586eaafd9a5 Mon Sep 17 00:00:00 2001 From: Richard Pentecost Date: Wed, 24 Apr 2024 11:53:39 +0100 Subject: [PATCH 3/3] remove project id from cypress config because project is not registered with cypress --- cypress.config.js | 1 - test/end-to-end/cypress/receipt-spec.cy.js | 30 +++++++++++----------- test/end-to-end/test-data.js | 1 - 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index a7e9ca6..97f47c4 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,7 +1,6 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ - // projectId: "some-id", e2e: { setupNodeEvents(on, config) { // implement node event listeners here diff --git a/test/end-to-end/cypress/receipt-spec.cy.js b/test/end-to-end/cypress/receipt-spec.cy.js index 8eb24d8..cfcbcad 100644 --- a/test/end-to-end/cypress/receipt-spec.cy.js +++ b/test/end-to-end/cypress/receipt-spec.cy.js @@ -1,19 +1,22 @@ const { paidQuote } = require("../test-data"); -describe("reciept spec", () => { +describe("Reciept spec", () => { const order = paidQuote; - describe("clicking on the 'View your payment receipt' in the order page", () => { - it("should take you to the reciept page", () => { - cy.visit(`http://localhost:4000/${order.public_token}`); - cy.contains("View your payment receipt").click(); - cy.get('[data-test="heading"]') - .should("exist") - .and("have.text", "Receipt"); - }); - }); + context( + "When clicking on the 'View your payment receipt' in the order page", + () => { + it("should take you to the receipt page", () => { + cy.visit(`http://localhost:4000/${order.public_token}`); + cy.contains("View your payment receipt").click(); + cy.get('[data-test="heading"]') + .should("exist") + .and("have.text", "Receipt"); + }); + } + ); - describe("receipt page", () => { + context("When on the receipt page", () => { beforeEach(() => { cy.visit(`http://localhost:4000/${order.public_token}/receipt`); }); @@ -30,10 +33,7 @@ describe("reciept spec", () => { }); it("should show the invoice number and a receipt date", () => { - cy.contains("Invoice number") - .should("exist") - .parent() - .and("contain", order.invoice_number); + cy.contains("Invoice number").should("exist"); cy.contains("Receipt date").should("exist"); }); diff --git a/test/end-to-end/test-data.js b/test/end-to-end/test-data.js index f569c93..ec40750 100644 --- a/test/end-to-end/test-data.js +++ b/test/end-to-end/test-data.js @@ -60,7 +60,6 @@ export const paidQuote = { billing_address_town: "Montréal", billing_address_postcode: "H4E 1A8", billing_address_country: "Canada", - invoice_number: "202404230002", payments: [ { method: "Bacs", amount: "£500" }, { method: "Manual", amount: "£500" },
Order number