Skip to content

Commit

Permalink
fix bugs with user and navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 29, 2024
1 parent eee94ee commit 3826fad
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 39 deletions.
14 changes: 7 additions & 7 deletions e2e/tests/ui-driven/src/create-flow-with-geospatial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { createAuthenticatedSession } from "./helpers/globalHelpers";
import { answerFindProperty, clickContinue } from "./helpers/userActions";
import { PlaywrightEditor } from "./pages/Editor";
import {
navigateToService,
publishService,
turnServiceOnline,
} from "./helpers/navigateAndPublish";
Expand All @@ -24,13 +25,13 @@ test.describe("Flow creation, publish and preview", () => {
try {
context = await setUpTestContext(context);
} catch (error) {
await tearDownTestContext(context);
await tearDownTestContext();
throw error;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test("Create a flow", async ({ browser }) => {
Expand Down Expand Up @@ -76,17 +77,16 @@ test.describe("Flow creation, publish and preview", () => {
userId: context.user!.id!,
});
// publish flow
await page.goto(`/${context.team.slug}/${serviceProps.slug}`);
publishService(page);
await navigateToService(page, serviceProps.slug)
await publishService(page);

let previewLink = page.getByRole("link", {
name: "Open published service",
});
await expect(previewLink).toBeVisible();

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

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

// Exit back to main Editor page
page.locator('[aria-label="Editor"]').click();
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 @@ -44,13 +44,13 @@ test.describe("Flow creation, publish and preview", () => {
context = await setUpTestContext(context);
} catch (error) {
// ensure proper teardown if setup fails
await tearDownTestContext(context);
await tearDownTestContext();
throw error;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test("Create a flow", async ({ browser }) => {
Expand Down
22 changes: 8 additions & 14 deletions e2e/tests/ui-driven/src/helpers/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ 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";

export const contextDefaults: TestContext = {
user: {
id: 0,
id:0,
firstName: "Test",
lastName: "Test",
email: "[email protected]",
Expand All @@ -28,13 +27,15 @@ export const contextDefaults: TestContext = {
},
};

const $admin = getCoreDomainClient();

export async function setUpTestContext(
initialContext: TestContext,
): Promise<TestContext> {
const $admin = getCoreDomainClient();
const context: TestContext = { ...initialContext };
if (context.user) {
context.user.id = await $admin.user.create(context.user);
const {firstName, lastName, email, isPlatformAdmin} = context.user
context.user.id = await $admin.user.create({firstName, lastName, email, isPlatformAdmin});
}
if (context.team) {
context.team.id = await $admin.team.create({
Expand Down Expand Up @@ -74,17 +75,10 @@ export async function setUpTestContext(
return context;
}

export async function tearDownTestContext(context: TestContext) {
const adminGQLClient = getGraphQLClient();
if (context.flow || context.externalPortalFlow) {
export async function tearDownTestContext() {
await $admin.flow._destroyAll();
}
if (context.user) {
await deleteUser(adminGQLClient, context);
}
if (context.team) {
await deleteTeam(adminGQLClient, context);
}
await $admin.user._destroyAll()
await $admin.team._destroyAll()
}

export function generateAuthenticationToken(userId: string) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Flow {
}

export interface TestContext {
user: Omit<User, "teams">;
user: Pick<User, "firstName" | "lastName" | "email" | "isPlatformAdmin" | "id">
team: { id?: number } & NewTeam;
flow?: Flow;
externalPortalFlow?: Flow;
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/invite-to-pay/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ test.describe("Agent journey @regression", async () => {
context = await setUpTestContext(context);
} catch (e) {
// ensure proper teardown if setup fails
await tearDownTestContext(context);
await tearDownTestContext();
throw e;
}
});

test.afterAll(async () => await tearDownTestContext(context));
test.afterAll(async () => await tearDownTestContext());

test("agent can send a payment request", async ({ page }) => {
await navigateToPayComponent(page, context);
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/invite-to-pay/nominee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ test.describe("Nominee journey @regression", async () => {
context = await setUpTestContext(context);
} catch (e) {
// ensure proper teardown if setup fails
await tearDownTestContext(context);
await tearDownTestContext();
throw e;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test("responding to a valid payment request", async ({ page, request }) => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/login.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ test.describe("Login", () => {
context = await setUpTestContext(context);
} catch (error) {
// ensure proper teardown if setup fails
await tearDownTestContext(context);
await tearDownTestContext();
throw error;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test("setting a cookie bypasses login", async ({ browser }) => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/src/pages/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class PlaywrightEditor {
async createQuestionWithOptions(title: string, answers: string[]) {
await createQuestionWithOptions(this.page, this.firstNode, title, answers);
await expect(
this.page.locator("a").filter({ hasText: this.answers.questionText }),
this.page.locator("a").filter({ hasText: title }),
).toBeVisible();
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/pay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ test.describe("Gov Pay integration @regression", async () => {
context = await setUpTestContext(context);
} catch (e) {
// ensure proper teardown if setup fails
await tearDownTestContext(context);
await tearDownTestContext();
throw e;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test("a successful payment", async ({ page }) => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/refresh-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ test.describe("Refresh page", () => {
context = await setUpTestContext(context);
} catch (error) {
// ensure proper teardown if setup fails
await tearDownTestContext(context);
await tearDownTestContext();
throw error;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test("user data persists on page refresh @regression", async ({
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/save-and-return.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ test.describe("Save and return", () => {
try {
context = await setUpTestContext(context);
} catch (e) {
await tearDownTestContext(context);
await tearDownTestContext();
throw e;
}
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test.describe("email", () => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/sections.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test.describe("Section statuses", () => {
try {
context = await setUpTestContext(context);
} catch (e) {
await tearDownTestContext(context);
await tearDownTestContext();
throw e;
}
});
Expand All @@ -58,7 +58,7 @@ test.describe("Section statuses", () => {
});

test.afterAll(async () => {
await tearDownTestContext(context);
await tearDownTestContext();
});

test.describe("a straight-through journey", () => {
Expand Down

0 comments on commit 3826fad

Please sign in to comment.