From 37b59cc57df1f3ee6c291c4f51aa81b5f0e64829 Mon Sep 17 00:00:00 2001 From: jer3k <99355997+jer3k@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:33:10 -0700 Subject: [PATCH 1/3] fix: integration timeout (#438) --- backend-external/tests/integration/integration.spec.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend-external/tests/integration/integration.spec.ts b/backend-external/tests/integration/integration.spec.ts index 5990ba5a2..ef22cbe91 100644 --- a/backend-external/tests/integration/integration.spec.ts +++ b/backend-external/tests/integration/integration.spec.ts @@ -5,24 +5,25 @@ 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', () => { @@ -30,6 +31,7 @@ describe('/v1/pay-transparency/ GET', () => { return request .get('/v1/pay-transparency') .set('x-api-key', config.get('server:apiKey')) + .retry(3) .expect(200) .expect(({ body }) => { expect(body).toHaveProperty('totalRecords'); From ff781b9d0fdc5610fef2bffcc207aa5c3062ef12 Mon Sep 17 00:00:00 2001 From: Goeme Nthomiwa Date: Thu, 25 Apr 2024 15:29:29 -0700 Subject: [PATCH 2/3] feat: changing the shape of the output of the external api (#439) --- .../src/v1/routes/pay-transparency-routes.ts | 6 -- .../routes/external-consumer-routes.spec.ts | 1 - .../external-consumer-service.spec.ts | 83 ++++++++++--------- .../v1/services/external-consumer-service.ts | 39 ++++++--- 4 files changed, 69 insertions(+), 60 deletions(-) diff --git a/backend-external/src/v1/routes/pay-transparency-routes.ts b/backend-external/src/v1/routes/pay-transparency-routes.ts index 302b35311..0756c1842 100644 --- a/backend-external/src/v1/routes/pay-transparency-routes.ts +++ b/backend-external/src/v1/routes/pay-transparency-routes.ts @@ -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 diff --git a/backend/src/v1/routes/external-consumer-routes.spec.ts b/backend/src/v1/routes/external-consumer-routes.spec.ts index 051196f67..90c6fe252 100644 --- a/backend/src/v1/routes/external-consumer-routes.spec.ts +++ b/backend/src/v1/routes/external-consumer-routes.spec.ts @@ -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, diff --git a/backend/src/v1/services/external-consumer-service.spec.ts b/backend/src/v1/services/external-consumer-service.spec.ts index 9cdf46f8f..19357c0a0 100644 --- a/backend/src/v1/services/external-consumer-service.spec.ts +++ b/backend/src/v1/services/external-consumer-service.spec.ts @@ -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, }); }); diff --git a/backend/src/v1/services/external-consumer-service.ts b/backend/src/v1/services/external-consumer-service.ts index 0450c6a37..0b3b459e9 100644 --- a/backend/src/v1/services/external-consumer-service.ts +++ b/backend/src/v1/services/external-consumer-service.ts @@ -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) => { @@ -25,6 +26,7 @@ const denormalizeReport = ( calculation_code: any; }[], ) => { + return { ...pick(report, [ 'report_id', @@ -143,6 +145,12 @@ const externalConsumerService = { }, pay_transparency_company: true, }, + where: { + create_date: { + gte: convert(startDt).toDate(), + lte: convert(endDt).toDate(), + }, + }, }, }, skip: offset, @@ -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, - ); - }), - }; - }), + ), + }; + }), + ], }; }, }; From 1cb3ef36b32e663c0674d1ba07c068a83b0f3e2f Mon Sep 17 00:00:00 2001 From: jer3k <99355997+jer3k@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:37:59 -0700 Subject: [PATCH 3/3] fix integration timeouts --- backend-external/tests/integration/integration.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend-external/tests/integration/integration.spec.ts b/backend-external/tests/integration/integration.spec.ts index ef22cbe91..924e629aa 100644 --- a/backend-external/tests/integration/integration.spec.ts +++ b/backend-external/tests/integration/integration.spec.ts @@ -29,7 +29,7 @@ describe('/v1/pay-transparency/ GET', () => { 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') + .get('/v1/pay-transparency?pageSize=1') .set('x-api-key', config.get('server:apiKey')) .retry(3) .expect(200)