Skip to content

Commit

Permalink
fix: use throw handling to test config immutableness
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenkapelian committed Nov 28, 2024
1 parent 7d5b336 commit 8508c24
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions tests/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="jest-extended" />
import { Interceptable, MockAgent, setGlobalDispatcher } from 'undici';
import { commonDbPartialV1, commonS3PartialV1 } from '@map-colonies/schemas';
import { StatusCodes } from 'http-status-codes';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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/);
});
});
});

0 comments on commit 8508c24

Please sign in to comment.