From 628da2230198be60edcdeffcc908afd01cbe9d79 Mon Sep 17 00:00:00 2001 From: Alexander Lee Date: Fri, 19 Apr 2024 16:55:08 +0800 Subject: [PATCH] fix: collaborators test --- .../__tests__/CollaboratorsService.spec.ts | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/services/identity/__tests__/CollaboratorsService.spec.ts b/src/services/identity/__tests__/CollaboratorsService.spec.ts index 5f1414bb1..c9d2cfbd5 100644 --- a/src/services/identity/__tests__/CollaboratorsService.spec.ts +++ b/src/services/identity/__tests__/CollaboratorsService.spec.ts @@ -51,6 +51,7 @@ describe("CollaboratorsService", () => { } const mockUsersService = { findOrCreateByEmail: jest.fn(), + getWhitelistRecordsFromEmail: jest.fn(), } const collaboratorsService = new CollaboratorsService({ @@ -70,15 +71,12 @@ describe("CollaboratorsService", () => { // Arrange const mockWhitelistEntries = [ { - id: mockWhitelistId, email: mockEmailAddress, expiry: null, - createdAt: new Date(), - updatedAt: new Date(), }, ] - mockWhitelistRepo.findAll.mockResolvedValue( - (mockWhitelistEntries as unknown) as Whitelist[] + mockUsersService.getWhitelistRecordsFromEmail.mockResolvedValue( + mockWhitelistEntries ) // Act @@ -88,22 +86,19 @@ describe("CollaboratorsService", () => { // Assert expect(role).toStrictEqual(CollaboratorRoles.Admin) - expect(mockWhitelistRepo.findAll).toHaveBeenCalled() + expect(mockUsersService.getWhitelistRecordsFromEmail).toHaveBeenCalled() }) it("should derive contributor role for valid contributor-eligible emails", async () => { // Arrange const mockWhitelistEntries = [ { - id: mockWhitelistId, email: mockEmailAddress, expiry: new Date(), - createdAt: new Date(), - updatedAt: new Date(), }, ] - mockWhitelistRepo.findAll.mockResolvedValue( - (mockWhitelistEntries as unknown) as Whitelist[] + mockUsersService.getWhitelistRecordsFromEmail.mockResolvedValue( + mockWhitelistEntries ) // Act @@ -113,13 +108,13 @@ describe("CollaboratorsService", () => { // Assert expect(role).toStrictEqual(CollaboratorRoles.Contributor) - expect(mockWhitelistRepo.findAll).toHaveBeenCalled() + expect(mockUsersService.getWhitelistRecordsFromEmail).toHaveBeenCalled() }) it("should derive no role for emails from non-whitelisted domains", async () => { // Arrange const mockWhitelistEntries: never[] = [] - mockWhitelistRepo.findAll.mockResolvedValue( + mockUsersService.getWhitelistRecordsFromEmail.mockResolvedValue( mockWhitelistEntries as Whitelist[] ) @@ -130,7 +125,7 @@ describe("CollaboratorsService", () => { // Assert expect(role).toStrictEqual(null) - expect(mockWhitelistRepo.findAll).toHaveBeenCalled() + expect(mockUsersService.getWhitelistRecordsFromEmail).toHaveBeenCalled() }) })