Skip to content

Commit

Permalink
added some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
al-rosenthal committed Jun 14, 2023
1 parent 4ffc506 commit 591c19a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
21 changes: 21 additions & 0 deletions api/src/repositories/submission-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SUBMISSION_MESSAGE_TYPE,
SUBMISSION_STATUS_TYPE
} from './submission-repository';
import { simsHandlebarsTemplate_DETAILS, simsHandlebarsTemplate_HEADER } from './templates/SIMS-handlebar-template';

chai.use(sinonChai);

Expand Down Expand Up @@ -881,4 +882,24 @@ describe('SubmissionRepository', () => {
expect(response).to.eql(mockResponse);
});
});

describe('getHandleBarsTemplateByDatasetId', () => {
beforeEach(() => {
sinon.restore();
});

it('should succeed with valid data', async () => {
const mockResponse = {
header: simsHandlebarsTemplate_HEADER,
details: simsHandlebarsTemplate_DETAILS
};
const mockDBConnection = getMockDBConnection();

const submissionRepository = new SubmissionRepository(mockDBConnection);

const response = await submissionRepository.getHandleBarsTemplateByDatasetId('uuid');

expect(response).to.eql(mockResponse);
});
});
});
20 changes: 20 additions & 0 deletions api/src/services/submission-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,24 @@ describe('SubmissionService', () => {
expect(response).to.be.eql(1);
});
});

describe('getHandleBarsTemplateByDatasetId', () => {
it('should succeed with valid data', async () => {
const mockDBConnection = getMockDBConnection();
const submissionService = new SubmissionService(mockDBConnection);

const repo = sinon.stub(SubmissionRepository.prototype, 'getHandleBarsTemplateByDatasetId').resolves({
header: 'header',
details: 'details'
});

const response = await submissionService.getHandleBarsTemplateByDatasetId('uuid');

expect(repo).to.be.calledOnce;
expect(response).to.be.eql({
header: 'header',
details: 'details'
});
});
});
});
5 changes: 3 additions & 2 deletions api/src/services/submission-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ export class SubmissionService extends DBService {
}

/**
* Gets an object containing handlebars templates for the dataset page for a given dataset ID
*
* @param datasetId
* @returns
* @param datasetId uuid used to fetch handlebars templates
* @returns An object containing
*/
async getHandleBarsTemplateByDatasetId(datasetId: string): Promise<IHandlebarsTemplates> {
return this.submissionRepository.getHandleBarsTemplateByDatasetId(datasetId);
Expand Down
13 changes: 13 additions & 0 deletions app/src/hooks/api/useDatasetApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,17 @@ describe('useDatasetApi', () => {
datasets: [{ datasetId: 'bbb' }, { datasetId: 'ccc' }]
});
});

it('getHandleBarsTemplateByDatasetId works as expected', async () => {
mock.onGet(`api/dwc/submission/uuid/handlebar`).reply(200, {
header: 'Header Template',
details: 'Details Template'
});

const results = await useDatasetApi(axios).getHandleBarsTemplateByDatasetId('uuid');
expect(results).toEqual({
header: 'Header Template',
details: 'Details Template'
});
});
});

0 comments on commit 591c19a

Please sign in to comment.