From 67481d5c9289ac6c20c322bcc4795c9babf6d454 Mon Sep 17 00:00:00 2001 From: CeciliaLiu8 Date: Fri, 12 Apr 2024 10:54:39 -0500 Subject: [PATCH] MAT-6819 optimize code --- src/auth/auth.guard.spec.ts | 4 ++-- src/services/export.service.ts | 20 ++++++-------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/auth/auth.guard.spec.ts b/src/auth/auth.guard.spec.ts index 55bb9bd..62cdd70 100644 --- a/src/auth/auth.guard.spec.ts +++ b/src/auth/auth.guard.spec.ts @@ -42,7 +42,7 @@ describe('AuthGuard', () => { verifyAccessToken: () => ({ oktaToken: { claims: { - sub: 'aUser@company.com', + sub: 'a_user@acompany.com', }, }, }), @@ -60,7 +60,7 @@ describe('AuthGuard', () => { body: undefined, headers: { authorization: - 'Bearer eyJraWQiOiJNNG9CMW9DSmthdC0tYTNENFFXUFA3RWZCbUl3NG9BV05KYWJxdEJhUnM4IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULmRQdFdGMndrYlN5VjJxVW1BanQ0dXBERklwOExMT2poRFl4MWxzYWJkaWciLCJpc3MiOiJodHRwczovL2Rldi0xODA5MjU3OC5va3RhLmNvbS9vYXV0aDIvZGVmYXVsdCIsImF1ZCI6ImFwaTovL2RlZmF1bHQiLCJpYXQiOjE3MTI5MjYyNTIsImV4cCI6MTcxMjkyOTg1MiwiY2lkIjoiMG9hMmZxdGF6OTVmcUpxYmY1ZDciLCJ1aWQiOiIwMHUzaTNjM3p6WlhLcjkwMTVkNyIsInNjcCI6WyJwcm9maWxlIiwib3BlbmlkIl0sImF1dGhfdGltZSI6MTcxMjkyNjI1MSwic3ViIjoiY2VjaWxpYS5saXVAc2VtYW50aWNiaXRzLmNvbSJ9.bdZh7ygtJKvausHo58VGPLonPeWPAGXDFXHDY445ERxwCpNSiy-VdfZF3TZfg_s9k-XAwRGcd-T7lcy4dW9Qh6L74bdDucYX_TSR8WreLvS3W4o-uyRi0HQU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', }, } as unknown as Request; }); diff --git a/src/services/export.service.ts b/src/services/export.service.ts index 952c34f..b96c3a7 100644 --- a/src/services/export.service.ts +++ b/src/services/export.service.ts @@ -245,25 +245,17 @@ export class ExportService { populationDto: PopulationDto, result, ) { - let foundPopulation: PopulationDto = null; - result.populations?.forEach((currentPopulation) => { - if (currentPopulation.name === populationDto.name) { - foundPopulation = currentPopulation; - } - }); + const foundPopulation: PopulationDto = result.populations?.find( + (currentPopulation) => currentPopulation.name === populationDto.name, + ); testCaseData.push(foundPopulation?.actual); } private getPopulations = (testCaseExcelExportDto: TestCaseExcelExportDto) => { - let populations: PopulationDto[] = []; - testCaseExcelExportDto.testCaseExecutionResults?.forEach( - (result: TestCaseExecutionResultDto) => { - if (result.populations?.length > 0) { - populations = result.populations; - } - }, + const result = testCaseExcelExportDto.testCaseExecutionResults?.find( + (result) => result.populations?.length > 0, ); - return populations; + return result ? result.populations : []; }; private populateFirstRow(worksheet, firstRowData) {