From 8508c24f7e6a244e66683143a0d11f8ce5b8993e Mon Sep 17 00:00:00 2001 From: ronenk1 Date: Thu, 28 Nov 2024 10:08:01 +0200 Subject: [PATCH] fix: use throw handling to test config immutableness --- tests/config.spec.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/tests/config.spec.ts b/tests/config.spec.ts index d51297b..bfb6f3a 100644 --- a/tests/config.spec.ts +++ b/tests/config.spec.ts @@ -1,4 +1,3 @@ -/// import { Interceptable, MockAgent, setGlobalDispatcher } from 'undici'; import { commonDbPartialV1, commonS3PartialV1 } from '@map-colonies/schemas'; import { StatusCodes } from 'http-status-codes'; @@ -304,7 +303,7 @@ describe('config', () => { await expect(promise).rejects.toThrow(); }); - it('should returned on getAll() a full frozen configuration object ', async () => { + it('should not allow to modify the root object', async () => { const configInstance = await config({ configName: 'name', version: 1, @@ -315,10 +314,13 @@ describe('config', () => { }); const conf = configInstance.getAll(); - expect(conf).toBeFrozen(); + const action = () => { + conf.host = 'dummmy.host.check'; + }; + expect(action).toThrow(/Cannot assign to read only property/); }); - it('should returned on get(`ssl`) a frozen sub configuration object ', async () => { + it('should not allow to modify the child object', async () => { const configInstance = await config({ configName: 'name', version: 1, @@ -329,7 +331,28 @@ describe('config', () => { }); const conf = configInstance.get('ssl'); - expect(conf).toBeFrozen(); + const action = () => { + conf.enabled = true; // try to change ssl configuration + }; + expect(action).toThrow(/Cannot assign to read only property/); + }); + + it('should not allow to modify the extracted child object from root', async () => { + const configInstance = await config({ + configName: 'name', + version: 1, + schema: commonDbPartialV1, + configServerUrl: URL, + localConfigPath: './tests/config', + offlineMode: true, + }); + + const conf = configInstance.getAll(); + const sslConf = conf.ssl; + const action = () => { + sslConf.enabled = true; + }; + expect(action).toThrow(/Cannot assign to read only property/); }); }); });