Skip to content

Commit

Permalink
prismaclient fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
jho44 committed Feb 27, 2024
1 parent 28e525a commit e24fd1c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
1 change: 1 addition & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const config: PlaywrightTestConfig = {
},
timeout: 10000,
testDir: 'tests',
testMatch:'*spec.ts',
use: {
locale: 'en-US',
timezoneId: 'America/Los_Angeles'
Expand Down
35 changes: 7 additions & 28 deletions tests/db.spec.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
import { expect, test } from '@playwright/test';
import { PrismaClient } from '@prisma/client';
import { expect } from '@playwright/test';
import SeedUtils from '../prisma/utils';
import { test } from './test';

const host = 'http://localhost:5173';
const prisma = new PrismaClient();
test.beforeAll(async () => {
const utils = new SeedUtils(new Date(), prisma);

await Promise.all([
utils.deleteUserAndHousehold('+12015550003'),
utils.deleteUserAndHousehold('+12015550004'),
utils.deleteAllFriendRequests()
]);

await Promise.all([
...[3, 4].map((userInd) => utils.createUserWithEmptyHousehold(userInd)),
...[4].map((userInd) => utils.createActiveSession(userInd))
]);

await Promise.all([
utils.createFriendRequest(4, 3),
utils.createHouseholdConnection(3, 5),
utils.createHouseholdInvite(5, 2)
]);
});

test.only("User can't save profile without session cookie", async ({ page, context }) => {
test("User can't save profile without session cookie", async ({ page, context }) => {
const res = await context.request.fetch(host + '/db', {
method: 'post',
headers: {
Expand All @@ -52,8 +31,8 @@ that info is derived from the session cookie
- User 6 fails to delete another user
*/

test.describe.only('Household Invites', () => {
test.beforeAll(async () => {
test.describe('Household Invites', () => {
test.beforeAll(async ({ prisma }) => {
const utils = new SeedUtils(new Date(), prisma);

await Promise.all([
Expand Down Expand Up @@ -117,8 +96,8 @@ test.describe.only('Household Invites', () => {
});
});

test.describe.only('Friend Requests', () => {
test.beforeAll(async () => {
test.describe('Friend Requests', () => {
test.beforeAll(async ({ prisma }) => {
const utils = new SeedUtils(new Date(), prisma);

await Promise.all([
Expand Down
13 changes: 13 additions & 0 deletions tests/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { test as base } from '@playwright/test';
import { PrismaClient } from '@prisma/client';

// Note that we pass worker fixture types as a second template parameter.
export const test = base.extend<{}, { prisma: PrismaClient }>({
prisma: [
async ({}, use) => {
const prisma = new PrismaClient();
await use(prisma);
},
{ scope: 'worker' }
],
});

0 comments on commit e24fd1c

Please sign in to comment.