-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGetCollectionsForCreating.test.ts
More file actions
28 lines (23 loc) · 1.3 KB
/
GetCollectionsForCreating.test.ts
File metadata and controls
28 lines (23 loc) · 1.3 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
import { ICollectionsRepository } from '../../../src/collections/domain/repositories/ICollectionsRepository'
import { GetCollectionsForCreating } from '../../../src/collections/domain/useCases/GetCollectionsForCreating'
import { CollectionSummary, ReadError } from '../../../src'
const sample: CollectionSummary[] = [
{ id: 1, alias: 'col1', displayName: 'Collection 1' },
{ id: 2, alias: 'col2', displayName: 'Collection 2' }
]
describe('GetCollectionsForCreating', () => {
test('should return collections for creating on success', async () => {
const repo: ICollectionsRepository = {} as ICollectionsRepository
repo.getCollectionsForCreating = jest.fn().mockResolvedValue(sample)
const uc = new GetCollectionsForCreating(repo)
await expect(uc.execute('testUser')).resolves.toEqual(sample)
expect(repo.getCollectionsForCreating).toHaveBeenCalledWith('testUser')
})
test('should return error result on repository error', async () => {
const repo: ICollectionsRepository = {} as ICollectionsRepository
repo.getCollectionsForCreating = jest.fn().mockRejectedValue(new ReadError('x'))
const uc = new GetCollectionsForCreating(repo)
await expect(uc.execute('testUser')).rejects.toThrow(ReadError)
expect(repo.getCollectionsForCreating).toHaveBeenCalledWith('testUser')
})
})