Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permits as first class citizens! #414

Merged
merged 22 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/constants/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const coordinator_agency = [
{ id: 6, name: 'Alaska Department of Fish and Game' },
{ id: 7, name: 'Alces Environmental Ltd.' },
{ id: 8, name: 'Allnorth Consultants Limited' },
{ id: 9, name: 'Allouette River Mnagement Society' },
{ id: 9, name: 'Allouette River Management Society' },
{ id: 10, name: 'AMEC Earth and Environmental' },
{ id: 11, name: 'Applied Aquatic Research Ltd.' },
{ id: 12, name: 'Applied Ecological Solutions Corp.' },
Expand Down
30 changes: 20 additions & 10 deletions api/src/models/permit-no-sampling.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { describe } from 'mocha';
import { PostPermitNoSamplingData, PostPermitNoSamplingObject } from './permit-no-sampling';
import { PostPermitNoSamplingObject } from './permit-no-sampling';
import { PostPermitData } from './project-create';

describe('postPermitNoSamplingObject', () => {
describe('No values provided', () => {
Expand Down Expand Up @@ -40,7 +41,8 @@ describe('postPermitNoSamplingObject', () => {
permit_number: '456',
permit_type: 'type 2'
}
]
],
existing_permits: [1, 2]
}
};

Expand Down Expand Up @@ -69,6 +71,14 @@ describe('postPermitNoSamplingObject', () => {
permit_number: '456',
permit_type: 'type 2'
}
],
existing_permits: [
{
permit_id: 1
},
{
permit_id: 2
}
]
});
});
Expand All @@ -77,10 +87,10 @@ describe('postPermitNoSamplingObject', () => {

describe('PostPermitNoSamplingData', () => {
describe('No values provided', () => {
let postPermitNoSamplingData: PostPermitNoSamplingData;
let postPermitNoSamplingData: PostPermitData;

before(() => {
postPermitNoSamplingData = new PostPermitNoSamplingData(null);
postPermitNoSamplingData = new PostPermitData(null);
});

it('sets permit to default values', function () {
Expand All @@ -89,12 +99,12 @@ describe('PostPermitNoSamplingData', () => {
});

describe('All values provided where permits has no length', () => {
let postPermitNoSamplingData: PostPermitNoSamplingData;
let postPermitNoSamplingData: PostPermitData;

const obj = { permits: [] };

before(() => {
postPermitNoSamplingData = new PostPermitNoSamplingData(obj);
postPermitNoSamplingData = new PostPermitData(obj);
});

it('sets permits', function () {
Expand All @@ -103,12 +113,12 @@ describe('PostPermitNoSamplingData', () => {
});

describe('All values provided where permits is null', () => {
let postPermitNoSamplingData: PostPermitNoSamplingData;
let postPermitNoSamplingData: PostPermitData;

const obj = { permits: null };

before(() => {
postPermitNoSamplingData = new PostPermitNoSamplingData(obj);
postPermitNoSamplingData = new PostPermitData(obj);
});

it('sets permits', function () {
Expand All @@ -117,12 +127,12 @@ describe('PostPermitNoSamplingData', () => {
});

describe('All values provided where permits is a valid array', () => {
let postPermitNoSamplingData: PostPermitNoSamplingData;
let postPermitNoSamplingData: PostPermitData;

const obj = { permits: [{ permit_number: 1, permit_type: 'type' }] };

before(() => {
postPermitNoSamplingData = new PostPermitNoSamplingData(obj);
postPermitNoSamplingData = new PostPermitData(obj);
});

it('sets permits', function () {
Expand Down
30 changes: 3 additions & 27 deletions api/src/models/permit-no-sampling.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getLogger } from '../utils/logger';
import { PostCoordinatorData } from './project-create';
import { PostCoordinatorData, PostPermitData } from './project-create';

const defaultLog = getLogger('models/permit-no-sampling');

Expand All @@ -11,41 +11,17 @@ const defaultLog = getLogger('models/permit-no-sampling');
*/
export class PostPermitNoSamplingObject {
coordinator: PostCoordinatorData;
permit: PostPermitNoSamplingData;
permit: PostPermitData;

constructor(obj?: any) {
defaultLog.debug({ label: 'PostPermitNoSamplingObject', message: 'params', obj });

this.coordinator = (obj?.coordinator && new PostCoordinatorData(obj.coordinator)) || null;
this.permit = (obj?.permit && new PostPermitNoSamplingData(obj.permit)) || null;
this.permit = (obj?.permit && new PostPermitData(obj.permit)) || null;
}
}

export interface IPostPermitNoSampling {
permit_number: string;
permit_type: string;
}

/**
* Processes POST /permit-no-sampling permit data
*
* @export
* @class PostPermitNoSamplingData
*/
export class PostPermitNoSamplingData {
permits: IPostPermitNoSampling[];

constructor(obj?: any) {
defaultLog.debug({ label: 'PostPermitNoSamplingData', message: 'params', obj });

this.permits =
(obj?.permits?.length &&
obj.permits.map((item: any) => {
return {
permit_number: item.permit_number,
permit_type: item.permit_type
};
})) ||
[];
}
}
15 changes: 5 additions & 10 deletions api/src/models/project-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ describe('PostProjectObject', () => {
permit: {
permits: [
{
permit_number: 1,
sampling_conducted: 'true'
permit_number: 1
}
]
},
Expand Down Expand Up @@ -305,8 +304,7 @@ describe('PostPermitData', () => {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'true'
permit_type: 'permit type'
}
]
};
Expand All @@ -319,8 +317,7 @@ describe('PostPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: true
permit_type: 'permit type'
}
]);
});
Expand All @@ -333,8 +330,7 @@ describe('PostPermitData', () => {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'false'
permit_type: 'permit type'
}
]
};
Expand All @@ -347,8 +343,7 @@ describe('PostPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: false
permit_type: 'permit type'
}
]);
});
Expand Down
18 changes: 15 additions & 3 deletions api/src/models/project-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class PostCoordinatorData {
export interface IPostPermit {
permit_number: string;
permit_type: string;
sampling_conducted: boolean;
}

export interface IPostExistingPermit {
permit_id: number;
}

/**
Expand All @@ -71,6 +74,7 @@ export interface IPostPermit {
*/
export class PostPermitData {
permits: IPostPermit[];
existing_permits: IPostExistingPermit[];

constructor(obj?: any) {
defaultLog.debug({ label: 'PostPermitData', message: 'params', obj });
Expand All @@ -80,8 +84,16 @@ export class PostPermitData {
obj.permits.map((item: any) => {
return {
permit_number: item.permit_number,
permit_type: item.permit_type,
sampling_conducted: (item.sampling_conducted === 'true' && true) || false
permit_type: item.permit_type
};
})) ||
[];

this.existing_permits =
(obj?.existing_permits?.length &&
obj.existing_permits.map((item: any) => {
return {
permit_id: item
};
})) ||
[];
Expand Down
102 changes: 1 addition & 101 deletions api/src/models/project-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
GetIUCNClassificationData,
PutLocationData,
PutFundingSource,
PutPermitData,
GetPermitData
} from './project-update';

Expand Down Expand Up @@ -478,106 +477,7 @@ describe('GetPermitData', () => {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'true'
}
]);
});
});
});

describe('PutPermitData', () => {
describe('No values provided', () => {
let projectPermitData: PutPermitData;

before(() => {
projectPermitData = new PutPermitData(null);
});

it('sets permits', function () {
expect(projectPermitData.permits).to.eql([]);
});
});

describe('All values provided are null', () => {
let projectPermitData: PutPermitData;

before(() => {
projectPermitData = new PutPermitData({
permits: null
});
});

it('sets permits', function () {
expect(projectPermitData.permits).to.eql([]);
});
});

describe('All values provided are empty arrays', () => {
let projectPermitData: PutPermitData;

before(() => {
projectPermitData = new PutPermitData({
permits: []
});
});

it('sets permits', function () {
expect(projectPermitData.permits).to.eql([]);
});
});

describe('All values provided with sampling conducted as true', () => {
let projectPermitData: PutPermitData;

const obj = {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'true'
}
]
};

before(() => {
projectPermitData = new PutPermitData(obj);
});

it('sets permits', function () {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: true
}
]);
});
});

describe('All values provided with sampling conducted as false', () => {
let projectPermitData: PutPermitData;

const obj = {
permits: [
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: 'false'
}
]
};

before(() => {
projectPermitData = new PutPermitData(obj);
});

it('sets permits', function () {
expect(projectPermitData.permits).to.eql([
{
permit_number: '1',
permit_type: 'permit type',
sampling_conducted: false
permit_type: 'permit type'
}
]);
});
Expand Down
Loading