Skip to content

Commit

Permalink
BHBC-1545: Tech Debt: Updated apidoc for /user/* (#681)
Browse files Browse the repository at this point in the history
Update openapi doc for /user/* endpoints
Misc unit test updates
  • Loading branch information
anissa-agahchen authored Jan 7, 2022
1 parent cd03829 commit 22f0317
Show file tree
Hide file tree
Showing 12 changed files with 1,321 additions and 45 deletions.
437 changes: 437 additions & 0 deletions api/src/openapi/schemas/geoJson.ts

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions api/src/openapi/schemas/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
projectCreatePostRequestObject,
projectIdResponseObject,
projectUpdateGetResponseObject,
projectUpdatePutRequestObject,
projectViewGetResponseObject
projectUpdatePutRequestObject
} from './project';

describe('projectCreatePostRequestObject', () => {
Expand Down Expand Up @@ -40,11 +39,3 @@ describe('projectUpdatePutRequestObject', () => {
expect(ajv.validateSchema(projectUpdatePutRequestObject)).to.be.true;
});
});

describe('projectViewGetResponseObject', () => {
const ajv = new Ajv();

it('is valid openapi v3 schema', () => {
expect(ajv.validateSchema(projectViewGetResponseObject)).to.be.true;
});
});
9 changes: 0 additions & 9 deletions api/src/openapi/schemas/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@ export const projectCreatePostRequestObject = {
}
};

/**
* Response object for project view GET request
*/
export const projectViewGetResponseObject = {
title: 'Project get response object, for view purposes',
type: 'object',
properties: {}
};

const projectUpdateProperties = {
coordinator: {
type: 'object',
Expand Down
26 changes: 24 additions & 2 deletions api/src/paths/project/{projectId}/participants/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import chai, { expect } from 'chai';
import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import * as create_project_participants from './create';
import SQL from 'sql-template-strings';
import * as db from '../../../../database/db';
import { getMockDBConnection } from '../../../../__mocks__/db';
import { HTTPError } from '../../../../errors/custom-error';
import { getMockDBConnection } from '../../../../__mocks__/db';
import * as create_project_participants from './create';
import user_queries from '../../../../queries/users';

chai.use(sinonChai);

Expand Down Expand Up @@ -59,4 +61,24 @@ describe('creates a list of project participants', () => {
expect((actualError as HTTPError).message).to.equal('Missing required body param `participants`');
}
});

it('should throw an error when ensureSystemUserAndProjectParticipantUser fails', async () => {
const mockQuery = sinon.stub();

mockQuery.resolves({
rows: null
});

sinon.stub(db, 'getDBConnection').returns(dbConnectionObj);
sinon.stub(user_queries, 'getUserByUserIdentifierSQL').returns(SQL`something`);

try {
const result = create_project_participants.createProjectParticipants();
await result({ ...sampleReq }, (null as unknown) as any, (null as unknown) as any);
expect.fail();
} catch (actualError) {
expect((actualError as HTTPError).status).to.equal(400);
expect((actualError as HTTPError).message).to.equal('Failed to get system user');
}
});
});
238 changes: 236 additions & 2 deletions api/src/paths/project/{projectId}/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
GetProjectData
} from '../../../models/project-view';
import { GetFundingData } from '../../../models/project-view-update';
import { projectViewGetResponseObject } from '../../../openapi/schemas/project';
import { geoJsonFeature } from '../../../openapi/schemas/geoJson';
import { queries } from '../../../queries/queries';
import { authorizeRequestHandler } from '../../../request-handlers/security/authorization';
import { getLogger } from '../../../utils/logger';
Expand Down Expand Up @@ -59,7 +59,241 @@ GET.apiDoc = {
content: {
'application/json': {
schema: {
...(projectViewGetResponseObject as object)
title: 'Project get response object, for view purposes',
type: 'object',
required: [
'id',
'project',
'permit',
'coordinator',
'objectives',
'location',
'iucn',
'funding',
'partnerships'
],
properties: {
id: {
description: 'Project id',
type: 'number'
},
project: {
description: 'Basic project metadata',
type: 'object',
required: [
'project_name',
'project_type',
'project_activities',
'start_date',
'end_date',
'comments',
'completion_status',
'publish_date'
],
properties: {
project_name: {
type: 'string'
},
project_type: {
type: 'number'
},
project_activities: {
type: 'array',
items: {
type: 'number'
}
},
start_date: {
type: 'string',
format: 'date',
description: 'ISO 8601 date string for the project start date'
},
end_date: {
type: 'string',
format: 'date',
description: 'ISO 8601 date string for the project end date'
},
comments: {
type: 'string',
description: 'Comments'
},
completion_status: {
description: 'Status of the project being active/completed',
type: 'string'
},
publish_date: {
description: 'Status of the project being published/unpublished',
format: 'date',
type: 'string'
}
}
},
permit: {
type: 'object',
required: ['permits'],
properties: {
permits: {
type: 'array',
items: {
title: 'Project permit',
type: 'object',
properties: {
permit_number: {
type: 'string'
},
permit_type: {
type: 'string'
}
}
}
}
}
},
coordinator: {
title: 'Project coordinator',
type: 'object',
required: ['first_name', 'last_name', 'email_address', 'coordinator_agency', 'share_contact_details'],
properties: {
first_name: {
type: 'string'
},
last_name: {
type: 'string'
},
email_address: {
type: 'string'
},
coordinator_agency: {
type: 'string'
},
share_contact_details: {
type: 'string',
enum: ['true', 'false']
}
}
},
objectives: {
description: 'The project objectives and caveats',
type: 'object',
required: ['objectives', 'caveats'],
properties: {
objectives: {
type: 'string'
},
caveats: {
type: 'string'
}
}
},
location: {
description: 'The project location object',
type: 'object',
required: ['location_description', 'geometry'],
properties: {
location_description: {
type: 'string'
},
geometry: {
type: 'array',
items: {
...(geoJsonFeature as object)
}
}
}
},
iucn: {
description: 'The International Union for Conservation of Nature number',
type: 'object',
required: ['classificationDetails'],
properties: {
classificationDetails: {
type: 'array',
items: {
type: 'object',
properties: {
classification: {
type: 'string'
},
subClassification1: {
type: 'string'
},
subClassification2: {
type: 'string'
}
}
}
}
}
},
funding: {
description: 'The project funding details',
type: 'object',
required: ['fundingSources'],
properties: {
fundingSources: {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'number'
},
agency_id: {
type: 'number'
},
investment_action_category: {
type: 'number'
},
investment_action_category_name: {
type: 'string'
},
agency_name: {
type: 'string'
},
funding_amount: {
type: 'number'
},
start_date: {
type: 'string',
format: 'date',
description: 'ISO 8601 date string for the funding start date'
},
end_date: {
type: 'string',
format: 'date',
description: 'ISO 8601 date string for the funding end_date'
},
agency_project_id: {
type: 'string'
},
revision_count: {
type: 'number'
}
}
}
}
}
},
partnerships: {
description: 'The project partners',
type: 'object',
required: ['indigenous_partnerships', 'stakeholder_partnerships'],
properties: {
indigenous_partnerships: {
type: 'array',
items: {
type: 'string'
}
},
stakeholder_partnerships: {
type: 'array',
items: {
type: 'string'
}
}
}
}
}
}
}
}
Expand Down
Loading

0 comments on commit 22f0317

Please sign in to comment.