-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaywright.fixtures.ts
60 lines (57 loc) · 1.78 KB
/
playwright.fixtures.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { db } from "./src/lib/database";
import { Passwords } from "./src/lib/auth";
import { test as base } from "@playwright/test";
import { Kysely } from "kysely";
import { DB } from "kysely-codegen";
export { expect } from "@playwright/test";
type TestFixtures = {
db: Kysely<DB>;
viewer: { id: string; email: string; username: string | null };
};
export const test = base.extend<TestFixtures>({
async db({}, use) {
await use(db);
},
viewer: async ({ db, context }, use, testInfo) => {
const time = Date.now();
const username = `user${testInfo.workerIndex}${time}`;
const email = `${username}@test.com`;
const password = "password";
const user = await db
.insertInto("users")
.values({ email, password: await Passwords.hash(password) })
.returning(["id", "email", "username"])
.executeTakeFirstOrThrow();
const session = await db
.insertInto("sessions")
.values({ user_id: user.id })
.returning("id")
.executeTakeFirstOrThrow();
// TODO look at how supabase issues cookies...
await context.addCookies([
{
name: "viewer_session",
value: session.id,
domain: "localhost",
path: "/",
},
]);
await context.addCookies([
{
name: "viewer_timezone",
value: "America%2FChicago",
domain: "localhost",
path: "/",
},
]);
await use(user);
await db.deleteFrom("sessions").where("user_id", "=", user.id).execute();
// TODO don't nuke entire history, delete plus join didn't work
await db.deleteFrom("journal_entry_history").execute();
await db
.deleteFrom("journal_entries")
.where("user_id", "=", user.id)
.execute();
await db.deleteFrom("users").where("id", "=", user.id).execute();
},
});