Skip to content

Commit

Permalink
Survey- Additional Fields (#731)
Browse files Browse the repository at this point in the history
* create/view/edit  survey page with new purpose and methodology form
* addition of "ecological season", "intended outcome" and "vantage" lookup tables
& removal of common survey methodology - field table name change to "field method"
* "survey.objectives" attribute name change to "survey.additional_details"
*  seeding new lookup tables
* re-seed "field method" table
* tests
  • Loading branch information
anissa-agahchen authored Apr 14, 2022
1 parent 8e17b80 commit a1c59bd
Show file tree
Hide file tree
Showing 62 changed files with 3,653 additions and 1,220 deletions.
7 changes: 4 additions & 3 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@

| Technology | Version | Website | Description |
| ---------- | ------- | ------------------------------------ | -------------------- |
| node | 10.x.x | https://nodejs.org/en/ | JavaScript Runtime |
| node | 14.x.x | https://nodejs.org/en/ | JavaScript Runtime |
| npm | 6.x.x | https://www.npmjs.com/ | Node Package Manager |
| PostgreSQL | 9.6 | https://www.postgresql.org/download/ | PSQL database |

<br />

# API Specification

The root API schema is defined in `./src/openapi/api.ts`.

If this project is running in docker you can view the api docs at: `http://localhost:6100/api/api-docs/`.
If this project is running in docker you can view the beautified api docs at: `http://localhost:6100/api-docs/`.

- The raw api-docs are available at: `http://localhost:6100/raw-api-docs/`.

This project uses npm package `express-openapi` via `./app.ts` to automatically generate the express server and its routes, based on the contents of the `./src/openapi/api.ts` and the `./src/path/` content.

Expand Down
24 changes: 0 additions & 24 deletions api/src/models/survey-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ describe('PostSurveyObject', () => {
expect(data.survey_name).to.equal(null);
});

it('sets survey_purpose', () => {
expect(data.survey_purpose).to.equal(null);
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql([]);
});
Expand All @@ -26,10 +22,6 @@ describe('PostSurveyObject', () => {
expect(data.ancillary_species).to.eql([]);
});

it('sets common survey methodology id', () => {
expect(data.common_survey_methodology_id).to.equal(null);
});

it('sets start_date', () => {
expect(data.start_date).to.equal(null);
});
Expand Down Expand Up @@ -116,10 +108,6 @@ describe('PostSurveyObject', () => {
expect(data.survey_name).to.equal(surveyObj.survey_name);
});

it('sets survey_purpose', () => {
expect(data.survey_purpose).to.equal(surveyObj.survey_purpose);
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql(surveyObj.focal_species);
});
Expand All @@ -128,10 +116,6 @@ describe('PostSurveyObject', () => {
expect(data.ancillary_species).to.eql(surveyObj.ancillary_species);
});

it('sets common_survey_methodology_id', () => {
expect(data.common_survey_methodology_id).to.eql(surveyObj.common_survey_methodology_id);
});

it('sets start_date', () => {
expect(data.start_date).to.equal(surveyObj.start_date);
});
Expand Down Expand Up @@ -205,10 +189,6 @@ describe('PostSurveyObject', () => {
expect(data.survey_name).to.equal(surveyObj.survey_name);
});

it('sets survey_purpose', () => {
expect(data.survey_purpose).to.equal(surveyObj.survey_purpose);
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql(surveyObj.focal_species);
});
Expand All @@ -217,10 +197,6 @@ describe('PostSurveyObject', () => {
expect(data.ancillary_species).to.eql(surveyObj.ancillary_species);
});

it('sets common_survey_methodology_id', () => {
expect(data.common_survey_methodology_id).to.eql(surveyObj.common_survey_methodology_id);
});

it('sets start_date', () => {
expect(data.start_date).to.equal(surveyObj.start_date);
});
Expand Down
14 changes: 10 additions & 4 deletions api/src/models/survey-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ export class PostSurveyObject {
sedis_procedures_accepted: boolean;
focal_species: number[];
ancillary_species: number[];
common_survey_methodology_id: number;
field_method_id: number;
ecological_season_id: number;
vantage_code_ids: number[];
start_date: string;
end_date: string;
survey_area_name: string;
survey_data_proprietary: boolean;
survey_purpose: string;
intended_outcome_id: number;
additional_details: string;
geometry: Feature[];
permit_number: string;
permit_type: string;
Expand All @@ -48,15 +51,18 @@ export class PostSurveyObject {
this.sedis_procedures_accepted = obj?.sedis_procedures_accepted === 'true' || false;
this.focal_species = (obj?.focal_species?.length && obj.focal_species) || [];
this.ancillary_species = (obj?.ancillary_species?.length && obj.ancillary_species) || [];
this.common_survey_methodology_id = obj?.common_survey_methodology_id || null;
this.field_method_id = obj?.field_method_id || null;
this.start_date = obj?.start_date || null;
this.survey_area_name = obj?.survey_area_name || null;
this.permit_number = obj?.permit_number || null;
this.permit_type = obj?.permit_type || null;
this.funding_sources = (obj?.funding_sources?.length && obj.funding_sources) || [];
this.survey_data_proprietary = obj?.survey_data_proprietary === 'true' || false;
this.survey_name = obj?.survey_name || null;
this.survey_purpose = obj?.survey_purpose || null;
this.intended_outcome_id = obj?.intended_outcome_id || null;
this.ecological_season_id = obj?.ecological_season_id || null;
this.additional_details = obj?.additional_details || null;
this.vantage_code_ids = (obj?.vantage_code_ids?.length && obj.vantage_code_ids) || [];
this.geometry = (obj?.geometry?.length && obj.geometry) || [];
this.survey_proprietor =
(obj && obj.survey_data_proprietary === 'true' && new PostSurveyProprietorData(obj)) || undefined;
Expand Down
126 changes: 85 additions & 41 deletions api/src/models/survey-update.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import { describe } from 'mocha';
import { GetUpdateSurveyDetailsData, PutSurveyDetailsData } from './survey-update';
import { GetUpdateSurveyDetailsData, PutSurveyDetailsData, PutSurveyPurposeAndMethodologyData } from './survey-update';

describe('GetUpdateSurveyDetailsData', () => {
describe('No values provided', () => {
Expand All @@ -14,10 +14,6 @@ describe('GetUpdateSurveyDetailsData', () => {
expect(data.survey_name).to.equal('');
});

it('sets survey_purpose', () => {
expect(data.survey_purpose).to.equal('');
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql([]);
});
Expand All @@ -26,10 +22,6 @@ describe('GetUpdateSurveyDetailsData', () => {
expect(data.ancillary_species).to.eql([]);
});

it('sets common survey methodology id', () => {
expect(data.common_survey_methodology_id).to.equal(null);
});

it('sets start_date', () => {
expect(data.start_date).to.equal('');
});
Expand Down Expand Up @@ -107,10 +99,6 @@ describe('GetUpdateSurveyDetailsData', () => {
expect(data.survey_name).to.equal(surveyData.name);
});

it('sets survey_purpose', () => {
expect(data.survey_purpose).to.equal(surveyData.objectives);
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql(surveyData.focal_species);
});
Expand All @@ -119,10 +107,6 @@ describe('GetUpdateSurveyDetailsData', () => {
expect(data.ancillary_species).to.eql(surveyData.ancillary_species);
});

it('sets common survey methodology id', () => {
expect(data.common_survey_methodology_id).to.equal(surveyData.common_survey_methodology_id);
});

it('sets start_date', () => {
expect(data.start_date).to.equal(surveyData.start_date);
});
Expand Down Expand Up @@ -204,10 +188,6 @@ describe('GetUpdateSurveyDetailsData', () => {
expect(data.survey_name).to.equal(surveyData.name);
});

it('sets survey_purpose', () => {
expect(data.survey_purpose).to.equal(surveyData.objectives);
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql(surveyData.focal_species);
});
Expand All @@ -216,10 +196,6 @@ describe('GetUpdateSurveyDetailsData', () => {
expect(data.ancillary_species).to.eql(surveyData.ancillary_species);
});

it('sets common survey methodology id', () => {
expect(data.common_survey_methodology_id).to.equal(surveyData.common_survey_methodology_id);
});

it('sets start_date', () => {
expect(data.start_date).to.equal(surveyData.start_date);
});
Expand Down Expand Up @@ -274,10 +250,6 @@ describe('PutSurveyData', () => {
expect(data.name).to.equal(null);
});

it('sets objectives', () => {
expect(data.objectives).to.equal(null);
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql([]);
});
Expand All @@ -286,10 +258,6 @@ describe('PutSurveyData', () => {
expect(data.ancillary_species).to.eql([]);
});

it('sets common_survey_methodology_id', () => {
expect(data.common_survey_methodology_id).to.equal(null);
});

it('sets geometry', () => {
expect(data.geometry).to.equal(null);
});
Expand Down Expand Up @@ -363,10 +331,6 @@ describe('PutSurveyData', () => {
expect(data.name).to.equal(surveyData.survey_details.survey_name);
});

it('sets objectives', () => {
expect(data.objectives).to.equal(surveyData.survey_details.survey_purpose);
});

it('sets focal_species', () => {
expect(data.focal_species).to.eql(surveyData.survey_details.focal_species);
});
Expand All @@ -375,10 +339,6 @@ describe('PutSurveyData', () => {
expect(data.ancillary_species).to.eql(surveyData.survey_details.ancillary_species);
});

it('sets common_survey_methodology_id', () => {
expect(data.common_survey_methodology_id).to.equal(surveyData.survey_details.common_survey_methodology_id);
});

it('sets start_date', () => {
expect(data.start_date).to.equal(surveyData.survey_details.start_date);
});
Expand Down Expand Up @@ -408,3 +368,87 @@ describe('PutSurveyData', () => {
});
});
});

describe('PutSurveyPurposeAndMethodologyData', () => {
describe('No values provided', () => {
let data: PutSurveyPurposeAndMethodologyData;

before(() => {
data = new PutSurveyPurposeAndMethodologyData(null);
});

it('sets id', () => {
expect(data.id).to.equal(null);
});

it('sets intended_outcomes_id', () => {
expect(data.intended_outcome_id).to.eql(null);
});

it('sets field_method_id', () => {
expect(data.field_method_id).to.eql(null);
});

it('sets additional_details', () => {
expect(data.additional_details).to.equal(null);
});

it('sets ecological_season_id', () => {
expect(data.ecological_season_id).to.equal(null);
});

// it('sets vantage_code_ids', () => {
// expect(data.vantage_code_ids).to.equal([]);
// });

it('sets revision_count', () => {
expect(data.revision_count).to.equal(null);
});
});

describe('All values provided', () => {
let data: PutSurveyPurposeAndMethodologyData;

const purposeAndMethodologyData = {
id: 1,
field_method_id: 1,
additional_details: 'additional details',
vantage_code_ids: [1, 2],
ecological_season_id: 1,
intended_outcome_id: 1,
revision_count: 1
};

before(() => {
data = new PutSurveyPurposeAndMethodologyData(purposeAndMethodologyData);
});

it('sets id', () => {
expect(data.id).to.equal(purposeAndMethodologyData.id);
});

it('sets intended_outcomes_id', () => {
expect(data.intended_outcome_id).to.eql(purposeAndMethodologyData.intended_outcome_id);
});

it('sets additional_details', () => {
expect(data.additional_details).to.eql(purposeAndMethodologyData.additional_details);
});

it('sets field_method_id', () => {
expect(data.field_method_id).to.equal(purposeAndMethodologyData.field_method_id);
});

it('sets ecological_season_id', () => {
expect(data.ecological_season_id).to.equal(purposeAndMethodologyData.ecological_season_id);
});

it('sets vantage_code_ids', () => {
expect(data.vantage_code_ids).to.equal(purposeAndMethodologyData.vantage_code_ids);
});

it('sets revision_count', () => {
expect(data.revision_count).to.equal(purposeAndMethodologyData.revision_count);
});
});
});
Loading

0 comments on commit a1c59bd

Please sign in to comment.