From 2677f7c3d35fb1d16bd2a2f1228bb1de3fbf686c Mon Sep 17 00:00:00 2001 From: Tyler Myracle Date: Sun, 21 Jan 2024 21:31:59 -0600 Subject: [PATCH] clean up after tests --- apps/e2e/src/support/e2e.ts | 10 ++++++++++ apps/server/src/app/routes/e2e.router.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/apps/e2e/src/support/e2e.ts b/apps/e2e/src/support/e2e.ts index 896a1612..7794688c 100644 --- a/apps/e2e/src/support/e2e.ts +++ b/apps/e2e/src/support/e2e.ts @@ -40,3 +40,13 @@ beforeEach(() => { }) cy.visit('/') }) + +after(() => { + cy.apiRequest({ + method: 'POST', + url: 'e2e/clean', + body: {}, + }).then((response) => { + expect(response.status).to.equal(200) + }) +}) diff --git a/apps/server/src/app/routes/e2e.router.ts b/apps/server/src/app/routes/e2e.router.ts index c82bcfcc..58d02e72 100644 --- a/apps/server/src/app/routes/e2e.router.ts +++ b/apps/server/src/app/routes/e2e.router.ts @@ -78,4 +78,19 @@ router.post( }) ) +router.post( + '/clean', + endpoint.create({ + resolve: async ({ ctx }) => { + const user = ctx.user! + await ctx.prisma.$transaction([ + ctx.prisma.$executeRaw`DELETE FROM "user" WHERE auth_id=${user.authId};`, + ctx.prisma.$executeRaw`DELETE FROM "auth_user" WHERE id=${user.authId};`, + ]) + + return { success: true } + }, + }) +) + export default router