From 9b8787e92cc851253181754108cd93bd3df189af Mon Sep 17 00:00:00 2001 From: Bas Meeuwissen Date: Mon, 23 Dec 2024 20:34:00 +0100 Subject: [PATCH] #559: consistency check --- .../test/runtime/ConfigurationBuilder.spec.ts | 5 ++--- .../runtime/fixtures/filenames.fixture.ts | 2 +- .../runtime/fixtures/validation.fixture.ts | 2 +- .../test/server/ConfigurationBuilder.spec.ts | 2 +- .../test/server/fixtures/files.fixture.ts | 1 + .../server/fixtures/validation.fixture.ts | 6 +++--- .../test/utils/ConfigurationReader.spec.ts | 10 +++++----- .../utils/fixtures/configuration.fixture.ts | 20 +++++++++---------- .../test/utils/fixtures/files.fixture.ts | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/configuration/test/runtime/ConfigurationBuilder.spec.ts b/packages/configuration/test/runtime/ConfigurationBuilder.spec.ts index 04887e17..07ce6f9b 100644 --- a/packages/configuration/test/runtime/ConfigurationBuilder.spec.ts +++ b/packages/configuration/test/runtime/ConfigurationBuilder.spec.ts @@ -3,9 +3,8 @@ import { describe, expect, it } from 'vitest'; import { configurationBuilder, FILENAMES, CONFIGURATIONS, RuntimeConfigurationInvalid, VALIDATION_RESULT } from './fixtures'; -describe('ConfigurationBuilder', () => +describe('runtime/ConfigurationBuilder', () => { - it('should build a default runtime configuration without configuration file', async () => { const promise = configurationBuilder.build(); @@ -13,7 +12,7 @@ describe('ConfigurationBuilder', () => await expect(promise).resolves.toEqual(CONFIGURATIONS.DEFAULT); }); - it('should build a valid runtime configuration', async () => + it('should build a valid runtime configuration from a valid file', async () => { const promise = configurationBuilder.build(FILENAMES.VALID); diff --git a/packages/configuration/test/runtime/fixtures/filenames.fixture.ts b/packages/configuration/test/runtime/fixtures/filenames.fixture.ts index e9773901..1f1bd925 100644 --- a/packages/configuration/test/runtime/fixtures/filenames.fixture.ts +++ b/packages/configuration/test/runtime/fixtures/filenames.fixture.ts @@ -4,4 +4,4 @@ export const FILENAMES = { VALID: 'valid-runtime-configuration.json', INVALID: 'invalid-runtime-configuration.json', MISSING: 'missing-runtime-configuration.json', -}; +} as const; diff --git a/packages/configuration/test/runtime/fixtures/validation.fixture.ts b/packages/configuration/test/runtime/fixtures/validation.fixture.ts index d9b2f545..6b53931c 100644 --- a/packages/configuration/test/runtime/fixtures/validation.fixture.ts +++ b/packages/configuration/test/runtime/fixtures/validation.fixture.ts @@ -6,7 +6,7 @@ const VALIDATION_RESULT: ValidationResult = valid: false, errors: [ "Unknown field 'invalid'", - ], + ] } as const; export { VALIDATION_RESULT }; diff --git a/packages/configuration/test/server/ConfigurationBuilder.spec.ts b/packages/configuration/test/server/ConfigurationBuilder.spec.ts index 21bc85d2..396d87b9 100644 --- a/packages/configuration/test/server/ConfigurationBuilder.spec.ts +++ b/packages/configuration/test/server/ConfigurationBuilder.spec.ts @@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'; import { configurationBuilder, FILENAMES, SERVER_CONFIGURATION, ServerConfigurationInvalid, VALIDATION_RESULT } from './fixtures'; -describe('ConfigurationBuilder', () => +describe('server/ConfigurationBuilder', () => { it('should build a valid server configuration', async () => { diff --git a/packages/configuration/test/server/fixtures/files.fixture.ts b/packages/configuration/test/server/fixtures/files.fixture.ts index c1b787ba..68f5297a 100644 --- a/packages/configuration/test/server/fixtures/files.fixture.ts +++ b/packages/configuration/test/server/fixtures/files.fixture.ts @@ -7,4 +7,5 @@ import { FILENAMES } from './filenames.fixture'; export const FILES: Record = { VALID_CONFIGURATION: new File(FILENAMES.VALID_CONFIGURATION, 'text/json', JSON.stringify(SERVER_CONFIGURATION)), + INVALID_CONFIGURATION: new File(FILENAMES.INVALID_CONFIGURATION, 'text/json', JSON.stringify({})), } as const; diff --git a/packages/configuration/test/server/fixtures/validation.fixture.ts b/packages/configuration/test/server/fixtures/validation.fixture.ts index ed89fe05..58a6c5b7 100644 --- a/packages/configuration/test/server/fixtures/validation.fixture.ts +++ b/packages/configuration/test/server/fixtures/validation.fixture.ts @@ -1,12 +1,12 @@ import { ValidationResult } from "@jitar/validation"; -const VALIDATION_RESULT = +const VALIDATION_RESULT: ValidationResult = { valid: false, errors: [ "Field 'url' is required", - ], -} as ValidationResult; + ] +} as const; export { VALIDATION_RESULT }; diff --git a/packages/configuration/test/utils/ConfigurationReader.spec.ts b/packages/configuration/test/utils/ConfigurationReader.spec.ts index b6d385db..62e21310 100644 --- a/packages/configuration/test/utils/ConfigurationReader.spec.ts +++ b/packages/configuration/test/utils/ConfigurationReader.spec.ts @@ -5,27 +5,27 @@ import { reader, FILENAMES, CONFIGURATIONS, InvalidConfigurationFile } from "./f describe('ConfigurationReader', () => { - it('should return default configuration for non-existing config file', async () => + it('should return an empty configuration for non-existing config file', async () => { const configuration = await reader.read(FILENAMES.NON_EXISTING); - expect(configuration).toEqual(CONFIGURATIONS.default); + expect(configuration).toEqual(CONFIGURATIONS.EMPTY); }); it('should read json configuration', async () => { const configuration = await reader.read(FILENAMES.CORRECT_TYPE); - expect(configuration).toEqual(CONFIGURATIONS.result); + expect(configuration).toEqual(CONFIGURATIONS.RESULT); }); it('should read json configuration with environment variables', async () => { - vi.stubEnv(CONFIGURATIONS.envVariables.TARGET_PATH_ENV_UTIL_KEY, CONFIGURATIONS.envVariables.TARGET_PATH_ENV_UTIL_VALUE); + vi.stubEnv(CONFIGURATIONS.ENV_VARIABLES.TARGET_PATH_ENV_UTIL_KEY, CONFIGURATIONS.ENV_VARIABLES.TARGET_PATH_ENV_UTIL_VALUE); const configuration = await reader.read(FILENAMES.ENV_VARIABLES); - expect(configuration).toEqual(CONFIGURATIONS.envResult); + expect(configuration).toEqual(CONFIGURATIONS.ENV_RESULT); vi.unstubAllEnvs(); }); diff --git a/packages/configuration/test/utils/fixtures/configuration.fixture.ts b/packages/configuration/test/utils/fixtures/configuration.fixture.ts index 28aebdb3..6be017f6 100644 --- a/packages/configuration/test/utils/fixtures/configuration.fixture.ts +++ b/packages/configuration/test/utils/fixtures/configuration.fixture.ts @@ -1,25 +1,25 @@ -const resultConfiguration = +const resultConfiguration: Record = { source: null, target: './jitar' } as const; -const envConfiguration = +const envConfiguration: Record = { source: '${SOURCE_PATH_ENV_UTIL}', target: '${TARGET_PATH_ENV_UTIL}' } as const; -const envResultConfiguration = +const envResultConfiguration: Record = { source: 'null', target: './jitar' } as const; -const defaultConfiguration = {} as const; +const emptyConfiguration: Record = {} as const; -const envVariables = +const envVariables: Record = { TARGET_PATH_ENV_UTIL_KEY: 'TARGET_PATH_ENV_UTIL', TARGET_PATH_ENV_UTIL_VALUE: './jitar' @@ -27,9 +27,9 @@ const envVariables = export const CONFIGURATIONS: Record = { - result: resultConfiguration, - env: envConfiguration, - envResult: envResultConfiguration, - default: defaultConfiguration, - envVariables + EMPTY: emptyConfiguration, + RESULT: resultConfiguration, + ENV: envConfiguration, + ENV_RESULT: envResultConfiguration, + ENV_VARIABLES: envVariables } as const; diff --git a/packages/configuration/test/utils/fixtures/files.fixture.ts b/packages/configuration/test/utils/fixtures/files.fixture.ts index 804ca3ed..348e6cd6 100644 --- a/packages/configuration/test/utils/fixtures/files.fixture.ts +++ b/packages/configuration/test/utils/fixtures/files.fixture.ts @@ -6,7 +6,7 @@ import { CONFIGURATIONS } from './configuration.fixture'; export const FILES: Record = { - CORRECT_TYPE: new File(FILENAMES.CORRECT_TYPE, 'text/json', JSON.stringify(CONFIGURATIONS.result)), + CORRECT_TYPE: new File(FILENAMES.CORRECT_TYPE, 'text/json', JSON.stringify(CONFIGURATIONS.RESULT)), INCORRECT_TYPE: new File(FILENAMES.INCORRECT_TYPE, 'text/plain', 'source: null\ntarget: .jitar'), - ENV_VARIABLES: new File(FILENAMES.ENV_VARIABLES, 'text/json', JSON.stringify(CONFIGURATIONS.env)) + ENV_VARIABLES: new File(FILENAMES.ENV_VARIABLES, 'text/json', JSON.stringify(CONFIGURATIONS.ENV)) } as const;