Skip to content

Commit

Permalink
SIMSBIOHUB-459: Revert test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisupshall committed Feb 12, 2024
1 parent c0da5e4 commit ed941b6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
18 changes: 16 additions & 2 deletions api/src/repositories/taxonomy-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('TaxonomyRepository', () => {
});

describe('addItisTaxonRecord', () => {
it('should return undefined on successful insert', async () => {
it('should return a new taxon record', async () => {
const mockQueryResponse = {
rowCount: 1,
rows: [
Expand Down Expand Up @@ -75,7 +75,21 @@ describe('TaxonomyRepository', () => {

const response = await taxonomyRepository.addItisTaxonRecord(1, 'string', 'string', {}, 'string');

expect(response).to.be.eql(undefined);
expect(response).to.be.eql({
taxon_id: 1,
itis_tsn: 1,
bc_taxon_code: 'string',
itis_scientific_name: 'string',
common_name: 'string',
itis_data: {},
record_effective_date: 'string',
record_end_date: 'string',
create_date: 'string',
create_user: 1,
update_date: 'string',
update_user: 1,
revision_count: 1
});
});
});

Expand Down
50 changes: 37 additions & 13 deletions api/src/services/taxonomy-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('TaxonomyService', () => {

const response = await taxonomyService.getTaxonByTsnIds([1]);

expect(repo).to.be.calledTwice;
expect(repo).to.be.calledOnce;
expect(response).to.be.eql([{ tsn: 1, commonName: 'common_name', scientificName: 'itis_scientific_name' }]);
});

Expand Down Expand Up @@ -104,24 +104,19 @@ describe('TaxonomyService', () => {

const taxonomyService = new TaxonomyService(mockDBConnection);

const getTaxonByTsnIdsStub = sinon
.stub(TaxonomyRepository.prototype, 'getTaxonByTsnIds')
.onCall(0)
.resolves([getTaxonRecord[0]])
.onCall(1)
.resolves([...getTaxonRecord]);
const repo = sinon.stub(TaxonomyRepository.prototype, 'getTaxonByTsnIds').resolves([getTaxonRecord[0]]);

const searchItisByTSNStub = sinon
.stub(ItisService.prototype, 'searchItisByTSN')
.resolves(getItisSolrSearchResponse);

const addItisTaxonRecordStub = sinon.stub(TaxonomyService.prototype, 'addItisTaxonRecord').resolves();
const itisService = sinon.stub(TaxonomyService.prototype, 'addItisTaxonRecord').resolves(getTaxonRecord[1]);

const response = await taxonomyService.getTaxonByTsnIds([1, 2]);

expect(getTaxonByTsnIdsStub).to.be.calledTwice;
expect(repo).to.be.calledOnce;
expect(searchItisByTSNStub).to.be.calledOnce;
expect(addItisTaxonRecordStub).to.be.calledOnce;
expect(itisService).to.be.calledOnce;
expect(response).to.be.eql([
{ tsn: 1, commonName: 'common_name', scientificName: 'itis_scientific_name' },
{ tsn: 2, commonName: 'common_name', scientificName: 'itis_scientific_name' }
Expand All @@ -135,11 +130,40 @@ describe('TaxonomyService', () => {

const taxonomyService = new TaxonomyService(mockDBConnection);

const addItisTaxonRecordStub = sinon.stub(TaxonomyRepository.prototype, 'addItisTaxonRecord').resolves();

await taxonomyService.addItisTaxonRecord(getItisSolrSearchResponse[0]);
const addItisTaxonRecordStub = sinon.stub(TaxonomyRepository.prototype, 'addItisTaxonRecord').resolves({
taxon_id: 1,
itis_tsn: 1,
bc_taxon_code: null,
itis_scientific_name: 'scientificName',
common_name: 'commonName',
itis_data: {},
record_effective_date: 'updateDate',
record_end_date: null,
create_date: 'now',
create_user: 1,
update_date: null,
update_user: null,
revision_count: 1
});

const response = await taxonomyService.addItisTaxonRecord(getItisSolrSearchResponse[0]);

expect(addItisTaxonRecordStub).to.be.calledOnce;
expect(response).to.be.eql({
taxon_id: 1,
itis_tsn: 1,
bc_taxon_code: null,
itis_scientific_name: 'scientificName',
common_name: 'commonName',
itis_data: {},
record_effective_date: 'updateDate',
record_end_date: null,
create_date: 'now',
create_user: 1,
update_date: null,
update_user: null,
revision_count: 1
});
});
});

Expand Down

0 comments on commit ed941b6

Please sign in to comment.