Skip to content

Commit

Permalink
Move user creation and login to fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Nov 30, 2024
1 parent fdcb574 commit e63c1dd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
42 changes: 42 additions & 0 deletions testing/e2e/fixtures/auth.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { test } from "@playwright/test";

type Account = {
eveId: number;
name: string;
};

export const authFixture = test.extend<{}, { account: Account }>({
account: [
async ({}, use, workerInfo) => {
await use({
eveId: 1000 + workerInfo.workerIndex,
name: `E2E User ${workerInfo.workerIndex}`,
});
},
{ scope: "worker" },
],

page: async ({ page, request, account }, use) => {
const { name, eveId } = account;

await request.post("http://localhost:4001/clone-bay-mocking/create-user", {
data: {
main: {
eveId,
name,
corporation: { eveId: 123, name: "Jotain", ticker: "JTN" },
accessToken: "asd",
refreshToken: "asd",
},
alts: [],
admin: true,
},
});

await page.goto(
`http://localhost:4001/clone-bay-mocking/login?eveId=${eveId}`,
);

await use(page);
},
});
4 changes: 4 additions & 0 deletions testing/e2e/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { mergeTests } from "@playwright/test";
import { authFixture } from "./auth.fixture";

export const test = mergeTests(authFixture);
25 changes: 4 additions & 21 deletions testing/e2e/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
import { expect, test } from "@playwright/test";
import { expect } from "@playwright/test";
import { test } from "../fixtures/fixtures";

test("has title", async ({ page }) => {
await page.goto("");
await expect(page.getByText("Welcome to Holenav!")).toBeVisible();
});

test("Create folder", async ({ page, request }) => {
await request.post("http://localhost:4001/clone-bay-mocking/create-user", {
data: {
main: {
eveId: test.info().workerIndex,
name: `E2E User ${test.info().workerIndex}`,
corporation: { eveId: 123, name: "Jotain", ticker: "JTN" },
accessToken: "asd",
refreshToken: "asd",
},
alts: [],
admin: true,
},
});

await page.goto(
`http://localhost:4001/clone-bay-mocking/login?eveId=${test.info().workerIndex}`,
);

const mapName = `E2E Map ${test.info().workerIndex}`;
test("Create map", async ({ page, account }) => {
const mapName = `E2E Map ${account.eveId}`;
await page.goto("/system/J104809");
await page.getByRole("button", { name: "Select active map" }).click();
await page.getByRole("menuitem", { name: "New Map" }).click();
Expand Down

0 comments on commit e63c1dd

Please sign in to comment.