Skip to content

Commit

Permalink
revert flows change and add expect to makePaymentRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 29, 2024
1 parent 208b3e3 commit 6f70225
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/create-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down
39 changes: 17 additions & 22 deletions e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreDomainClient["team"]["create"]>[0];

Expand All @@ -23,7 +24,8 @@ export interface Context {
isPlatformAdmin: boolean;
};
team: { id?: number } & NewTeam;
flows?: Flow[];
flow?: Flow;
externalPortalFlow?:Flow;
sessionIds?: string[];
}

Expand Down Expand Up @@ -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!,
});
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/helpers/globalHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -132,7 +132,7 @@ export async function modifyFlow({
}
`,
{
flowId: context.flows?.[0].id,
flowId: context.flow?.id,
userId: context.user!.id,
data: modifiedFlow,
},
Expand Down
3 changes: 2 additions & 1 deletion e2e/tests/ui-driven/src/helpers/userActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check warning on line 7 in e2e/tests/ui-driven/src/helpers/userActions.ts

View workflow job for this annotation

GitHub Actions / E2E tests

'exp' is defined but never used. Allowed unused vars must match /^_/u

export async function saveSession({
page,
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions e2e/tests/ui-driven/src/invite-to-pay/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/ui-driven/src/invite-to-pay/helpers.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
15 changes: 6 additions & 9 deletions e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -85,16 +84,15 @@ 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");

Check warning on line 89 in e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts

View workflow job for this annotation

GitHub Actions / E2E tests

Unexpected use of networkidle

await expect(page.getByText(PAYMENT_NOT_FOUND_TEXT)).toBeVisible();
});

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

Check warning on line 97 in e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts

View workflow job for this annotation

GitHub Actions / E2E tests

Unexpected use of networkidle

Expand Down Expand Up @@ -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");

Check warning on line 131 in e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts

View workflow job for this annotation

GitHub Actions / E2E tests

Unexpected use of networkidle
}
Expand Down Expand Up @@ -173,11 +170,11 @@ async function createSession({
await client.request<Record<"session", Pick<Session, "id">[]>>(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,
});
}

Expand Down
7 changes: 3 additions & 4 deletions e2e/tests/ui-driven/src/pay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
5 changes: 2 additions & 3 deletions e2e/tests/ui-driven/src/save-and-return.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions e2e/tests/ui-driven/src/sections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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);
});

Expand Down Expand Up @@ -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(
Expand All @@ -555,7 +555,7 @@ async function modifyFlow({
}
`,
{
flowId: context.flows![0].id,
flowId: context.flow?.id,
userId: context.user!.id,
data: flowData,
},
Expand Down

0 comments on commit 6f70225

Please sign in to comment.