Skip to content

Commit

Permalink
BHBC-918: Edit General Information (#180)
Browse files Browse the repository at this point in the history
* BHBC-918: Edit General Information

* Fix tests after rebase.
Add new modal tests for edit general information.

* Fix code smell
  • Loading branch information
NickPhura authored Mar 30, 2021
1 parent ee44536 commit 142e3c9
Show file tree
Hide file tree
Showing 53 changed files with 1,604 additions and 666 deletions.
2 changes: 1 addition & 1 deletion api/src/database/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export const getDBConnection = function (keycloakToken: string): IDBConnection {
const setSystemUserContextSQLStatement = setSystemUserContextSQL(userIdentifier, systemUserType);

if (!setSystemUserContextSQLStatement) {
throw new HTTP400('Failed to build SQL statement');
throw new HTTP400('Failed to build SQL user context statement');
}

try {
Expand Down
174 changes: 173 additions & 1 deletion api/src/models/project-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { describe } from 'mocha';
import {
GetCoordinatorData,
GetPartnershipsData,
GetProjectData,
GetObjectivesData,
PutCoordinatorData,
PutPartnershipsData,
PutSpeciesData,
PutObjectivesData
PutObjectivesData,
PutProjectData
} from './project-update';

describe('PutPartnershipsData', () => {
Expand Down Expand Up @@ -408,3 +410,173 @@ describe('PutObjectivesData', () => {
});
});
});

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

before(() => {
data = new GetProjectData();
});

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

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

it('sets project_activities', () => {
expect(data.project_activities).to.eql([]);
});

it('sets climate_change_initiatives', () => {
expect(data.climate_change_initiatives).to.eql([]);
});

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

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

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

describe('all values provided', () => {
const projectData = {
name: 'project name',
pt_id: 4,
start_date: '2020-04-20T07:00:00.000Z',
end_date: '2020-05-20T07:00:00.000Z',
revision_count: 1
};

const activityData = [{ a_id: 1 }, { a_id: 2 }];

const climateInitiativeData = [{ cci_id: 1 }, { cci_id: 2 }, { cci_id: 3 }];

let data: GetProjectData;

before(() => {
data = new GetProjectData(projectData, activityData, climateInitiativeData);
});

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

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

it('sets project_activities', () => {
expect(data.project_activities).to.eql([1, 2]);
});

it('sets climate_change_initiatives', () => {
expect(data.climate_change_initiatives).to.eql([1, 2, 3]);
});

it('sets start_date', () => {
expect(data.start_date).to.equal('2020-04-20T07:00:00.000Z');
});

it('sets end_date', () => {
expect(data.end_date).to.equal('2020-05-20T07:00:00.000Z');
});

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

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

before(() => {
data = new PutProjectData();
});

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

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

it('sets project_activities', () => {
expect(data.project_activities).to.eql([]);
});

it('sets climate_change_initiatives', () => {
expect(data.climate_change_initiatives).to.eql([]);
});

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

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

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

describe('all values provided', () => {
const obj = {
project_name: 'project name',
project_type: 4,
project_activities: [1, 2],
climate_change_initiatives: [1, 2, 3],
start_date: '2020-04-20T07:00:00.000Z',
end_date: '2020-05-20T07:00:00.000Z',
revision_count: 1
};

let data: PutProjectData;

before(() => {
data = new PutProjectData(obj);
});

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

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

it('sets project_activities', () => {
expect(data.project_activities).to.eql([1, 2]);
});

it('sets climate_change_initiatives', () => {
expect(data.climate_change_initiatives).to.eql([1, 2, 3]);
});

it('sets start_date', () => {
expect(data.start_date).to.equal('2020-04-20T07:00:00.000Z');
});

it('sets end_date', () => {
expect(data.end_date).to.equal('2020-05-20T07:00:00.000Z');
});

it('sets revision_count', () => {
expect(data.revision_count).to.equal(1);
});
});
});
43 changes: 38 additions & 5 deletions api/src/models/project-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export class PutSpeciesData {
export class PutProjectData {
name: string;
type: number;
project_activities: number[];
climate_change_initiatives: number[];
start_date: string;
end_date: string;
revision_count: number;
Expand All @@ -46,9 +48,11 @@ export class PutProjectData {

this.name = obj?.project_name || null;
this.type = obj?.project_type || null;
this.project_activities = (obj?.project_activities?.length && obj.project_activities) || [];
this.climate_change_initiatives = (obj?.climate_change_initiatives?.length && obj.climate_change_initiatives) || [];
this.start_date = obj?.start_date || null;
this.end_date = obj?.end_date || null;
this.revision_count = obj?.revision_count ?? null;
this.revision_count = obj?.revision_count || null;
}
}

Expand All @@ -62,7 +66,7 @@ export class PutLocationData {

this.location_description = (obj && obj.location_description) || null;
this.geometry = (obj?.geometry?.length && obj.geometry) || [];
this.revision_count = obj?.revision_count ?? null;
this.revision_count = obj?.revision_count || null;
}
}

Expand All @@ -76,7 +80,7 @@ export class PutObjectivesData {

this.objectives = obj?.objectives || '';
this.caveats = obj?.caveats || null;
this.revision_count = obj?.revision_count ?? null;
this.revision_count = obj?.revision_count || null;
}
}

