diff --git a/src/integration/NotificationOnEditHandler.spec.ts b/src/integration/NotificationOnEditHandler.spec.ts index b84a2b07a..a19fae18d 100644 --- a/src/integration/NotificationOnEditHandler.spec.ts +++ b/src/integration/NotificationOnEditHandler.spec.ts @@ -119,7 +119,8 @@ const reviewRequestService = new ReviewRequestService( ReviewMeta, ReviewRequestView, pageService, - configService + configService, + sequelize ) // Using a mock SitesCacheService as the actual service has setInterval // which causes tests to not exit. diff --git a/src/integration/Notifications.spec.ts b/src/integration/Notifications.spec.ts index ece332ae8..bde797402 100644 --- a/src/integration/Notifications.spec.ts +++ b/src/integration/Notifications.spec.ts @@ -112,7 +112,8 @@ const reviewRequestService = new ReviewRequestService( ReviewMeta, ReviewRequestView, pageService, - configService + configService, + sequelize ) // Using a mock SitesCacheService as the actual service has setInterval // which causes tests to not exit. diff --git a/src/integration/Privatisation.spec.ts b/src/integration/Privatisation.spec.ts index 4c3fec07c..77f728393 100644 --- a/src/integration/Privatisation.spec.ts +++ b/src/integration/Privatisation.spec.ts @@ -141,7 +141,8 @@ const reviewRequestService = new ReviewRequestService( ReviewMeta, ReviewRequestView, pageService, - configService + configService, + sequelize ) // Using a mock SitesCacheService as the actual service has setInterval // which causes tests to not exit. diff --git a/src/integration/Reviews.spec.ts b/src/integration/Reviews.spec.ts index 26e4b1fe9..7728aaae4 100644 --- a/src/integration/Reviews.spec.ts +++ b/src/integration/Reviews.spec.ts @@ -144,7 +144,8 @@ const reviewRequestService = new ReviewRequestService( ReviewMeta, ReviewRequestView, pageService, - configService + configService, + sequelize ) // Using a mock SitesCacheService as the actual service has setInterval // which causes tests to not exit. diff --git a/src/integration/Sites.spec.ts b/src/integration/Sites.spec.ts index d0ac87540..6983b574e 100644 --- a/src/integration/Sites.spec.ts +++ b/src/integration/Sites.spec.ts @@ -111,7 +111,8 @@ const reviewRequestService = new ReviewRequestService( ReviewMeta, ReviewRequestView, pageService, - configService + configService, + sequelize ) // Using a mock SitesCacheService as the actual service has setInterval // which causes tests to not exit. diff --git a/src/services/review/__tests__/ReviewRequestService.spec.ts b/src/services/review/__tests__/ReviewRequestService.spec.ts index ef7d70ad7..31f405959 100644 --- a/src/services/review/__tests__/ReviewRequestService.spec.ts +++ b/src/services/review/__tests__/ReviewRequestService.spec.ts @@ -1,6 +1,7 @@ import _ from "lodash" import { err, ok, okAsync } from "neverthrow" import { Attributes, ModelStatic } from "sequelize" +import { Sequelize } from "sequelize-typescript" import { ReviewRequest, @@ -52,7 +53,7 @@ import { import { mockUserWithSiteSessionData } from "@root/fixtures/sessionData" import { PageService } from "@root/services/fileServices/MdPageServices/PageService" import { ConfigService } from "@root/services/fileServices/YmlFileServices/ConfigService" -import { EditedPageDto, GithubCommentData } from "@root/types/dto/review" +import { GithubCommentData } from "@root/types/dto/review" import { Commit } from "@root/types/github" import * as ReviewApi from "@services/db/review" import _ReviewRequestService from "@services/review/ReviewRequestService" @@ -114,6 +115,10 @@ const MockConfigService = { isConfigFile: jest.fn(), } +const MockSequelize = { + transaction: jest.fn((transaction) => transaction()), +} + const ReviewRequestService = new _ReviewRequestService( (MockReviewApi as unknown) as typeof ReviewApi, (MockUsersRepository as unknown) as ModelStatic, @@ -122,7 +127,8 @@ const ReviewRequestService = new _ReviewRequestService( (MockReviewMetaRepository as unknown) as ModelStatic, (MockReviewRequestViewRepository as unknown) as ModelStatic, (MockPageService as unknown) as PageService, - (MockConfigService as unknown) as ConfigService + (MockConfigService as unknown) as ConfigService, + (MockSequelize as unknown) as Sequelize ) const SpyReviewRequestService = { @@ -774,7 +780,7 @@ describe("ReviewRequestService", () => { MockReviewRequestRepository.findAll.mockResolvedValueOnce([ MOCK_REVIEW_REQUEST_ONE, ]) - MockReviewRequestViewRepository.upsert.mockResolvedValueOnce(undefined) + MockReviewRequestViewRepository.create.mockResolvedValueOnce(undefined) // Act await ReviewRequestService.markAllReviewRequestsAsViewed( @@ -783,13 +789,10 @@ describe("ReviewRequestService", () => { ) // Assert - expect(MockReviewRequestViewRepository.findAll).toHaveBeenCalled() - expect(MockReviewRequestRepository.findAll).toHaveBeenCalled() - expect(MockReviewRequestViewRepository.upsert).toHaveBeenCalledWith({ - reviewRequestId: MOCK_REVIEW_REQUEST_ONE.id, - siteId: mockSiteOrmResponseWithAllCollaborators.id, - userId: mockUserWithSiteSessionData.isomerUserId, - lastViewedAt: null, + MockSequelize.transaction(() => { + expect(MockReviewRequestViewRepository.findAll).toHaveBeenCalled() + expect(MockReviewRequestRepository.findAll).toHaveBeenCalled() + expect(MockReviewRequestViewRepository.create).toHaveBeenCalled() }) })