Skip to content

Commit

Permalink
fix: Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Sep 19, 2023
1 parent 3c6e8db commit f456bcb
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 92 deletions.
4 changes: 1 addition & 3 deletions e2e/tests/api-driven/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ To add new tests to this folder, follow these steps:
2. Inside each test subfolder, include the following files:

- `<YOUR_FEATURE>.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`.
56 changes: 34 additions & 22 deletions e2e/tests/api-driven/src/globalHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
import { TEST_EMAIL } from "../../ui-driven/src/helpers";
import { $admin } from "./client";

export function createTeam(args?: Partial<Parameters<typeof $admin.team.create>[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<Parameters<typeof $admin.team.create>[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<Parameters<typeof $admin.user.create>[0]>) {
return safely(() => $admin.user.create({
firstName: "Test",
lastName: "Test",
email: TEST_EMAIL,
...args,
}));
export function createUser(
args?: Partial<Parameters<typeof $admin.user.create>[0]>,
) {
return safely(() =>
$admin.user.create({
firstName: "Test",
lastName: "Test",
email: TEST_EMAIL,
...args,
}),
);
}

export function createFlow(args: Omit<Parameters<typeof $admin.flow.create>[0], "data">) {
return safely(() => $admin.flow.create({
data: { dummy: "flowData "},
...args,
}))
export function createFlow(
args: Omit<Parameters<typeof $admin.flow.create>[0], "data">,
) {
return safely(() =>
$admin.flow.create({
data: { dummy: "flowData " },
...args,
}),
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/api-driven/src/invite-to-pay/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ export const setup = async () => {
};

return world;
}
};
47 changes: 26 additions & 21 deletions e2e/tests/api-driven/src/invite-to-pay/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ export class CustomWorld extends World {
paymentRequestId?: string;
}

Before<CustomWorld>("@invite-to-pay", async function() {
Before<CustomWorld>("@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,
Expand All @@ -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",
Expand All @@ -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);
},
);
12 changes: 6 additions & 6 deletions e2e/tests/api-driven/src/permissions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ 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" });
const teamId2 = await createTeam({ name: "E2E Team 2", slug: "e2e-team2" });
const user1 = {
id: await createUser({ email: "[email protected]" }),
email: "[email protected]",
}
};
const user2 = {
id: await createUser({ email: "[email protected]" }),
email: "[email protected]",
}
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,
Expand All @@ -47,7 +47,7 @@ export const setup = async () => {
};

return world;
}
};

export const performGQLQuery = async ({
world,
Expand Down
14 changes: 10 additions & 4 deletions e2e/tests/api-driven/src/permissions/queries/flows.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
}
`
}
`;
4 changes: 2 additions & 2 deletions e2e/tests/api-driven/src/permissions/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { INSERT_FLOW_QUERY } from "./flows";
export const queries = {
flows: {
insert: INSERT_FLOW_QUERY,
}
}
},
};
59 changes: 26 additions & 33 deletions e2e/tests/api-driven/src/permissions/steps.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -22,19 +15,20 @@ export class CustomWorld extends World {
teamId2!: number;
team1Flow!: string;
team2Flow!: string;

error?: Error = undefined;
activeUser!: TestUser;
}

Before<CustomWorld>("@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 () {
Expand All @@ -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,
Expand Down

0 comments on commit f456bcb

Please sign in to comment.