Expand All @@ -96,7 +100,7 @@ export class PutCoordinatorData {
this.email_address = obj?.email_address || null;
this.coordinator_agency = obj?.coordinator_agency || null;
this.share_contact_details = (obj?.share_contact_details === 'true' && true) || false;
this.revision_count = obj?.revision_count ?? null;
this.revision_count = obj?.revision_count || null;
}
}

Expand Down Expand Up @@ -128,7 +132,7 @@ export class GetCoordinatorData {
this.email_address = obj?.coordinator_email_address || null;
this.coordinator_agency = obj?.coordinator_agency_name || null;
this.share_contact_details = (obj?.coordinator_public && 'true') || 'false';
this.revision_count = obj?.revision_count ?? null;
this.revision_count = obj?.revision_count || null;
}
}

Expand Down Expand Up @@ -205,3 +209,32 @@ export class GetObjectivesData {
this.revision_count = obj?.revision_count ?? null;
}
}

/**
* Pre-processes GET /projects/{projectId}/update project data
*
* @export
* @class GetProjectData
*/
export class GetProjectData {
project_name: string;
project_type: number;
project_activities: number[];
climate_change_initiatives: number[];
start_date: string;
end_date: string;
revision_count: number;

constructor(projectData?: any, activityData?: any[], climateInitiativeData?: any[]) {
defaultLog.debug({ label: 'GetProjectData', message: 'params', projectData, activityData, climateInitiativeData });

this.project_name = projectData?.name || '';
this.project_type = projectData?.pt_id || '';
this.project_activities = (activityData?.length && activityData.map((item) => item.a_id)) || [];
this.climate_change_initiatives =
(climateInitiativeData?.length && climateInitiativeData.map((item) => item.cci_id)) || [];
this.start_date = projectData?.start_date || '';
this.end_date = projectData?.end_date || '';
this.revision_count = projectData?.revision_count || null;
}
}
6 changes: 2 additions & 4 deletions api/src/models/project-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const defaultLog = getLogger('models/project-view');
*/
export class GetProjectData {
project_name: string;
project_type: number;
project_type_name: string;
project_type: string;
project_activities: number[];
climate_change_initiatives: number[];
start_date: string;
Expand All @@ -23,8 +22,7 @@ export class GetProjectData {
defaultLog.debug({ label: 'GetProjectData', message: 'params', projectData, activityData, climateInitiativeData });

this.project_name = projectData?.name || '';
this.project_type = projectData?.pt_id || '';
this.project_type_name = projectData?.pt_name || '';
this.project_type = projectData?.type || '';
this.project_activities = (activityData?.length && activityData.map((item) => item.a_id)) || [];
this.climate_change_initiatives =
(climateInitiativeData?.length && climateInitiativeData.map((item) => item.cci_id)) || [];
Expand Down
2 changes: 1 addition & 1 deletion api/src/paths/permit-no-sampling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const insertNoSamplePermitNumber = async (
if (!result || !result.id) {
throw {
status: 400,
message: 'Failed to insert into no_sample_permit table'
message: 'Failed to insert no-sampling permit data'
};
}

Expand Down
Loading

0 comments on commit 142e3c9

Please sign in to comment.