-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BHBC-2076: Add test for useResourcesApi
- Loading branch information
1 parent
d9dd16d
commit f197c0b
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import useResourcesApi from './useResourcesApi'; | ||
|
||
describe('useResourcesApi', () => { | ||
let mock: any; | ||
|
||
beforeEach(() => { | ||
mock = new MockAdapter(axios); | ||
}); | ||
|
||
afterEach(() => { | ||
mock.restore(); | ||
}); | ||
|
||
it('listResources works as expected for an empty list', async () => { | ||
mock.onGet('/api/resources/list').reply(200, { | ||
files: [] | ||
}); | ||
|
||
const result = await useResourcesApi(axios).listResources(); | ||
|
||
expect(result).toEqual({ files: [] }); | ||
}); | ||
|
||
it('listResources works as expected for a non-empty list', async () => { | ||
mock.onGet('/api/resources/list').reply(200, { | ||
files: [ | ||
{ | ||
fileName: 'filename', | ||
url: 'url', | ||
lastModified: 'lastmodified', | ||
fileSize: 10, | ||
metadata: { | ||
templateName: 'templatename', | ||
templateType: 'templatetype', | ||
species: 'species' | ||
} | ||
} | ||
] | ||
}); | ||
|
||
const result = await useResourcesApi(axios).listResources(); | ||
|
||
expect(result.files).toBeDefined(); | ||
expect(result.files.length).toEqual(1); | ||
expect(result.files[0]).toEqual({ | ||
fileName: 'filename', | ||
url: 'url', | ||
lastModified: 'lastmodified', | ||
fileSize: 10, | ||
metadata: { | ||
templateName: 'templatename', | ||
templateType: 'templatetype', | ||
species: 'species' | ||
} | ||
}); | ||
}); | ||
}); |