From 5e865d24e14ea1e921efa300d6c6fb9a127faba5 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Thu, 5 Jan 2023 17:12:05 +0800 Subject: [PATCH] Fix: reset database tables before integration tests --- src/integration/NotificationOnEditHandler.spec.ts | 12 ++++++++++++ src/integration/Notifications.spec.ts | 9 +++++++++ src/integration/Reviews.spec.ts | 2 ++ 3 files changed, 23 insertions(+) diff --git a/src/integration/NotificationOnEditHandler.spec.ts b/src/integration/NotificationOnEditHandler.spec.ts index ed66a041e..cbebc2633 100644 --- a/src/integration/NotificationOnEditHandler.spec.ts +++ b/src/integration/NotificationOnEditHandler.spec.ts @@ -110,6 +110,18 @@ describe("Notifications Router", () => { changed_files: [], created_at: new Date(), }) + + // We need to force the relevant tables to start from a clean slate + // Otherwise, some tests may fail due to the auto-incrementing IDs + // not starting from 1 + await User.sync({ force: true }) + await Site.sync({ force: true }) + await Repo.sync({ force: true }) + await SiteMember.sync({ force: true }) + await Notification.sync({ force: true }) + await ReviewMeta.sync({ force: true }) + await ReviewRequest.sync({ force: true }) + // Set up User and Site table entries await User.create({ id: mockIsomerUserId, diff --git a/src/integration/Notifications.spec.ts b/src/integration/Notifications.spec.ts index 412270a9b..79b822be5 100644 --- a/src/integration/Notifications.spec.ts +++ b/src/integration/Notifications.spec.ts @@ -110,6 +110,15 @@ describe("Notifications Router", () => { const MOCK_ANOTHER_SITE_MEMBER_ID = "3" beforeAll(async () => { + // We need to force the relevant tables to start from a clean slate + // Otherwise, some tests may fail due to the auto-incrementing IDs + // not starting from 1 + await User.sync({ force: true }) + await Site.sync({ force: true }) + await Repo.sync({ force: true }) + await SiteMember.sync({ force: true }) + await Notification.sync({ force: true }) + // Set up User and Site table entries await User.create({ id: mockIsomerUserId, diff --git a/src/integration/Reviews.spec.ts b/src/integration/Reviews.spec.ts index cf5ddf44b..7179bafef 100644 --- a/src/integration/Reviews.spec.ts +++ b/src/integration/Reviews.spec.ts @@ -139,6 +139,8 @@ describe("Review Requests Integration Tests", () => { await Site.sync({ force: true }) await Repo.sync({ force: true }) await SiteMember.sync({ force: true }) + await Notification.sync({ force: true }) + await ReviewMeta.sync({ force: true }) await User.create(MOCK_USER_DBENTRY_ONE) await User.create(MOCK_USER_DBENTRY_TWO)