-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved database clearing into global-teardown.ts
- Loading branch information
1 parent
5185d9f
commit 7eb3a2a
Showing
3 changed files
with
30 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import clientPromise from "$lib/mongo/mongodb"; | ||
import type { ObjectId } from "mongodb"; | ||
import dotenv from "dotenv"; | ||
import type { FullConfig } from "@playwright/test"; | ||
dotenv.config(); | ||
|
||
async function globalTeardown(config: FullConfig) { | ||
const client = await clientPromise; | ||
|
||
for (let i = 1; i <= config.workers; i++) { | ||
console.log("clearing test user" + i + " data"); | ||
const sessionToken = process.env[`TEST_SESSION_${i}`]; | ||
if (!sessionToken) break; | ||
|
||
const sessionDocument = await client.db().collection("sessions").findOne({ sessionToken }); | ||
if (!sessionDocument) break; | ||
|
||
// Clear all test user generated data | ||
const userId = sessionDocument.userId as ObjectId; | ||
await client.db().collection("mesocycles").deleteMany({ userId }); | ||
await client.db().collection("mesocycleTemplates").deleteMany({ userId }); | ||
await client.db().collection("workouts").deleteMany({ userId }); | ||
await client.db().collection("userPreferences").deleteOne({ userId }); | ||
} | ||
} | ||
|
||
export default globalTeardown; |