Skip to content

Commit

Permalink
Merge pull request #31 from osher-sade/master
Browse files Browse the repository at this point in the history
Added tests
  • Loading branch information
osher-sade authored Feb 7, 2019
2 parents 1c2428a + 7f771f5 commit fc51d06
Show file tree
Hide file tree
Showing 6 changed files with 381 additions and 18 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
clearMocks : true,
moduleFileExtensions: [
"ts",
"js",
Expand Down
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/type-declarations/winston-logstash-transport.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
declare module 'winston-logstash-transport' {
import * as Transport from 'winston-transport';
import {TransportStreamOptions} from 'winston-transport';

interface logstashTransportOptions extends TransportStreamOptions {
interface LogstashTransportOptions extends Transport.TransportStreamOptions {
host?: string,
port?: number,
trailingLineFeed?: boolean,
trailingLineFeedChar?: string
}

export class LogstashTransport extends Transport{
constructor({}: logstashTransportOptions)
export class LogstashTransport extends Transport {
constructor({}: LogstashTransportOptions)
}
}
3 changes: 0 additions & 3 deletions test/foo.test.ts

This file was deleted.

121 changes: 121 additions & 0 deletions test/polaris-logger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { Logger } from 'winston';
import { LoggerConfiguration } from '../src/configurations/logger-configuration';
import { ApplicationLogProperties } from '../src/entities';
import { PolarisLogger } from '../src/polaris-logger';
import { createLogger } from '../src/winston-logger';

const loggerImplMock: { [T in keyof Logger]: any } = {
fatal: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
trace: jest.fn(),
} as any;
jest.mock('../src/winston-logger', () => {
return {
createLogger: jest.fn(() => {
return loggerImplMock;
}),
};
});

describe('polaris-logger tests', () => {
const appProps: ApplicationLogProperties = {
id: 'p0laris-l0gs',
name: 'polaris-logs',
repositoryVersion: 'v1',
environment: 'environment',
component: 'component',
};
const config: LoggerConfiguration = {
loggerLevel: 'info',
logstashHost: '127.0.0.1',
logstashPort: 8080,
};
const message: string = 'log message';

test('creating a polaris logger with application properties and configuration - winston createLogger was called with configuration', () => {
const logger = new PolarisLogger(appProps, config);

expect(createLogger).toHaveBeenCalledWith(config);
});

test('fatal - logging message - message and application properties are in the log', () => {
const logger = new PolarisLogger(appProps, config);
logger.fatal(message);
expect(loggerImplMock.fatal).toHaveBeenCalledWith({
message,
component: appProps.component,
environment: appProps.environment,
repositoryVersion: appProps.repositoryVersion,
eventKindDescription: { systemId: appProps.id },
system: { id: appProps.id, name: appProps.name },
});
});

test('error - logging message - message and application properties are in the log', () => {
const logger = new PolarisLogger(appProps, config);
logger.error(message);
expect(loggerImplMock.error).toHaveBeenCalledWith({
message,
component: appProps.component,
environment: appProps.environment,
repositoryVersion: appProps.repositoryVersion,
eventKindDescription: { systemId: appProps.id },
system: { id: appProps.id, name: appProps.name },
});
});

test('warn - logging message - message and application properties are in the log', () => {
const logger = new PolarisLogger(appProps, config);
logger.warn(message);
expect(loggerImplMock.warn).toHaveBeenCalledWith({
message,
component: appProps.component,
environment: appProps.environment,
repositoryVersion: appProps.repositoryVersion,
eventKindDescription: { systemId: appProps.id },
system: { id: appProps.id, name: appProps.name },
});
});

test('info - logging message - message and application properties are in the log', () => {
const logger = new PolarisLogger(appProps, config);
logger.info(message);
expect(loggerImplMock.info).toHaveBeenCalledWith({
message,
component: appProps.component,
environment: appProps.environment,
repositoryVersion: appProps.repositoryVersion,
eventKindDescription: { systemId: appProps.id },
system: { id: appProps.id, name: appProps.name },
});
});

test('debug - logging message - message and application properties are in the log', () => {
const logger = new PolarisLogger(appProps, config);
logger.debug(message);
expect(loggerImplMock.debug).toHaveBeenCalledWith({
message,
component: appProps.component,
environment: appProps.environment,
repositoryVersion: appProps.repositoryVersion,
eventKindDescription: { systemId: appProps.id },
system: { id: appProps.id, name: appProps.name },
});
});

test('trace - logging message - message and application properties are in the log', () => {
const logger = new PolarisLogger(appProps, config);
logger.trace(message);
expect(loggerImplMock.trace).toHaveBeenCalledWith({
message,
component: appProps.component,
environment: appProps.environment,
repositoryVersion: appProps.repositoryVersion,
eventKindDescription: { systemId: appProps.id },
system: { id: appProps.id, name: appProps.name },
});
});
});
Loading

0 comments on commit fc51d06

Please sign in to comment.