Skip to content

Commit

Permalink
Merge pull request #523 from uktrade/feature/tet-680-order-receipt-pa…
Browse files Browse the repository at this point in the history
…ge-e2e-tests

create test data, add cypress tests for the receipt page
  • Loading branch information
Richard-Pentecost authored Apr 25, 2024
2 parents 5b56eae + 1724138 commit c8c08bd
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 21 deletions.
1 change: 0 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
projectId: "some-id",
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/_includes/cost-table.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table>
<table data-test="cost-table">
<thead>
<tr>
<th>Order number</th>
Expand Down
4 changes: 2 additions & 2 deletions src/app/views/_layouts/invoice.njk
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

{% block body_main_content %}
<p class="local-header__back u-print-hide">
<a href="/{{ publicToken }}">View your order history</a>
<a href="/{{ publicToken }}" data-test='view-order-history-link'>View your order history</a>
</p>

<img src="{{ getAssetPath('images/dbt-invoice-logo.png') }}" width="200"><br>

<h1>{{ heading | default('Invoice') }}</h1>
<h1 data-test='heading'>{{ heading | default('Invoice') }}</h1>

<div class="u-clearfix">
<div class="u-float-left u-max-half">
Expand Down
32 changes: 17 additions & 15 deletions src/app/views/receipt.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,29 @@
{% set creationDateValue = order.paid_on %}

{% block invoice_payment_information %}
<h2 class="heading-medium">
<h2 class="heading-medium" data-test="payments-heading">
Payment details
{% if payments.length > 1 %}
({{ payments.length }} {{ ' payment' | pluralise(payments.length) }})
<span>({{ payments.length }} payments)<span>
{% endif %}
</h2>

{% for payment in payments %}
{% if payments.length > 1 %}
<h3 class="heading-small">Payment {{ loop.index }}</h3>
{% endif %}
<div data-test="payment-{{ loop.index }}">
{% if payments.length > 1 %}
<h3 class="heading-small">Payment {{ loop.index }}</h3>
{% 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'
}) }}
</div>
{% endfor %}
{% endblock %}
95 changes: 95 additions & 0 deletions test/end-to-end/cypress/receipt-spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const { paidQuote } = require("../test-data");

describe("Reciept spec", () => {
const order = paidQuote;

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");
});
}
);

context("When on the 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");
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");
});
});
});
67 changes: 67 additions & 0 deletions test/end-to-end/test-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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",
payments: [
{ method: "Bacs", amount: "£500" },
{ method: "Manual", amount: "£500" },
],
};

0 comments on commit c8c08bd

Please sign in to comment.