Skip to content

Commit

Permalink
BHBC-1783: Error When Editing Purpose and Methodology (#787)
Browse files Browse the repository at this point in the history
Fixed an error that occurred when attempting to edit the ‘Purpose and Methodology’ section of a survey.

 - Updated schema validation for GET on purpose_methodology update endpoint.
 - BHBC-1783: Add API response validation testing to update endpoint (work in progress).
 - BHBC-1783: Amend platform-service and its test file w 'dwc/submission/create' endpoint.
  • Loading branch information
curtisupshall authored Jun 6, 2022
1 parent d6da2ea commit 55d97a6
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 5 deletions.
113 changes: 113 additions & 0 deletions api/src/paths/project/{projectId}/survey/{surveyId}/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import chai, { expect } from 'chai';
import { describe } from 'mocha';
import OpenAPIResponseValidator, { OpenAPIResponseValidatorArgs } from 'openapi-response-validator';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import SQL from 'sql-template-strings';
Expand All @@ -18,6 +19,118 @@ describe('getSurveyForUpdate', () => {
sinon.restore();
});

describe('response validation', () => {
const responseValidator = new OpenAPIResponseValidator(
(update.GET.apiDoc as unknown) as OpenAPIResponseValidatorArgs
);

describe('should succeed when', () => {
it('has valid values', async () => {
const apiResponse = {
survey_details: {
id: 1,
survey_name: 'name',
focal_species: [1],
ancillary_species: [3],
start_date: '2020-04-04',
end_date: '2020-05-05',
biologist_first_name: 'first',
biologist_last_name: 'last',
survey_area_name: 'location',
revision_count: 1,
geometry: [],
permit_number: '',
permit_type: '',
completion_status: COMPLETION_STATUS.COMPLETED,
publish_date: '',
funding_sources: [1]
},
survey_purpose_and_methodology: {
id: 1,
intended_outcome_id: 8,
field_method_id: 1,
additional_details: 'details',
ecological_season_id: 1,
vantage_code_ids: [2],
surveyed_all_areas: 'true',
revision_count: 0
},
survey_proprietor: {
category_rationale: '',
data_sharing_agreement_required: 'false',
first_nations_id: null,
first_nations_name: '',
id: 1,
proprietary_data_category: null,
proprietary_data_category_name: '',
proprietor_name: '',
survey_data_proprietary: 'true',
revision_count: 1
}
};
const response = responseValidator.validateResponse(200, apiResponse);
expect(response).to.equal(undefined);
});

it('consists of an empty response', async () => {
const apiResponse = {
survey_details: null,
survey_purpose_and_methodology: null,
survey_proprietor: null
};
const response = responseValidator.validateResponse(200, apiResponse);
expect(response).to.equal(undefined);
});

it('contains nullable values where applicable', async () => {
const apiResponse = {
survey_details: {
id: 1,
survey_name: 'name',
focal_species: [1],
ancillary_species: [3],
start_date: '2020-04-04',
end_date: null,
biologist_first_name: 'first',
biologist_last_name: 'last',
survey_area_name: 'location',
revision_count: 1,
geometry: [],
permit_number: '',
permit_type: '',
completion_status: COMPLETION_STATUS.COMPLETED,
publish_date: '',
funding_sources: [1]
},
survey_purpose_and_methodology: {
id: 1,
intended_outcome_id: null,
field_method_id: 1,
additional_details: null,
ecological_season_id: null,
vantage_code_ids: [],
surveyed_all_areas: 'true',
revision_count: 0
},
survey_proprietor: {
category_rationale: '',
data_sharing_agreement_required: 'false',
first_nations_id: null,
first_nations_name: '',
id: 1,
proprietary_data_category: null,
proprietary_data_category_name: '',
proprietor_name: '',
survey_data_proprietary: 'true',
revision_count: 1
}
};
const response = responseValidator.validateResponse(200, apiResponse);
expect(response).to.equal(undefined);
});
});
});

it('should throw a 400 error when no survey id path param', async () => {
const dbConnectionObj = getMockDBConnection();

Expand Down
9 changes: 6 additions & 3 deletions api/src/paths/project/{projectId}/survey/{surveyId}/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@ GET.apiDoc = {
nullable: true
},
intended_outcome_id: {
type: 'number'
type: 'number',
nullable: true
},
ecological_season_id: {
type: 'number'
type: 'number',
nullable: true
},
vantage_code_ids: {
type: 'array',
Expand Down Expand Up @@ -273,7 +275,8 @@ GET.apiDoc = {
type: 'string'
},
proprietary_data_category: {
type: 'number'
type: 'number',
nullable: true
},
proprietary_data_category_name: {
type: 'string'
Expand Down
2 changes: 1 addition & 1 deletion api/src/services/platform-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('PlatformService', () => {
expect(keycloakServiceStub).to.have.been.calledOnce;

expect(axiosStub).to.have.been.calledOnceWith(
'backbone.com/api/dwc/dataset/create',
'backbone.com/api/dwc/submission/create',
sinon.match.instanceOf(Buffer),
{
headers: {
Expand Down
2 changes: 1 addition & 1 deletion api/src/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IDwCADataset {

export class PlatformService {
BACKBONE_API_HOST = process.env.BACKBONE_API_HOST;
BACKBONE_API_INGEST_PATH = '/api/dwc/dataset/create';
BACKBONE_API_INGEST_PATH = '/api/dwc/submission/create';

/**
* Submit a new Darwin Core Archive (DwCA) data package to the BioHub Platform Backbone.
Expand Down

0 comments on commit 55d97a6

Please sign in to comment.