From f349a41885aac761c1fcc46cb1158304b4447963 Mon Sep 17 00:00:00 2001 From: CeciliaLiu8 Date: Wed, 27 Mar 2024 10:18:56 -0500 Subject: [PATCH 1/3] MAT-6824 highlight failed test cases --- src/services/export.service.spec.ts | 53 +++++++++++++++++++++++++++++ src/services/export.service.ts | 18 ++++++++++ 2 files changed, 71 insertions(+) diff --git a/src/services/export.service.spec.ts b/src/services/export.service.spec.ts index 87067c2..7abfc30 100644 --- a/src/services/export.service.spec.ts +++ b/src/services/export.service.spec.ts @@ -43,6 +43,40 @@ describe('ExcelService', () => { }, ], }, + { + populations: [ + { + name: 'initialPopulation', + expected: 2, + actual: 2, + }, + ], + notes: '', + last: 'testSeries2', + first: 'testTitle2', + birthdate: '11/12/1972', + expired: '', + deathdate: '', + ethnicity: 'Hispanic or Latino', + race: 'Other Race', + gender: 'Female', + definitions: [ + { + logic: 'define "Denominator":\n "Initial Population"', + actual: 'UNHIT', + }, + ], + functions: [ + { + logic: 'HospitalizationWithObservation', + actual: 'FUNCTION', + }, + { + logic: 'NormalizeInterval', + actual: 'FUNCTION', + }, + ], + }, ], }; beforeEach(() => { @@ -163,6 +197,25 @@ describe('ExcelService', () => { expect(worksheet.getCell(3, 12).value).toBe('UNHIT'); expect(worksheet.getCell(3, 13).value).toBe('FUNCTION'); expect(worksheet.getCell(3, 14).value).toBe('FUNCTION'); + //failed test test cases font color is red + expect(worksheet.getRow(3).font.color.argb).toBe('ff0000'); + + expect(worksheet.getCell(4, 1).value).toBe(2); + expect(worksheet.getCell(4, 2).value).toBe(2); + expect(worksheet.getCell(4, 3).value).toBe(''); + expect(worksheet.getCell(4, 4).value).toBe('testSeries2'); + expect(worksheet.getCell(4, 5).value).toBe('testTitle2'); + expect(worksheet.getCell(4, 6).value).toBe('11/12/1972'); + expect(worksheet.getCell(4, 7).value).toBe('FALSE'); + expect(worksheet.getCell(4, 8).value).toBe(''); + expect(worksheet.getCell(4, 9).value).toBe('Hispanic or Latino'); + expect(worksheet.getCell(4, 10).value).toBe('Other Race'); + expect(worksheet.getCell(4, 11).value).toBe('Female'); + expect(worksheet.getCell(4, 12).value).toBe('UNHIT'); + expect(worksheet.getCell(4, 13).value).toBe('FUNCTION'); + expect(worksheet.getCell(4, 14).value).toBe('FUNCTION'); + //success test test cases font color is not red (undefined) + expect(worksheet.getRow(4).font).toBe(undefined); }); it('test generateXlsx', async () => { diff --git a/src/services/export.service.ts b/src/services/export.service.ts index d0c2ce9..0679424 100644 --- a/src/services/export.service.ts +++ b/src/services/export.service.ts @@ -144,6 +144,9 @@ export class ExportService { let firstRow = []; let headerRow = []; const testCasesData = []; + //failed test cases will have red text font + const failedIndexes = []; + let index: number = 3; testCaseGroupDto.testCaseExecutionResults.forEach( (result: TestCaseExecutionResultDto) => { const firstRowData = []; @@ -151,6 +154,7 @@ export class ExportService { const testCaseData = []; const populations: PopulationDto[] = this.getPopulations(testCaseGroupDto); + populations?.forEach((population) => { firstRowData.push('Expected', 'Actual'); headerRowData.push(population.name, population.name); @@ -158,6 +162,8 @@ export class ExportService { testCaseData, result, population, + index, + failedIndexes, ); }); @@ -165,6 +171,7 @@ export class ExportService { testCasesData.push(testCaseData); firstRow = firstRowData; headerRow = headerRowData; + index += 1; }, ); this.populateFirstRow(worksheet, firstRow); @@ -178,6 +185,9 @@ export class ExportService { testCasesData.forEach((testCaseData) => { worksheet.addRow(testCaseData); }); + failedIndexes.forEach((index) => { + worksheet.getRow(index).font = { color: { argb: 'ff0000' } }; + }); this.adjustColumnWidth(worksheet); } @@ -197,6 +207,8 @@ export class ExportService { testCaseData, result: TestCaseExecutionResultDto, population: PopulationDto, + index: number, + failedIndexes: number[], ) { let foundPopulation: PopulationDto = null; result.populations?.forEach((currentPopulation) => { @@ -205,6 +217,12 @@ export class ExportService { } }); testCaseData.push(foundPopulation?.expected, foundPopulation?.actual); + if (foundPopulation?.expected !== foundPopulation?.actual) { + if (failedIndexes.indexOf(index) === -1) { + //if not in the array + failedIndexes.push(index); + } + } return foundPopulation; } From d7c2134b8322d5fcef82034e557e4331a030e279 Mon Sep 17 00:00:00 2001 From: CeciliaLiu8 Date: Wed, 27 Mar 2024 10:27:43 -0500 Subject: [PATCH 2/3] MAT-6824 improve test coverage --- src/auth/auth.guard.spec.ts | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/auth/auth.guard.spec.ts b/src/auth/auth.guard.spec.ts index 8d5f0cc..f6a8d55 100644 --- a/src/auth/auth.guard.spec.ts +++ b/src/auth/auth.guard.spec.ts @@ -130,4 +130,44 @@ describe('AuthGuard', () => { expect(e.message).toBe('Token not present'); } }); + + it('should throw UnauthorizedException without Authorization in header', async () => { + const mockExecutionContext = createMock(); + expect(mockExecutionContext.switchToHttp()).toBeDefined(); + + mockExecutionContext.switchToHttp = jest.fn().mockResolvedValue({ + getRequest: () => ({ + originalUrl: '/', + method: 'GET', + params: undefined, + query: undefined, + body: undefined, + }), + getResponse: () => ({ + statusCode: 200, + }), + }); + + jest + .spyOn(mockExecutionContext.switchToHttp(), 'getRequest') + .mockImplementation(() => { + return { + originalUrl: '/', + method: 'GET', + params: undefined, + query: undefined, + body: undefined, + headers: { + authorize: + 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.kcPmFlSUdC9LvuMufomQepInu3GwbBKKct49e2dxyrI', + }, + } as unknown as Request; + }); + + try { + await guard.canActivate(mockExecutionContext); + } catch (e) { + expect(e.message).toBe('Token not present'); + } + }); }); From 5fca7ec9b81ceb797454c3c94432a4cf617a46c7 Mon Sep 17 00:00:00 2001 From: CeciliaLiu8 Date: Fri, 29 Mar 2024 05:11:36 -0500 Subject: [PATCH 3/3] MAT-6824 update from develop --- package-lock.json | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4a9eecc..6bafc63 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3934,7 +3934,6 @@ "version": "0.6.0", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", - "dev": true, "engines": { "node": ">= 0.6" } @@ -4948,7 +4947,6 @@ "version": "4.19.2", "resolved": "https://registry.npmjs.org/express/-/express-4.19.2.tgz", "integrity": "sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==", - "dev": true, "dependencies": { "accepts": "~1.3.8", "array-flatten": "1.1.1", @@ -4990,7 +4988,6 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, "dependencies": { "ms": "2.0.0" } @@ -4998,14 +4995,12 @@ "node_modules/express/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, "node_modules/express/node_modules/path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==", - "dev": true + "integrity": "sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==" }, "node_modules/external-editor": { "version": "3.1.0",