Skip to content

Commit

Permalink
[HOTFIX][NRPTI-1264] Update assessment sub types (#1265)
Browse files Browse the repository at this point in the history
* Update assessment sub types, fix tests

* Temporarily remove NRIS_ATTACHMENT_DATE
  • Loading branch information
sggerard authored Jul 30, 2024
1 parent 20958e3 commit 42f8772
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
2 changes: 1 addition & 1 deletion api/src/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ const executeQuery = async function (args, res, next) {
let _in = args.swagger.params._in ? args.swagger.params._in.value : '';
let subset = args.swagger.params.subset ? args.swagger.params.subset.value : null;

let roles = args.swagger.params.auth_payload ? args.swagger.params.auth_payload.client_roles : ['public'];
let roles = args.swagger.params.auth_payload && args.swagger.params.auth_payload.client_roles ? args.swagger.params.auth_payload.client_roles : ['public'];

if(!roles.includes('public')){
roles.push('public');
Expand Down
15 changes: 2 additions & 13 deletions api/src/integrations/nris-emli/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const NRIS_EMLI_API_ENDPOINT =
process.env.NRIS_EMLI_API_ENDPOINT || 'https://api.nrs.gov.bc.ca/nrisws-api/v1/emprInspections';
const NRIS_username = process.env.NRIS_username || null;
const NRIS_password = process.env.NRIS_password || null;
const NRIS_ATTACHMENT_DATE = process.env.NRIS_ATTACHMENT_DATE || '2024-06-01';
const RETRY_LIMIT = 10;

class NrisDataSource {
Expand Down Expand Up @@ -211,9 +210,7 @@ class NrisDataSource {

if (record.inspection.inspectionSubType !== 'Mine Inspection') return false;

if (record.assessmentSubType !== 'Compliance Review' && record.assessmentSubType !== 'Inspection') return false;

if (record.inspection.inspectionType[0] === 'Audit') return false;
if (record.assessmentSubType !== 'Inspection - Desktop' && record.assessmentSubType !== 'Inspection - Site Visit') return false;

return true;
}
Expand Down Expand Up @@ -312,15 +309,7 @@ class NrisDataSource {

isAttachmentAllowed(attachment){
//Allow final reports
if (attachment.fileType === 'Final Report') {
return true;
}
//Allow inspection reports if they were created after a specific date (June 1st)
if (attachment.fileType === 'Report') {
return attachment.attachmentComment.toLowerCase() === "inspection report"
&& attachment.attachmentDate != null && moment(attachment.attachmentDate).isAfter(NRIS_ATTACHMENT_DATE);
}
return false;
return attachment.fileType === 'Final Report' && attachment.attachmentMediaType === 'application/pdf'
}

// Grabs a file from NRIS datasource
Expand Down
26 changes: 13 additions & 13 deletions api/src/integrations/nris-emli/datasource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('NrisDataSource', () => {

for (const assessmentSubStatus of assessmentSubStatusList) {
const record = {
assessmentSubType: 'Inspection',
assessmentSubType: 'Inspection - Site Visit',
assessmentSubStatus: assessmentSubStatus,
inspection: {
inspectionType: ['Health and Safety'],
Expand All @@ -236,7 +236,7 @@ describe('NrisDataSource', () => {

for (const assessmentSubStatus of assessmentSubStatusList) {
const record = {
assessmentSubType: 'Inspection',
assessmentSubType: 'Inspection - Site Visit',
assessmentSubStatus: assessmentSubStatus,
inspection: {
inspectionType: ['Health and Safety'],
Expand All @@ -256,7 +256,7 @@ describe('NrisDataSource', () => {
const dataSource = new NrisDataSource();

const record = {
assessmentSubType: 'Inspection',
assessmentSubType: 'Inspection - Site Visit',
assessmentSubStatus: 'Closed',
inspection: {
inspectionType: ['Health and Safety'],
Expand All @@ -275,7 +275,7 @@ describe('NrisDataSource', () => {
const dataSource = new NrisDataSource();

const record = {
assessmentSubType: 'Inspection',
assessmentSubType: 'Inspection - Site Visit',
assessmentSubStatus: 'Closed',
inspection: {
inspectionType: ['Audit'],
Expand All @@ -294,7 +294,7 @@ describe('NrisDataSource', () => {
const dataSource = new NrisDataSource();

const record = {
assessmentSubType: 'Inspection',
assessmentSubType: 'Inspection - Site Visit',
assessmentSubStatus: 'Closed',
inspection: {
inspectionType: ['Health and Safety'],
Expand All @@ -309,10 +309,10 @@ describe('NrisDataSource', () => {
expect(result).toEqual(false);
});

it('should process Compliance Review OR Inspection assessmentSubType record', async () => {
it('should process Compliance Review OR Inspection assessmentSubType records', async () => {
const dataSource = new NrisDataSource();

const assessmentSubTypeList = ['Compliance Review', 'Inspection'];
const assessmentSubTypeList = ['Compliance Review', 'Inspection - Site Visit', 'Inspection - Desktop'];

for (const assessmentSubType of assessmentSubTypeList) {
const record = {
Expand Down Expand Up @@ -472,20 +472,20 @@ describe('NrisDataSource', () => {
attachment: [
{ attachmentId: 'attachmentId1', fileType: 'Other' },
{ attachmentId: 'attachmentId2', fileType: 'Final Report' },
{ attachmentId: 'attachmentId3', fileType: 'Report', attachmentComment: 'Inspection Report'},
{ attachmentId: 'attachmentId3', fileType: 'Report', attachmentComment: 'Inspection Report', attachmentDate: "2020-01-10 11:50"},
{ attachmentId: 'attachmentId4', fileType: 'Report', attachmentComment: 'Inspection Report', attachmentDate: "2024-06-06" },
//{ attachmentId: 'attachmentId3', fileType: 'Report', attachmentComment: 'Inspection Report'},
//{ attachmentId: 'attachmentId3', fileType: 'Report', attachmentComment: 'Inspection Report', attachmentDate: "2020-01-10 11:50"},
//{ attachmentId: 'attachmentId4', fileType: 'Report', attachmentComment: 'Inspection Report', attachmentDate: "2024-06-06" },
],
};

const newRecord = {};
await dataSource.createRecordAttachments(record, newRecord);

expect(dataSource.getFileFromNRIS).toHaveBeenCalledTimes(2);
expect(dataSource.getFileFromNRIS).toHaveBeenCalledTimes(1);
expect(dataSource.getFileFromNRIS).toHaveBeenCalledWith('sampleAssessmentId', 'attachmentId2');
expect(dataSource.getFileFromNRIS).toHaveBeenCalledWith('sampleAssessmentId', 'attachmentId4');
//expect(dataSource.getFileFromNRIS).toHaveBeenCalledWith('sampleAssessmentId', 'attachmentId4');

expect(dataSource.putFileS3).toHaveBeenCalledTimes(2);
expect(dataSource.putFileS3).toHaveBeenCalledTimes(1);
});
});

Expand Down

0 comments on commit 42f8772

Please sign in to comment.