Skip to content

Commit

Permalink
#559: consistency check
Browse files Browse the repository at this point in the history
  • Loading branch information
basmasking committed Dec 23, 2024
1 parent 2b206ac commit 9b8787e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ 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();

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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export const FILENAMES = {
VALID: 'valid-runtime-configuration.json',
INVALID: 'invalid-runtime-configuration.json',
MISSING: 'missing-runtime-configuration.json',
};
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const VALIDATION_RESULT: ValidationResult =
valid: false,
errors: [
"Unknown field 'invalid'",
],
]
} as const;

export { VALIDATION_RESULT };
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import { FILENAMES } from './filenames.fixture';
export const FILES: Record<string, File> =
{
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;
Original file line number Diff line number Diff line change
@@ -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 };
10 changes: 5 additions & 5 deletions packages/configuration/test/utils/ConfigurationReader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
20 changes: 10 additions & 10 deletions packages/configuration/test/utils/fixtures/configuration.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@

const resultConfiguration =
const resultConfiguration: Record<string, string | null> =
{
source: null,
target: './jitar'
} as const;

const envConfiguration =
const envConfiguration: Record<string, string | null> =
{
source: '${SOURCE_PATH_ENV_UTIL}',
target: '${TARGET_PATH_ENV_UTIL}'
} as const;

const envResultConfiguration =
const envResultConfiguration: Record<string, string | null> =
{
source: 'null',
target: './jitar'
} as const;

const defaultConfiguration = {} as const;
const emptyConfiguration: Record<string, string | null> = {} as const;

const envVariables =
const envVariables: Record<string, string | null> =
{
TARGET_PATH_ENV_UTIL_KEY: 'TARGET_PATH_ENV_UTIL',
TARGET_PATH_ENV_UTIL_VALUE: './jitar'
} as const;

export const CONFIGURATIONS: Record<string, any> =
{
result: resultConfiguration,
env: envConfiguration,
envResult: envResultConfiguration,
default: defaultConfiguration,
envVariables
EMPTY: emptyConfiguration,
RESULT: resultConfiguration,
ENV: envConfiguration,
ENV_RESULT: envResultConfiguration,
ENV_VARIABLES: envVariables
} as const;
4 changes: 2 additions & 2 deletions packages/configuration/test/utils/fixtures/files.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CONFIGURATIONS } from './configuration.fixture';

export const FILES: Record<string, File> =
{
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;

0 comments on commit 9b8787e

Please sign in to comment.