-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77aa243
commit cee4687
Showing
2 changed files
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import dotenv from "dotenv"; | ||
import postgres from "postgres"; | ||
|
||
dotenv.config(); // Load .env file contents into process.env | ||
|
||
export const teardown = async () => { | ||
try { | ||
if (!process.env.DATABASE_URL || !process.env.E2E_USER_ID) | ||
throw new Error("Missing env variables for DB clean up script"); | ||
const db = postgres(process.env.DATABASE_URL as string); | ||
|
||
// the test suit adds posts created by the E2E user. We want to remove them between test runs | ||
await db` | ||
DELETE FROM "Post" WHERE "userId" = ${process.env.E2E_USER_ID as string} | ||
`; | ||
// the test suit adds comments created by the E2E user. We want to remove them between test runs | ||
await db` | ||
DELETE FROM "Comment" WHERE "userId" = ${process.env.E2E_USER_ID as string} | ||
`; | ||
|
||
console.log("DB clean up successful"); | ||
} catch (err) { | ||
console.log("Error while cleaning up DB after E2E test run", err); | ||
} | ||
}; | ||
|
||
export default teardown; |
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