Skip to content

Commit

Permalink
#296: refactored service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
petermasking committed Oct 2, 2024
1 parent 6b34200 commit acce042
Show file tree
Hide file tree
Showing 56 changed files with 766 additions and 937 deletions.
35 changes: 35 additions & 0 deletions packages/execution/test/models/Application.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import { describe, expect, it } from 'vitest';

import { APPLICATIONS } from './fixtures';

const application = APPLICATIONS.GENERAL;

describe('models/Application', () =>
{
// TODO: Add classes tests

describe('.getProcedureNames()', () =>
{
it('should contain all public and protected procedure names', () =>
{
const procedureNames = application.getProcedureNames();

expect(procedureNames).toHaveLength(2);
expect(procedureNames).toContain('protected');
expect(procedureNames).toContain('public');
});
});

describe('.hasProcedure(name)', () =>
{
it('should have public procedures', () =>
{
const hasProtectedProcedure = application.hasProcedure('protected');
const hasPublicProcedure = application.hasProcedure('public');

expect(hasProtectedProcedure).toBeTruthy();
expect(hasPublicProcedure).toBeTruthy();
});
});
});
13 changes: 13 additions & 0 deletions packages/execution/test/models/fixtures/applications.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import Application from '../../../src/models/Application';

import { SEGMENTS } from './segments.fixture';

const generalApplication = new Application();
generalApplication.addSegment(SEGMENTS.GENERAL);
// TODO: Add more segments

export const APPLICATIONS =
{
GENERAL: generalApplication
};
1 change: 1 addition & 0 deletions packages/execution/test/models/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

export * from './applications.fixture';
export * from './executables.fixture';
export * from './implementations.fixture';
export * from './parameters.fixture';
Expand Down
2 changes: 1 addition & 1 deletion packages/logging/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class Logger
#debugEnabled: boolean;
#writer: Writer;

constructor(writer: Writer = console, debugEnabled: boolean = false)
constructor(debugEnabled: boolean = false, writer: Writer = console)
{
this.#debugEnabled = debugEnabled;
this.#writer = writer;
Expand Down
68 changes: 36 additions & 32 deletions packages/logging/test/Logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,27 @@ beforeEach(() =>
writer.clear();
});

const logger = new Logger(writer);

describe('Logger', () =>
{
describe('.debug(...messages))', () =>
describe('Message creation', () =>
{
it('should log messages when debug is enabled', () =>
{
const DebugLogger = new Logger(writer, true);
const logger = new Logger(false, writer);

DebugLogger.debug('message');
expect(writer.lastMessage).toEqual('[DEBUG] message');
});

it('should not log messages when debug is disabled', () =>
it('should log [CATEGORY] messages', () =>
{
logger.debug('message');
expect(writer.lastMessage).toEqual(undefined);
logger.info('info');
logger.warn('warn');
logger.error('error');
logger.fatal('fatal');

expect(writer.messages).toEqual([
'[INFO] info',
'[WARN] warn',
'[ERROR] error',
'[FATAL] fatal'
]);
});
});

it('log [CATEGORY] messages', () =>
{
logger.info('info');
logger.warn('warn');
logger.error('error');
logger.fatal('fatal');

expect(writer.messages).toEqual([
'[INFO] info',
'[WARN] warn',
'[ERROR] error',
'[FATAL] fatal'
]);
});

describe('.#createMessage()', () =>
{

it('should format string message', () =>
{
logger.info(INPUT.STRING);
Expand Down Expand Up @@ -123,4 +106,25 @@ describe('Logger', () =>
expect(writer.lastMessage).toEqual(OUTPUT.ERROR_WITH_STACKTRACE);
});
});

describe('Debug mode', () =>
{
it('should log messages when debug is enabled', () =>
{
const logger = new Logger(true, writer);

logger.debug('message');

expect(writer.lastMessage).toEqual('[DEBUG] message');
});

it('should not log messages when debug is disabled', () =>
{
const logger = new Logger(false, writer);

logger.debug('message');

expect(writer.lastMessage).toEqual(undefined);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { describe, expect, it } from 'vitest';

import { RUNTIMES } from '../_fixtures/services/Runtime.fixture';
import { RUNTIMES } from './_fixtures/services/Runtime.fixture';

const goodRuntime = RUNTIMES.GOOD;
const badRuntime = RUNTIMES.BAD;
Expand Down
75 changes: 0 additions & 75 deletions packages/runtime/test/_fixtures/interfaces/FileManager.fixture.ts

This file was deleted.

70 changes: 0 additions & 70 deletions packages/runtime/test/_fixtures/interfaces/HealthCheck.fixture.ts

This file was deleted.

55 changes: 0 additions & 55 deletions packages/runtime/test/_fixtures/interfaces/Middleware.fixture.ts

This file was deleted.

32 changes: 0 additions & 32 deletions packages/runtime/test/_fixtures/services/LocalGateway.fixture.ts

This file was deleted.

Loading

0 comments on commit acce042

Please sign in to comment.