Skip to content

Commit

Permalink
Delete created data after all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelnietoa committed Jan 25, 2022
1 parent 5a529d0 commit 833471b
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions playwright/auth/auth-index.test.ts
Expand Up @@ -22,27 +22,18 @@ test.describe("Can signup from a team invite", async () => {

await page.goto("/settings/teams");

// If team does not exist, create it
try {
await page.waitForSelector(`a[title="${team}"]`, { timeout: 3000 });
} catch (error) {
// Create New Team
await page.click('button[type="button"]');
await page.fill('input[name="name"]', team);
await page.click('button[type="submit"]');
}
// Create New Team
await page.click('button[type="button"]');
await page.fill('input[name="name"]', team);
await page.click('button[type="submit"]');

// Click the team link
await page.click(`a[title="${team}"]`);

try {
await page.waitForSelector(`[data-testid="member-email"][data-email="${email}"]`, { timeout: 3000 });
} catch (error) {
// Send invite to team
await page.click('[data-testid="new-member-button"]');
await page.fill('input[id="inviteUser"]', email);
await page.click('[data-testid="invite-new-member-button"]');
}
// Send invite to team
await page.click('[data-testid="new-member-button"]');
await page.fill('input[id="inviteUser"]', email);
await page.click('[data-testid="invite-new-member-button"]');

const tokenObj = await prisma.verificationRequest.findFirst({
where: { identifier: email },
Expand All @@ -53,14 +44,40 @@ test.describe("Can signup from a team invite", async () => {
});

test.afterAll(async () => {
// Delete user with email
// Delete test user
await prisma.user.delete({
where: { email },
});
// Delete verification request with token
// Delete verification request
await prisma.verificationRequest.delete({
where: { token },
});
// Delete membership of pro user with the "test-team" team
// First, let's find the userId of the pro user
const proUserId = (
await prisma.user.findUnique({
where: { username: usernameAlreadyTaken },
select: { id: true },
})
)?.id;
if (!proUserId) return;
// Then, let's find the teamId of the "test-team" team
const teamId = (
await prisma.team.findUnique({
where: { slug: team },
select: { id: true },
})
)?.id;
if (!teamId) return;

// Now, let's delete the membership
await prisma.membership.delete({
where: {
userId_teamId: { userId: proUserId, teamId },
},
});
// And finally, delete the team
await prisma.team.delete({ where: { slug: team } });
});

test("Username already taken", async ({ page }) => {
Expand Down

0 comments on commit 833471b

Please sign in to comment.