From 6f70225270541f9d90367001f449ae598878bc6b Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Fri, 29 Nov 2024 14:17:38 +0000 Subject: [PATCH] revert flows change and add expect to makePaymentRequest --- .../src/create-flow-with-geospatial.spec.ts | 2 +- e2e/tests/ui-driven/src/create-flow.spec.ts | 4 +- e2e/tests/ui-driven/src/helpers/context.ts | 39 ++++++++----------- .../ui-driven/src/helpers/globalHelpers.ts | 4 +- .../ui-driven/src/helpers/userActions.ts | 3 +- .../ui-driven/src/invite-to-pay/agent.spec.ts | 10 ++--- .../ui-driven/src/invite-to-pay/helpers.ts | 6 +-- .../src/invite-to-pay/nominee.spec.ts | 15 +++---- e2e/tests/ui-driven/src/pay.spec.ts | 7 ++-- .../ui-driven/src/save-and-return.spec.ts | 5 +-- e2e/tests/ui-driven/src/sections.spec.ts | 10 ++--- 11 files changed, 48 insertions(+), 57 deletions(-) diff --git a/e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts b/e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts index 5a41195bfa..991dcd0bc5 100644 --- a/e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts +++ b/e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts @@ -45,7 +45,7 @@ test.describe("Flow creation, publish and preview", () => { await editor.addNewService(); // update context to allow flow to be torn down - context.flows = [{ ...serviceProps }]; + context.flow = { ...serviceProps }; await editor.createFindProperty(); await expect(editor.nodeList).toContainText(["Find property"]); diff --git a/e2e/tests/ui-driven/src/create-flow.spec.ts b/e2e/tests/ui-driven/src/create-flow.spec.ts index dab9f9d4db..2c83eab2c6 100644 --- a/e2e/tests/ui-driven/src/create-flow.spec.ts +++ b/e2e/tests/ui-driven/src/create-flow.spec.ts @@ -67,7 +67,7 @@ test.describe("Flow creation, publish and preview", () => { await editor.addNewService(); // update context to allow flow to be torn down - context.flows = [{ ...serviceProps }]; + context.flow = { ...serviceProps }; await editor.createQuestion(); await editor.createNoticeOnEachBranch(); @@ -199,7 +199,7 @@ test.describe("Flow creation, publish and preview", () => { await editor.addNewService(); // update context to allow new flow to be torn down - context.flows?.push({ ...externalPortalServiceProps }); + context.externalPortalFlow = { ...externalPortalServiceProps }; await createQuestionWithOptions( page, diff --git a/e2e/tests/ui-driven/src/helpers/context.ts b/e2e/tests/ui-driven/src/helpers/context.ts index 4356b9c07f..42c5d6b224 100644 --- a/e2e/tests/ui-driven/src/helpers/context.ts +++ b/e2e/tests/ui-driven/src/helpers/context.ts @@ -3,6 +3,7 @@ import { GraphQLClient, gql } from "graphql-request"; import { sign } from "jsonwebtoken"; import assert from "node:assert"; import { log } from "./globalHelpers"; +import { $admin } from "../../../api-driven/src/client"; type NewTeam = Parameters[0]; @@ -23,7 +24,8 @@ export interface Context { isPlatformAdmin: boolean; }; team: { id?: number } & NewTeam; - flows?: Flow[]; + flow?: Flow; + externalPortalFlow?:Flow; sessionIds?: string[]; } @@ -67,24 +69,24 @@ export async function setUpTestContext( }); } if ( - context.flows && - context.flows[0].slug && - context.flows[0].data && - context.flows[0].name && + context.flow && + context.flow.slug && + context.flow.data && + context.flow.name && context.team?.id && context.user?.id ) { - context.flows[0].id = await $admin.flow.create({ - slug: context.flows[0].slug, - name: context.flows[0].name, + context.flow.id = await $admin.flow.create({ + slug: context.flow.slug, + name: context.flow.name, teamId: context.team.id, - data: context.flows[0].data, + data: context.flow.data, status: "online", }); - context.flows[0].publishedId = await $admin.flow.publish({ + context.flow.publishedId = await $admin.flow.publish({ flow: { - id: context.flows[0].id, - data: context.flows[0].data, + id: context.flow.id, + data: context.flow.data, }, publisherId: context.user!.id!, }); @@ -106,15 +108,8 @@ export const externalPortalFlowData = { export async function tearDownTestContext(context: Context) { const adminGQLClient = getGraphQLClient(); - if (context.flows?.[0]) { - await deleteSession(adminGQLClient, context); - - for (const flow of context.flows) { - await deleteFlow(adminGQLClient, flow); - if (flow.publishedId) { - await deletePublishedFlow(adminGQLClient, flow); - } - } + if (context.flow || context.externalPortalFlow) { + await $admin.flow._destroyAll() } if (context.user) { await deleteUser(adminGQLClient, context); @@ -170,7 +165,7 @@ export async function findSessionId( id } }`, - { slug: context.flows?.[0].slug }, + { slug: context.flow.slug }, ); if (!flowResponse.flows.length || !flowResponse.flows[0].id) { return; diff --git a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts index 01a8b0933b..a52cee007c 100644 --- a/e2e/tests/ui-driven/src/helpers/globalHelpers.ts +++ b/e2e/tests/ui-driven/src/helpers/globalHelpers.ts @@ -114,7 +114,7 @@ export async function modifyFlow({ modifiedFlow: FlowGraph; }) { const adminGQLClient = getGraphQLClient(); - if (!context.flows?.[0]?.slug || !context.user?.id) { + if (!context.flow?.slug || !context.user?.id) { throw new Error("context must have a flow and user"); } await adminGQLClient.request( @@ -132,7 +132,7 @@ export async function modifyFlow({ } `, { - flowId: context.flows?.[0].id, + flowId: context.flow?.id, userId: context.user!.id, data: modifiedFlow, }, diff --git a/e2e/tests/ui-driven/src/helpers/userActions.ts b/e2e/tests/ui-driven/src/helpers/userActions.ts index 703153fb01..9da223b003 100644 --- a/e2e/tests/ui-driven/src/helpers/userActions.ts +++ b/e2e/tests/ui-driven/src/helpers/userActions.ts @@ -4,6 +4,7 @@ import { setupOSMockResponse } from "../mocks/osPlacesResponse"; import type { Context } from "./context"; import { findSessionId, getGraphQLClient } from "./context"; import { TEST_EMAIL, log, waitForDebugLog } from "./globalHelpers"; +import exp from "node:constants"; export async function saveSession({ page, @@ -35,7 +36,7 @@ export async function returnToSession({ sessionId: string; shouldContinue?: boolean; }) { - const returnURL = `/${context.team?.slug}/${context.flows?.[0].slug}/published?analytics=false&sessionId=${sessionId}`; + const returnURL = `/${context.team?.slug}/${context.flow?.slug}/published?analytics=false&sessionId=${sessionId}`; log(`returning to http://localhost:3000/${returnURL}`); await page.goto(returnURL, { waitUntil: "load" }); await page.locator("#email").fill(context.user?.email); diff --git a/e2e/tests/ui-driven/src/invite-to-pay/agent.spec.ts b/e2e/tests/ui-driven/src/invite-to-pay/agent.spec.ts index b510e8c1e2..527e788b95 100644 --- a/e2e/tests/ui-driven/src/invite-to-pay/agent.spec.ts +++ b/e2e/tests/ui-driven/src/invite-to-pay/agent.spec.ts @@ -23,13 +23,13 @@ import { mockPaymentRequest, modifiedInviteToPayFlow } from "./mocks"; let context: Context = { ...contextDefaults, - flows: [ + flow: { slug: "invite-to-pay-test", name: "Invite to pay test", data: inviteToPayFlow, - }, - ], + } + , sessionIds: [], // used to collect and clean up sessions }; @@ -108,7 +108,7 @@ test.describe("Agent journey @regression", async () => { const sessionId = await makePaymentRequest({ page: firstPage, context }); // Resume session - const resumeLink = `/${context.team!.slug!}/${context.flows![0].slug}/published?analytics=false&sessionId=${sessionId}`; + const resumeLink = `/${context.team!.slug!}/${context.flow?.slug}/published?analytics=false&sessionId=${sessionId}`; const secondPage = await browserContext.newPage(); await secondPage.goto(resumeLink); await expect( @@ -137,7 +137,7 @@ test.describe("Agent journey @regression", async () => { await modifyFlow({ context, modifiedFlow: modifiedInviteToPayFlow }); // Navigate to resume session link - const resumeLink = `/${context.team!.slug!}/${context.flows![0].slug}/published?analytics=false&sessionId=${sessionId}`; + const resumeLink = `/${context.team!.slug!}/${context.flow?.slug}/published?analytics=false&sessionId=${sessionId}`; const secondPage = await browserContext.newPage(); await secondPage.goto(resumeLink); await expect( diff --git a/e2e/tests/ui-driven/src/invite-to-pay/helpers.ts b/e2e/tests/ui-driven/src/invite-to-pay/helpers.ts index ff7b23239b..4d766f8d35 100644 --- a/e2e/tests/ui-driven/src/invite-to-pay/helpers.ts +++ b/e2e/tests/ui-driven/src/invite-to-pay/helpers.ts @@ -1,5 +1,5 @@ import { PaymentRequest } from "@opensystemslab/planx-core/dist/types"; -import type { Page } from "@playwright/test"; +import { expect, type Page } from "@playwright/test"; import { GraphQLClient, gql } from "graphql-request"; import { Context } from "../helpers/context"; import { TEST_EMAIL, addSessionToContext, log } from "../helpers/globalHelpers"; @@ -15,7 +15,7 @@ import { */ export async function navigateToPayComponent(page: Page, context: Context) { const previewURL = `/${context.team!.slug!}/${ - context.flows?.[0].slug + context.flow?.slug }/published?analytics=false`; await page.goto(previewURL); @@ -96,6 +96,6 @@ export async function makePaymentRequest({ await answerInviteToPayForm(page); page.getByRole("button", { name: "Send invitation to pay" }).click(); await page.waitForResponse((res) => res.url().includes("invite-to-pay")); - + await expect(page.getByText('Error generating payment')).toBeHidden() return sessionId; } diff --git a/e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts b/e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts index 981d6b89aa..15d99d9c0c 100644 --- a/e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts +++ b/e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts @@ -17,13 +17,12 @@ import { mockPaymentRequestDetails, mockSessionData } from "./mocks"; let context: Context = { ...contextDefaults, - flows: [ + flow: { slug: "invite-to-pay-test", name: "Invite to pay test", data: inviteToPayFlow, }, - ], sessionIds: [], // used to collect and clean up sessions }; @@ -85,7 +84,7 @@ test.describe("Nominee journey @regression", async () => { test("navigating to a URL with an invalid ID", async ({ page }) => { const invalidPaymentRequestURL = `/${context.team!.slug!}/${context - .flows![0].slug!}/pay?analytics=false&paymentRequestId=INVALID-ID`; + .flow?.slug}/pay?analytics=false&paymentRequestId=INVALID-ID`; await page.goto(invalidPaymentRequestURL); await page.waitForLoadState("networkidle"); @@ -93,8 +92,7 @@ test.describe("Nominee journey @regression", async () => { }); test("navigating to a URL without a paymentRequestId", async ({ page }) => { - const invalidPaymentRequestURL = `/${context.team!.slug!}/${context - .flows![0].slug!}/pay?analytics=false`; + const invalidPaymentRequestURL = `/${context.team!.slug!}/${context.flow?.slug}/pay?analytics=false`; await page.goto(invalidPaymentRequestURL); await page.waitForLoadState("networkidle"); @@ -128,8 +126,7 @@ async function navigateToPaymentRequestPage( paymentRequest: PaymentRequest, page: Page, ) { - const paymentRequestURL = `/${context.team!.slug!}/${context.flows![0] - .slug!}/pay?analytics=false&paymentRequestId=${paymentRequest.id}`; + const paymentRequestURL = `/${context.team!.slug!}/${context.flow?.slug}/pay?analytics=false&paymentRequestId=${paymentRequest.id}`; await page.goto(paymentRequestURL); await page.waitForLoadState("networkidle"); } @@ -173,11 +170,11 @@ async function createSession({ await client.request[]>>(mutation, { id: sessionId, data: { - id: context.flows![0].id, + id: context.flow?.id, ...mockSessionData, }, email: context.user.email, - flowId: context.flows![0].id, + flowId: context.flow?.id, }); } diff --git a/e2e/tests/ui-driven/src/pay.spec.ts b/e2e/tests/ui-driven/src/pay.spec.ts index e878ba9ae3..7ab35de921 100644 --- a/e2e/tests/ui-driven/src/pay.spec.ts +++ b/e2e/tests/ui-driven/src/pay.spec.ts @@ -20,17 +20,16 @@ import payFlow from "./mocks/flows/pay-flow.json"; let context: Context = { ...contextDefaults, - flows: [ + flow: { slug: "pay-test", name: "Pay test", data: payFlow, }, - ], + sessionIds: [], // used to collect and clean up sessions }; -const previewURL = `/${context.team!.slug!}/${context.flows![0] - .slug!}/published?analytics=false`; +const previewURL = `/${context.team!.slug!}/${context.flow?.slug}/published?analytics=false`; const payButtonText = "Pay now using GOV.UK Pay"; diff --git a/e2e/tests/ui-driven/src/save-and-return.spec.ts b/e2e/tests/ui-driven/src/save-and-return.spec.ts index 5703e0c598..aa7b17c731 100644 --- a/e2e/tests/ui-driven/src/save-and-return.spec.ts +++ b/e2e/tests/ui-driven/src/save-and-return.spec.ts @@ -22,15 +22,14 @@ import { test.describe("Save and return", () => { let context: Context = { ...contextDefaults, - flows: [ + flow: { slug: "e2e-save-and-return-test-flow", name: "E2E Save and Return test flow", data: simpleSendFlow, }, - ], }; - const previewURL = `/${context.team?.slug}/${context.flows![0].slug}/published?analytics=false`; + const previewURL = `/${context.team?.slug}/${context.flow?.slug}/published?analytics=false`; test.beforeAll(async () => { try { diff --git a/e2e/tests/ui-driven/src/sections.spec.ts b/e2e/tests/ui-driven/src/sections.spec.ts index 2961a8f9c1..fe7892aea4 100644 --- a/e2e/tests/ui-driven/src/sections.spec.ts +++ b/e2e/tests/ui-driven/src/sections.spec.ts @@ -36,13 +36,13 @@ export enum SectionStatus { test.describe("Section statuses", () => { let context: Context = { ...contextDefaults, - flows: [ + flow: { slug: "sections-test-flow", name: "Sections test flow", data: flow, }, - ], + }; test.beforeAll(async () => { @@ -55,7 +55,7 @@ test.describe("Section statuses", () => { }); test.beforeEach(async ({ page }) => { - const previewURL = `/${context.team?.slug}/${context.flows![0].slug}/published?analytics=false`; + const previewURL = `/${context.team?.slug}/${context.flow?.slug}/published?analytics=false`; await page.goto(previewURL); }); @@ -537,7 +537,7 @@ async function modifyFlow({ flowData: FlowGraph; }) { const adminGQLClient = getGraphQLClient(); - if (!context.flows![0].id || !context.user?.id) { + if (!context.flow?.id || !context.user?.id) { throw new Error("context must have a flow and user"); } await adminGQLClient.request( @@ -555,7 +555,7 @@ async function modifyFlow({ } `, { - flowId: context.flows![0].id, + flowId: context.flow?.id, userId: context.user!.id, data: flowData, },