Skip to content

Commit

Permalink
revert flows change and add expect to makePaymentRequest
Browse files Browse the repository at this point in the history
separate out types and service data

lint fix
  • Loading branch information
RODO94 committed Nov 29, 2024
1 parent 377a77a commit eee94ee
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 191 deletions.
27 changes: 9 additions & 18 deletions e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect, test } from "@playwright/test";

Check failure on line 1 in e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts

View workflow job for this annotation

GitHub Actions / E2E tests

[chromium] › create-flow-with-geospatial.spec.ts:71:7 › Flow creation

1) [chromium] › create-flow-with-geospatial.spec.ts:71:7 › Flow creation, publish and preview › Publish and preview flow with geospatial components Test timeout of 45000ms exceeded.
import type { Context } from "./helpers/context";
import {
contextDefaults,
setUpTestContext,
Expand All @@ -9,15 +8,17 @@ import { getTeamPage } from "./helpers/getPage";
import { createAuthenticatedSession } from "./helpers/globalHelpers";
import { answerFindProperty, clickContinue } from "./helpers/userActions";
import { PlaywrightEditor } from "./pages/Editor";
import {
publishService,
turnServiceOnline,
} from "./helpers/navigateAndPublish";
import { TestContext } from "./helpers/types";
import { serviceProps } from "./helpers/serviceData";

test.describe("Flow creation, publish and preview", () => {
let context: Context = {
let context: TestContext = {
...contextDefaults,
};
const serviceProps = {
name: "A Test Service",
slug: "a-test-service",
};

test.beforeAll(async () => {
try {
Expand All @@ -44,9 +45,6 @@ test.describe("Flow creation, publish and preview", () => {
page.on("dialog", (dialog) => dialog.accept(serviceProps.name));
await editor.addNewService();

// update context to allow flow to be torn down
context.flows = [{ ...serviceProps }];

await editor.createFindProperty();
await expect(editor.nodeList).toContainText(["Find property"]);
await editor.createInternalPortal();
Expand Down Expand Up @@ -79,8 +77,7 @@ test.describe("Flow creation, publish and preview", () => {
});
// publish flow
await page.goto(`/${context.team.slug}/${serviceProps.slug}`);
page.getByRole("button", { name: "CHECK FOR CHANGES TO PUBLISH" }).click();
page.getByRole("button", { name: "PUBLISH", exact: true }).click();
publishService(page);

let previewLink = page.getByRole("link", {
name: "Open published service",
Expand All @@ -89,13 +86,7 @@ test.describe("Flow creation, publish and preview", () => {

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

// Toggle flow online
page.locator('[aria-label="Service settings"]').click();
page.getByLabel("Offline").click();
page.getByRole("button", { name: "Save", disabled: false }).click();
await expect(
page.getByText("Service settings updated successfully"),
).toBeVisible();
turnServiceOnline(page);

// Exit back to main Editor page
page.locator('[aria-label="Editor"]').click();
Expand Down
43 changes: 19 additions & 24 deletions e2e/tests/ui-driven/src/create-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Browser, expect, test } from "@playwright/test";
import type { Context } from "./helpers/context";
import {
contextDefaults,
externalPortalFlowData,
externalPortalServiceProps,
setUpTestContext,
tearDownTestContext,
} from "./helpers/context";
Expand All @@ -21,18 +18,20 @@ import {
clickContinue,
} from "./helpers/userActions";
import { PlaywrightEditor } from "./pages/Editor";
import {
createExternalPortal,
createQuestionWithOptions,
} from "./helpers/addComponent";
import { createExternalPortal } from "./helpers/addComponent";
import {
navigateToService,
publishService,
turnServiceOnline,
} from "./helpers/navigateAndPublish";
import { TestContext } from "./helpers/types";
import {
externalPortalFlowData,
externalPortalServiceProps,
} from "./helpers/serviceData";

test.describe("Flow creation, publish and preview", () => {
let context: Context = {
let context: TestContext = {
...contextDefaults,
};
const serviceProps = {
Expand Down Expand Up @@ -67,7 +66,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 @@ -131,8 +130,7 @@ test.describe("Flow creation, publish and preview", () => {
userId: context.user!.id!,
});

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

await navigateToService(page, serviceProps.slug);
await publishService(page);

const previewLink = page.getByRole("link", {
Expand Down Expand Up @@ -166,8 +164,7 @@ test.describe("Flow creation, publish and preview", () => {
userId: context.user!.id!,
});

await page.goto(`/${context.team.slug}/${serviceProps.slug}`);

await navigateToService(page, serviceProps.slug);
await turnServiceOnline(page);

// Exit back to main Editor page
Expand Down Expand Up @@ -199,24 +196,22 @@ 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 };

const { title, answers } = externalPortalFlowData;

await editor.createQuestionWithOptions(title, answers);

await createQuestionWithOptions(
page,
editor.firstNode,
externalPortalFlowData.title,
externalPortalFlowData.answers,
);
await expect(editor.nodeList).toContainText([
externalPortalFlowData.title,
externalPortalFlowData.answers[0],
externalPortalFlowData.answers[1],
title,
answers[0],
answers[1],
]);

await publishService(page);
await turnServiceOnline(page);

navigateToService(page, serviceProps.slug);
await navigateToService(page, serviceProps.slug);

await createExternalPortal(page, page.locator("li:nth-child(6)"));

Expand Down
3 changes: 2 additions & 1 deletion e2e/tests/ui-driven/src/helpers/addComponent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentType } from "@opensystemslab/planx-core/types";
import { expect, Locator, Page } from "@playwright/test";
import { contextDefaults, externalPortalServiceProps } from "./context";
import { contextDefaults } from "./context";
import { externalPortalServiceProps } from "./serviceData";

const createBaseComponent = async (
page: Page,
Expand Down
90 changes: 28 additions & 62 deletions e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,12 @@ 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";
import { Flow, TestContext } from "./types";

type NewTeam = Parameters<CoreDomainClient["team"]["create"]>[0];

export interface Flow {
id?: string;
publishedId?: number;
slug: string;
name: string;
data?: object;
}

export interface Context {
user: {
id?: number;
firstName: string;
lastName: string;
email: string;
isPlatformAdmin: boolean;
};
team: { id?: number } & NewTeam;
flows?: Flow[];
sessionIds?: string[];
}

export const contextDefaults: Context = {
export const contextDefaults: TestContext = {
user: {
id: 0,
firstName: "Test",
lastName: "Test",
email: "[email protected]",
Expand All @@ -49,10 +29,10 @@ export const contextDefaults: Context = {
};

export async function setUpTestContext(
initialContext: Context,
): Promise<Context> {
initialContext: TestContext,
): Promise<TestContext> {
const $admin = getCoreDomainClient();
const context: Context = { ...initialContext };
const context: TestContext = { ...initialContext };
if (context.user) {
context.user.id = await $admin.user.create(context.user);
}
Expand All @@ -67,24 +47,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 @@ -94,27 +74,10 @@ export async function setUpTestContext(
return context;
}

export const externalPortalServiceProps = {
name: "An External Portal Service",
slug: "an-external-portal-service",
};

export const externalPortalFlowData = {
title: "Is this an External Portal?",
answers: ["It is an external portal", "No it is not an External Portal"],
};

export async function tearDownTestContext(context: Context) {
export async function tearDownTestContext(context: TestContext) {
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 +133,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 Expand Up @@ -273,7 +236,7 @@ async function deleteFlow(adminGQLClient: GraphQLClient, flow: Flow) {
}
}

async function deleteUser(adminGQLClient: GraphQLClient, context: Context) {
async function deleteUser(adminGQLClient: GraphQLClient, context: TestContext) {
if (context.user?.id) {
log(`deleting user ${context.user?.id}`);
await adminGQLClient.request(

Check failure on line 242 in e2e/tests/ui-driven/src/helpers/context.ts

View workflow job for this annotation

GitHub Actions / E2E tests

[chromium] › create-flow-with-geospatial.spec.ts:71:7 › Flow creation

1) [chromium] › create-flow-with-geospatial.spec.ts:71:7 › Flow creation, publish and preview › Publish and preview flow with geospatial components Error: Foreign key violation. update or delete on table "users" violates foreign key constraint "flows_creator_id_fkey" on table "flows": {"response":{"errors":[{"message":"Foreign key violation. update or delete on table \"users\" violates foreign key constraint \"flows_creator_id_fkey\" on table \"flows\"","extensions":{"path":"$","code":"constraint-violation"}}],"status":200,"headers":{}},"request":{"query":"mutation DeleteTestUser($userId: Int!) {\n delete_users_by_pk(id: $userId) {\n id\n }\n }","variables":{"userId":1}}} at helpers/context.ts:242 240 | if (context.user?.id) { 241 | log(`deleting user ${context.user?.id}`); > 242 | await adminGQLClient.request( | ^ 243 | `mutation DeleteTestUser($userId: Int!) { 244 | delete_users_by_pk(id: $userId) { 245 | id at makeRequest (/home/runner/work/planx-new/planx-new/e2e/tests/ui-driven/node_modules/.pnpm/github.com+theopensystemslab+planx-core@ccf9ac3/node_modules/@opensystemslab/planx-core/node_modules/graphql-request/src/index.ts:426:11) at deleteUser (/home/runner/work/planx-new/planx-new/e2e/tests/ui-driven/src/helpers/context.ts:242:5) at tearDownTestContext (/home/runner/work/planx-new/planx-new/e2e/tests/ui-driven/src/helpers/context.ts:83:5) at /home/runner/work/planx-new/planx-new/e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts:33:5
Expand Down Expand Up @@ -310,7 +273,7 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) {
}
}

async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) {
async function deleteTeam(adminGQLClient: GraphQLClient, context: TestContext) {
if (context.team?.id) {
log(`deleting team ${context.team?.id}`);
await adminGQLClient.request(
Expand Down Expand Up @@ -347,7 +310,10 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) {
}
}

async function setupGovPaySecret($admin: CoreDomainClient, context: Context) {
async function setupGovPaySecret(
$admin: CoreDomainClient,
context: TestContext,
) {
try {
await $admin.client.request(
gql`
Expand Down
12 changes: 6 additions & 6 deletions e2e/tests/ui-driven/src/helpers/globalHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FlowGraph } from "@opensystemslab/planx-core/types";
import type { Browser, Page, Request } from "@playwright/test";
import { gql } from "graphql-request";
import type { Context } from "./context";
import { generateAuthenticationToken, getGraphQLClient } from "./context";
import { TestContext } from "./types";

// Test card numbers to be used in gov.uk sandbox environment
// reference: https://docs.payments.service.gov.uk/testing_govuk_pay/#if-you-39-re-using-a-test-39-sandbox-39-account
Expand Down Expand Up @@ -87,15 +87,15 @@ export async function getSessionId(page: Page): Promise<string> {
return sessionId;
}

export async function addSessionToContext(page: Page, context: Context) {
export async function addSessionToContext(page: Page, context: TestContext) {
const sessionId = await getSessionId(page);
context.sessionIds!.push(sessionId);
return sessionId;
}

export async function waitForPaymentResponse(
page: Page,
context: Context,
context: TestContext,
): Promise<{ paymentId: string; state?: { status: string } }> {
const { payment_id: paymentId, state } = await page
.waitForResponse((response) => {
Expand All @@ -110,11 +110,11 @@ export async function modifyFlow({
context,
modifiedFlow,
}: {
context: Context;
context: TestContext;
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
2 changes: 0 additions & 2 deletions e2e/tests/ui-driven/src/helpers/navigateAndPublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export const navigateToService = async (page: Page, slug: string) => {
await page.goto(`/${contextDefaults.team.slug}/${slug}`);

await expect(page.getByRole("link", { name: slug })).toBeVisible();

return true;
};

export const publishService = async (page: Page) => {
Expand Down
Loading

0 comments on commit eee94ee

Please sign in to comment.