From f740a298c725a6de55c4d82c57cc99bfa9d72444 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sun, 15 Jan 2023 12:20:40 +0100 Subject: [PATCH 1/2] Tests for removing undefined properties in readCorsOptions Signed-off-by: Dominik --- .../src/http/readCorsOptions.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/backend-app-api/src/http/readCorsOptions.test.ts b/packages/backend-app-api/src/http/readCorsOptions.test.ts index af490a26f9..6791835ac3 100644 --- a/packages/backend-app-api/src/http/readCorsOptions.test.ts +++ b/packages/backend-app-api/src/http/readCorsOptions.test.ts @@ -84,4 +84,42 @@ describe('readCorsOptions', () => { expect(cors).toEqual(expect.objectContaining({})); expect(cors?.origin).toBeUndefined(); }); + + it('get\'s undefined properties removed', () => { + const config = new ConfigReader({ + cors: { + methods: ['get'], + maxAge: 100, + }, + }); + const cors = readCorsOptions(config); + expect(cors?.hasOwnProperty('origin')).toBeFalsy(); + expect(cors?.hasOwnProperty('methods')).toBeTruthy(); + expect(cors?.hasOwnProperty('allowedHeaders')).toBeFalsy(); + expect(cors?.hasOwnProperty('exposedHeaders')).toBeFalsy(); + expect(cors?.hasOwnProperty('credentials')).toBeFalsy(); + expect(cors?.hasOwnProperty('maxAge')).toBeTruthy(); + expect(cors?.hasOwnProperty('preflightContinue')).toBeFalsy(); + expect(cors?.hasOwnProperty('optionsSuccessStatus')).toBeFalsy(); + }); + + it('does not have undefined optionsSuccessStatus', () => { + const config = new ConfigReader({ + cors: { + optionsSuccessStatus: undefined + }, + }); + const cors = readCorsOptions(config); + expect(cors?.hasOwnProperty('optionsSuccessStatus')).toBeFalsy(); + }); + + it('does have defined optionsSuccessStatus', () => { + const config = new ConfigReader({ + cors: { + optionsSuccessStatus: 200 + }, + }); + const cors = readCorsOptions(config); + expect(cors?.optionsSuccessStatus).toBe(200); + }); }); From 8da47815f2f59f581ff3831fbaa2034f9cbfef07 Mon Sep 17 00:00:00 2001 From: Dominik Date: Sun, 15 Jan 2023 12:54:02 +0100 Subject: [PATCH 2/2] prettier Signed-off-by: Dominik --- packages/backend-app-api/src/http/readCorsOptions.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend-app-api/src/http/readCorsOptions.test.ts b/packages/backend-app-api/src/http/readCorsOptions.test.ts index 6791835ac3..ebedab860c 100644 --- a/packages/backend-app-api/src/http/readCorsOptions.test.ts +++ b/packages/backend-app-api/src/http/readCorsOptions.test.ts @@ -85,7 +85,7 @@ describe('readCorsOptions', () => { expect(cors?.origin).toBeUndefined(); }); - it('get\'s undefined properties removed', () => { + it("get's undefined properties removed", () => { const config = new ConfigReader({ cors: { methods: ['get'], @@ -106,7 +106,7 @@ describe('readCorsOptions', () => { it('does not have undefined optionsSuccessStatus', () => { const config = new ConfigReader({ cors: { - optionsSuccessStatus: undefined + optionsSuccessStatus: undefined, }, }); const cors = readCorsOptions(config); @@ -116,7 +116,7 @@ describe('readCorsOptions', () => { it('does have defined optionsSuccessStatus', () => { const config = new ConfigReader({ cors: { - optionsSuccessStatus: 200 + optionsSuccessStatus: 200, }, }); const cors = readCorsOptions(config);