Skip to content

Commit

Permalink
BHBC-2076: Add test for useResourcesApi
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisupshall committed Jan 12, 2023
1 parent d9dd16d commit f197c0b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions app/src/hooks/api/useResourcesApi.test.ts
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'
}
});
});
});

0 comments on commit f197c0b

Please sign in to comment.