Merge pull request #15757 from dpfaffenbauer/patch-3

Tests for removing undefined properties in readCorsOptions
This commit is contained in:
Patrik Oldsberg
2023-01-16 09:32:19 +01:00
committed by GitHub
@@ -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);
});
});