-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGetFile.test.ts
More file actions
89 lines (72 loc) · 3 KB
/
Copy pathGetFile.test.ts
File metadata and controls
89 lines (72 loc) · 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { createFileModel } from '../../testHelpers/files/filesHelper'
import { IFilesRepository } from '../../../src/files/domain/repositories/IFilesRepository'
import { GetFile } from '../../../src/files/domain/useCases/GetFile'
import { DatasetNotNumberedVersion, ReadError } from '../../../src'
describe('execute', () => {
test('should return file on repository success when passing numeric id', async () => {
const testFile = createFileModel()
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository
filesRepositoryStub.getFile = jest.fn().mockResolvedValue(testFile)
const sut = new GetFile(filesRepositoryStub)
const actual = await sut.execute(1)
expect(actual).toEqual(testFile)
expect(filesRepositoryStub.getFile).toHaveBeenCalledWith(
1,
DatasetNotNumberedVersion.LATEST,
false,
false
)
})
test('should return file on repository success when passing string id', async () => {
const testFile = createFileModel()
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository
filesRepositoryStub.getFile = jest.fn().mockResolvedValue(testFile)
const sut = new GetFile(filesRepositoryStub)
const actual = await sut.execute('doi:10.5072/FK2/J8SJZB')
expect(actual).toEqual(testFile)
expect(filesRepositoryStub.getFile).toHaveBeenCalledWith(
'doi:10.5072/FK2/J8SJZB',
DatasetNotNumberedVersion.LATEST,
false,
false
)
})
test('should return file on repository success when passing string id and version id', async () => {
const testFile = createFileModel()
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository
filesRepositoryStub.getFile = jest.fn().mockResolvedValue(testFile)
const sut = new GetFile(filesRepositoryStub)
const actual = await sut.execute('doi:10.5072/FK2/J8SJZB', '2.0')
expect(actual).toEqual(testFile)
expect(filesRepositoryStub.getFile).toHaveBeenCalledWith(
'doi:10.5072/FK2/J8SJZB',
'2.0',
false,
false
)
})
test('should return file on repository success when includeDeaccession is true', async () => {
const testFile = createFileModel()
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository
filesRepositoryStub.getFile = jest.fn().mockResolvedValue(testFile)
const sut = new GetFile(filesRepositoryStub)
const actual = await sut.execute(
'doi:10.5072/FK2/J8SJZB',
DatasetNotNumberedVersion.LATEST,
true
)
expect(actual).toEqual(testFile)
expect(filesRepositoryStub.getFile).toHaveBeenCalledWith(
'doi:10.5072/FK2/J8SJZB',
DatasetNotNumberedVersion.LATEST,
false,
true
)
})
test('should return error result on repository error', async () => {
const filesRepositoryStub: IFilesRepository = {} as IFilesRepository
filesRepositoryStub.getFile = jest.fn().mockRejectedValue(new ReadError())
const sut = new GetFile(filesRepositoryStub)
await expect(sut.execute(1)).rejects.toThrow(ReadError)
})
})