Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: collaborators test #1326

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions src/services/identity/__tests__/CollaboratorsService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe("CollaboratorsService", () => {
}
const mockUsersService = {
findOrCreateByEmail: jest.fn(),
getWhitelistRecordsFromEmail: jest.fn(),
}

const collaboratorsService = new CollaboratorsService({
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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[]
)

Expand All @@ -130,7 +125,7 @@ describe("CollaboratorsService", () => {

// Assert
expect(role).toStrictEqual(null)
expect(mockWhitelistRepo.findAll).toHaveBeenCalled()
expect(mockUsersService.getWhitelistRecordsFromEmail).toHaveBeenCalled()
})
})

Expand Down
Loading