From f456bcb1ec3c09c278f8be626e3fabb902f23079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 19 Sep 2023 18:23:22 +0100 Subject: [PATCH] fix: Linting --- e2e/tests/api-driven/README.md | 4 +- e2e/tests/api-driven/src/globalHelpers.ts | 56 +++++++++++------- .../api-driven/src/invite-to-pay/helpers.ts | 2 +- .../api-driven/src/invite-to-pay/steps.ts | 47 ++++++++------- .../api-driven/src/permissions/helpers.ts | 12 ++-- .../src/permissions/queries/flows.ts | 14 +++-- .../src/permissions/queries/index.ts | 4 +- e2e/tests/api-driven/src/permissions/steps.ts | 59 ++++++++----------- 8 files changed, 106 insertions(+), 92 deletions(-) diff --git a/e2e/tests/api-driven/README.md b/e2e/tests/api-driven/README.md index bc9a95d1de..fcc3e0e63e 100644 --- a/e2e/tests/api-driven/README.md +++ b/e2e/tests/api-driven/README.md @@ -19,11 +19,9 @@ To add new tests to this folder, follow these steps: 2. Inside each test subfolder, include the following files: - `.feature` file: This file contains the Gherkin syntax to describe the test scenario in a human-readable format. It outlines the steps and expected behaviour of the test. - - `helpers.ts` file: This file should contain utility functions and setup/cleanup logic for your test. At a minimum, it should include the following functions: - + - `setup()`: This function sets up the necessary environment or configurations required for the test scenario. - - `cleanup()`: This function performs cleanup tasks after the test scenario is executed, such as resetting the environment to its initial state. - `steps.ts` file: This file contains the step definitions for your Gherkin scenarios. Each step definition maps a step in the `.feature` file to a function that performs the corresponding action and assertion in your test. We aim to keep these steps as readable as possible, with the majority of the logic being contained within `helpers.ts`. diff --git a/e2e/tests/api-driven/src/globalHelpers.ts b/e2e/tests/api-driven/src/globalHelpers.ts index 3c5a312b60..9894013afd 100644 --- a/e2e/tests/api-driven/src/globalHelpers.ts +++ b/e2e/tests/api-driven/src/globalHelpers.ts @@ -1,32 +1,44 @@ import { TEST_EMAIL } from "../../ui-driven/src/helpers"; import { $admin } from "./client"; -export function createTeam(args?: Partial[0]>) { - return safely(() => $admin.team.create({ - name: "E2E Test Team", - slug: "E2E", - logo: "https://raw.githubusercontent.com/theopensystemslab/planx-team-logos/main/planx-testing.svg", - primaryColor: "#444444", - submissionEmail: TEST_EMAIL, - homepage: "planx.uk", - ...args, - })); +export function createTeam( + args?: Partial[0]>, +) { + return safely(() => + $admin.team.create({ + name: "E2E Test Team", + slug: "E2E", + logo: "https://raw.githubusercontent.com/theopensystemslab/planx-team-logos/main/planx-testing.svg", + primaryColor: "#444444", + submissionEmail: TEST_EMAIL, + homepage: "planx.uk", + ...args, + }), + ); } -export function createUser(args?: Partial[0]>) { - return safely(() => $admin.user.create({ - firstName: "Test", - lastName: "Test", - email: TEST_EMAIL, - ...args, - })); +export function createUser( + args?: Partial[0]>, +) { + return safely(() => + $admin.user.create({ + firstName: "Test", + lastName: "Test", + email: TEST_EMAIL, + ...args, + }), + ); } -export function createFlow(args: Omit[0], "data">) { - return safely(() => $admin.flow.create({ - data: { dummy: "flowData "}, - ...args, - })) +export function createFlow( + args: Omit[0], "data">, +) { + return safely(() => + $admin.flow.create({ + data: { dummy: "flowData " }, + ...args, + }), + ); } /** diff --git a/e2e/tests/api-driven/src/invite-to-pay/helpers.ts b/e2e/tests/api-driven/src/invite-to-pay/helpers.ts index 1665c794f2..343ccb0872 100644 --- a/e2e/tests/api-driven/src/invite-to-pay/helpers.ts +++ b/e2e/tests/api-driven/src/invite-to-pay/helpers.ts @@ -167,4 +167,4 @@ export const setup = async () => { }; return world; -} +}; diff --git a/e2e/tests/api-driven/src/invite-to-pay/steps.ts b/e2e/tests/api-driven/src/invite-to-pay/steps.ts index 9c8f04e33e..84e2eb6caa 100644 --- a/e2e/tests/api-driven/src/invite-to-pay/steps.ts +++ b/e2e/tests/api-driven/src/invite-to-pay/steps.ts @@ -21,18 +21,19 @@ export class CustomWorld extends World { paymentRequestId?: string; } -Before("@invite-to-pay", async function() { +Before("@invite-to-pay", async function () { const { teamId, userId } = await setup(); this.teamId = teamId; this.userId = userId; }); -After("@invite-to-pay", async function(this: CustomWorld) { +After("@invite-to-pay", async function (this: CustomWorld) { await cleanup(this); }); Given( - "a session with a payment request for an invite to pay flow where {string} is a send destination", { timeout: 60 * 1000 }, + "a session with a payment request for an invite to pay flow where {string} is a send destination", + { timeout: 60 * 1000 }, async function (this: CustomWorld, destination: string) { const { flowId, publishedFlowId } = await buildITPFlow({ destination, @@ -51,24 +52,25 @@ Given( if (!this.sessionId) { throw new Error("session not found"); } - const paymentRequest = await buildPaymentRequestForSession( - this.sessionId, - ); + const paymentRequest = await buildPaymentRequestForSession(this.sessionId); this.paymentRequestId = paymentRequest.id; }, ); -When("the payment request's `paid_at` date is set", async function (this: CustomWorld) { - if (!this.paymentRequestId) { - throw new Error("payment request not found"); - } - const operationSucceeded = await markPaymentRequestAsPaid( - this.paymentRequestId, - ); - if (!operationSucceeded) { - throw new Error("payment request was not marked as paid"); - } -}); +When( + "the payment request's `paid_at` date is set", + async function (this: CustomWorld) { + if (!this.paymentRequestId) { + throw new Error("payment request not found"); + } + const operationSucceeded = await markPaymentRequestAsPaid( + this.paymentRequestId, + ); + if (!operationSucceeded) { + throw new Error("payment request was not marked as paid"); + } + }, +); Then( "there should be an audit entry for a successful {string} submission", @@ -84,7 +86,10 @@ Then( }, ); -Then("the session's `submitted_at` date should be set", async function (this: CustomWorld) { - const submittedAt = await getSessionSubmittedAt(this.sessionId!); - assert(submittedAt); -}); +Then( + "the session's `submitted_at` date should be set", + async function (this: CustomWorld) { + const submittedAt = await getSessionSubmittedAt(this.sessionId!); + assert(submittedAt); + }, +); diff --git a/e2e/tests/api-driven/src/permissions/helpers.ts b/e2e/tests/api-driven/src/permissions/helpers.ts index 319545f9ea..903013a37e 100644 --- a/e2e/tests/api-driven/src/permissions/helpers.ts +++ b/e2e/tests/api-driven/src/permissions/helpers.ts @@ -21,7 +21,7 @@ export const cleanup = async () => { await $admin.flow._destroyAll(); await $admin.team._destroyAll(); await $admin.user._destroyAll(); -} +}; export const setup = async () => { const teamId1 = await createTeam({ name: "E2E Team 1", slug: "e2e-team1" }); @@ -29,13 +29,13 @@ export const setup = async () => { const user1 = { id: await createUser({ email: "e2e-user-1@opensystemslab.io" }), email: "e2e-user-1@opensystemslab.io", - } + }; const user2 = { id: await createUser({ email: "e2e-user-2@opensystemslab.io" }), email: "e2e-user-2@opensystemslab.io", - } - const team1Flow = await createFlow({ teamId: teamId1, slug: "team-1-flow" }) - const team2Flow = await createFlow({ teamId: teamId2, slug: "team-2-flow" }) + }; + const team1Flow = await createFlow({ teamId: teamId1, slug: "team-1-flow" }); + const team2Flow = await createFlow({ teamId: teamId2, slug: "team-2-flow" }); const world = { teamId1, @@ -47,7 +47,7 @@ export const setup = async () => { }; return world; -} +}; export const performGQLQuery = async ({ world, diff --git a/e2e/tests/api-driven/src/permissions/queries/flows.ts b/e2e/tests/api-driven/src/permissions/queries/flows.ts index 48833249f1..0427f8ec99 100644 --- a/e2e/tests/api-driven/src/permissions/queries/flows.ts +++ b/e2e/tests/api-driven/src/permissions/queries/flows.ts @@ -1,11 +1,17 @@ import { gql } from "graphql-request"; export const INSERT_FLOW_QUERY = gql` - mutation InsertFlowE2E ($teamId1: Int) { - insert_flows(objects: {data: "{hello: 'world'}", slug: "e2e-test-flow", team_id: $teamId1 }) { + mutation InsertFlowE2E($teamId1: Int) { + insert_flows( + objects: { + data: "{hello: 'world'}" + slug: "e2e-test-flow" + team_id: $teamId1 + } + ) { returning { id } } -} -` \ No newline at end of file + } +`; diff --git a/e2e/tests/api-driven/src/permissions/queries/index.ts b/e2e/tests/api-driven/src/permissions/queries/index.ts index 3a04074c62..19a6499ee2 100644 --- a/e2e/tests/api-driven/src/permissions/queries/index.ts +++ b/e2e/tests/api-driven/src/permissions/queries/index.ts @@ -3,5 +3,5 @@ import { INSERT_FLOW_QUERY } from "./flows"; export const queries = { flows: { insert: INSERT_FLOW_QUERY, - } -} \ No newline at end of file + }, +}; diff --git a/e2e/tests/api-driven/src/permissions/steps.ts b/e2e/tests/api-driven/src/permissions/steps.ts index 9628a80596..851f8b16a9 100644 --- a/e2e/tests/api-driven/src/permissions/steps.ts +++ b/e2e/tests/api-driven/src/permissions/steps.ts @@ -1,18 +1,11 @@ import { After, Before, Given, Then, When, World } from "@cucumber/cucumber"; import { strict as assert } from "node:assert"; -import { - getUser, -} from "../globalHelpers"; -import { - addUserToTeam, - cleanup, - performGQLQuery, - setup, -} from "./helpers"; +import { getUser } from "../globalHelpers"; +import { addUserToTeam, cleanup, performGQLQuery, setup } from "./helpers"; interface TestUser { - id: number, - email: string, + id: number; + email: string; } export class CustomWorld extends World { @@ -22,19 +15,20 @@ export class CustomWorld extends World { teamId2!: number; team1Flow!: string; team2Flow!: string; - + error?: Error = undefined; activeUser!: TestUser; } Before("@team-admin-permissions", async function () { - const { user1, user2, teamId1, teamId2, team1Flow, team2Flow } = await setup(); - this.user1 = user1 - this.user2 = user2 - this.teamId1 = teamId1 - this.teamId2 = teamId2 - this.team1Flow = team1Flow - this.team2Flow = team2Flow + const { user1, user2, teamId1, teamId2, team1Flow, team2Flow } = + await setup(); + this.user1 = user1; + this.user2 = user2; + this.teamId1 = teamId1; + this.teamId2 = teamId2; + this.team1Flow = team1Flow; + this.team2Flow = team2Flow; }); After("@team-admin-permissions", async function () { @@ -53,25 +47,24 @@ Given("a teamAdmin is a member of a team", async function (this: CustomWorld) { this.activeUser = this.user1; }); -Given("a teamAdmin is not in the requested team", async function (this: CustomWorld) { - await addUserToTeam(this.user2.id, this.teamId2); - const user = await getUser(this.user2.email); +Given( + "a teamAdmin is not in the requested team", + async function (this: CustomWorld) { + await addUserToTeam(this.user2.id, this.teamId2); + const user = await getUser(this.user2.email); - assert.ok(user, "User is not defined"); - assert.strictEqual(user.teams.length, 1); - assert.strictEqual(user.teams[0].role, "teamEditor"); - assert.strictEqual(user.teams[0].teamId, this.teamId2 ); + assert.ok(user, "User is not defined"); + assert.strictEqual(user.teams.length, 1); + assert.strictEqual(user.teams[0].role, "teamEditor"); + assert.strictEqual(user.teams[0].teamId, this.teamId2); - this.activeUser = this.user2; -}); + this.activeUser = this.user2; + }, +); When( "they perform {string} on {string}", - async function ( - this: CustomWorld, - action: string, - table: string, - ) { + async function (this: CustomWorld, action: string, table: string) { try { await performGQLQuery({ world: this,