-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSetDefaultContributorRole.test.ts
More file actions
29 lines (25 loc) · 1.43 KB
/
SetDefaultContributorRole.test.ts
File metadata and controls
29 lines (25 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { ICollectionsRepository } from '../../../src/collections/domain/repositories/ICollectionsRepository'
import { WriteError } from '../../../src'
import { SetDefaultContributorRole } from '../../../src/collections/domain/useCases/SetDefaultContributorRole'
describe('execute', () => {
test('should set default contributor role on repository success', async () => {
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
collectionRepositoryStub.setDefaultContributorRole = jest.fn().mockResolvedValue(undefined)
const testSetDefaultContributorRole = new SetDefaultContributorRole(
collectionRepositoryStub
)
await expect(testSetDefaultContributorRole.execute(1, "curator")).resolves.toBeUndefined()
expect(collectionRepositoryStub.setDefaultContributorRole).toHaveBeenCalledWith(1, "curator")
})
test('should return error result on repository error', async () => {
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
collectionRepositoryStub.setDefaultContributorRole = jest
.fn()
.mockRejectedValue(new WriteError())
const testSetDefaultContributorRole = new SetDefaultContributorRole(
collectionRepositoryStub
)
await expect(testSetDefaultContributorRole.execute(1, "curator")).rejects.toThrow(WriteError)
expect(collectionRepositoryStub.setDefaultContributorRole).toHaveBeenCalledWith(1, "curator")
})
})