Skip to content

Commit

Permalink
Merge branch 'bugfix/fix-integration-timeout-pt2' of https://github.c…
Browse files Browse the repository at this point in the history
…om/bcgov/fin-pay-transparency into bugfix/fix-integration-timeout-pt2
  • Loading branch information
jer3k committed Apr 25, 2024
2 parents 0c2a83d + 1cb3ef3 commit 2ce9327
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 63 deletions.
6 changes: 0 additions & 6 deletions backend-external/src/v1/routes/pay-transparency-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ const router = express.Router();
* Report:
* allOf:
* - $ref: "#/components/schemas/ReportItem"
* - type: object
* properties:
* history:
* type: array
* items:
* $ref: "#/components/schemas/ReportItem"
*
* PaginatedReports:
* type: object
Expand Down
8 changes: 5 additions & 3 deletions backend-external/tests/integration/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@ const request = agent(config.get('server:baseURL'));

describe('/ GET', () => {
it('the service should be running', () => {
return request.get('').expect(200);
return request.get('').retry(3).expect(200);
});
});

describe('/v1/docs/ GET', () => {
it('the service should be running', () => {
return request.get('/v1/docs/').expect(200);
return request.get('/v1/docs/').retry(3).expect(200);
});
});

describe('/v1/pay-transparency/ GET', () => {
it('returns error if secret key is not set', () => {
return request.get('/v1/pay-transparency').expect(400);
return request.get('/v1/pay-transparency').retry(3).expect(400);
});
it('returns error if secret key is wrong', () => {
return request
.get('/v1/pay-transparency')
.set('x-api-key', 'wrong_key')
.retry(3)
.expect(401);
});
it('returns data if secret key is provided', () => {
//note: this test requires both backend-external and backend to be running.
return request
.get('/v1/pay-transparency?pageSize=1')
.set('x-api-key', config.get('server:apiKey'))
.retry(3)
.expect(200)
.expect(({ body }) => {
expect(body).toHaveProperty('totalRecords');
Expand Down
1 change: 0 additions & 1 deletion backend/src/v1/routes/external-consumer-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ describe('external-consumer-routes', () => {
revision: REPORT.revision,
update_date: REPORT.update_date.toISOString(),
user_comment: REPORT.user_comment,
history: [],
},
],
totalRecords: 1,
Expand Down
83 changes: 43 additions & 40 deletions backend/src/v1/services/external-consumer-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,49 +143,52 @@ describe('external-consumer-service', () => {
revision: testData.revision,
update_date: testData.update_date,
user_comment: testData.user_comment,
history: [
});

expect(results.records[1]).toStrictEqual({
calculated_data: [
{
calculated_data: [
{
is_suppressed:
testData.report_history[0].calculated_data_history[0].is_suppressed,
value: testData.report_history[0].calculated_data_history[0].value,
calculation_code:
testData.report_history[0].calculated_data_history[0].calculation_code
.calculation_code,
},
],
company_address_line1:
testData.report_history[0].pay_transparency_company.address_line1,
company_address_line2:
testData.report_history[0].pay_transparency_company.address_line2,
company_bceid_business_guid:
testData.report_history[0].pay_transparency_company.bceid_business_guid,
company_city: testData.report_history[0].pay_transparency_company.city,
company_country: testData.report_history[0].pay_transparency_company.country,
company_id: testData.report_history[0].company_id,
company_name: testData.report_history[0].pay_transparency_company.company_name,
company_postal_code: testData.report_history[0].pay_transparency_company.postal_code,
company_province: testData.report_history[0].pay_transparency_company.province,
create_date: testData.report_history[0].create_date,
data_constraints: testData.report_history[0].data_constraints,
employee_count_range:
testData.report_history[0].employee_count_range.employee_count_range,
naics_code:
testData.report_history[0].naics_code_report_history_naics_codeTonaics_code
.naics_code,
naics_code_label:
testData.report_history[0].naics_code_report_history_naics_codeTonaics_code
.naics_label,
report_end_date: testData.report_history[0].report_end_date,
report_id: testData.report_history[0].report_id,
report_start_date: testData.report_history[0].report_start_date,
report_status: testData.report_history[0].report_status,
revision: testData.report_history[0].revision,
update_date: testData.report_history[0].update_date,
user_comment: testData.report_history[0].user_comment,
is_suppressed:
testData.report_history[0].calculated_data_history[0].is_suppressed,
value: testData.report_history[0].calculated_data_history[0].value,
calculation_code:
testData.report_history[0].calculated_data_history[0]
.calculation_code.calculation_code,
},
],
company_address_line1:
testData.report_history[0].pay_transparency_company.address_line1,
company_address_line2:
testData.report_history[0].pay_transparency_company.address_line2,
company_bceid_business_guid:
testData.report_history[0].pay_transparency_company.bceid_business_guid,
company_city: testData.report_history[0].pay_transparency_company.city,
company_country:
testData.report_history[0].pay_transparency_company.country,
company_id: testData.report_history[0].company_id,
company_name:
testData.report_history[0].pay_transparency_company.company_name,
company_postal_code:
testData.report_history[0].pay_transparency_company.postal_code,
company_province:
testData.report_history[0].pay_transparency_company.province,
create_date: testData.report_history[0].create_date,
data_constraints: testData.report_history[0].data_constraints,
employee_count_range:
testData.report_history[0].employee_count_range.employee_count_range,
naics_code:
testData.report_history[0]
.naics_code_report_history_naics_codeTonaics_code.naics_code,
naics_code_label:
testData.report_history[0]
.naics_code_report_history_naics_codeTonaics_code.naics_label,
report_end_date: testData.report_history[0].report_end_date,
report_id: testData.report_history[0].report_id,
report_start_date: testData.report_history[0].report_start_date,
report_status: testData.report_history[0].report_status,
revision: testData.report_history[0].revision,
update_date: testData.report_history[0].update_date,
user_comment: testData.report_history[0].user_comment,
});
});

Expand Down
39 changes: 26 additions & 13 deletions backend/src/v1/services/external-consumer-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import prismaReadOnlyReplica from '../prisma/prisma-client-readonly-replica';
import { LocalDate, convert } from '@js-joda/core';
import pick from 'lodash/pick';
import flatten from 'lodash/flatten';
import { PayTransparencyUserError } from './file-upload-service';

const denormalizeCompany = (company) => {
Expand All @@ -25,6 +26,7 @@ const denormalizeReport = (
calculation_code: any;
}[],
) => {

return {
...pick(report, [
'report_id',
Expand Down Expand Up @@ -143,6 +145,12 @@ const externalConsumerService = {
},
pay_transparency_company: true,
},
where: {
create_date: {
gte: convert(startDt).toDate(),
lte: convert(endDt).toDate(),
},
},
},
},
skip: offset,
Expand All @@ -153,22 +161,27 @@ const externalConsumerService = {
totalRecords: totalCount,
page: offset,
pageSize: limit,
records: results.map((report) => {
return {
...denormalizeReport(
report,
(r) => r.naics_code_pay_transparency_report_naics_codeTonaics_code,
(r) => r.pay_transparency_calculated_data,
),
history: report.report_history.map((report) => {
return denormalizeReport(
records: [
...results.map((report) => {
return {
...denormalizeReport(
report,
(r) =>
r.naics_code_pay_transparency_report_naics_codeTonaics_code,
(r) => r.pay_transparency_calculated_data,
),
};
}),
...flatten(results.map((r) => r.report_history)).map((report) => {
return {
...denormalizeReport(
report,
(r) => r.naics_code_report_history_naics_codeTonaics_code,
(r) => r.calculated_data_history,
);
}),
};
}),
),
};
}),
],
};
},
};
Expand Down

0 comments on commit 2ce9327

Please sign in to comment.