Skip to content

Commit

Permalink
test(sequalize): pass jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed Jul 28, 2023
1 parent 76ba1bd commit 3658a17
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/integration/NotificationOnEditHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/integration/Notifications.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/integration/Privatisation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/integration/Reviews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/integration/Sites.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 13 additions & 10 deletions src/services/review/__tests__/ReviewRequestService.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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<User>,
Expand All @@ -122,7 +127,8 @@ const ReviewRequestService = new _ReviewRequestService(
(MockReviewMetaRepository as unknown) as ModelStatic<ReviewMeta>,
(MockReviewRequestViewRepository as unknown) as ModelStatic<ReviewRequestView>,
(MockPageService as unknown) as PageService,
(MockConfigService as unknown) as ConfigService
(MockConfigService as unknown) as ConfigService,
(MockSequelize as unknown) as Sequelize
)

const SpyReviewRequestService = {
Expand Down Expand Up @@ -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(
Expand All @@ -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()
})
})

Expand Down

0 comments on commit 3658a17

Please sign in to comment.