Archived
0
0
Fork 0
This repository has been archived on 2024-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
argonbot/tests/utils/logger.test.ts

147 lines
4 KiB
TypeScript

/*
* This file is part of ArgonBot
*
* ArgonBot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ArgonBot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ArgonBot. If not, see <https: //www.gnu.org/licenses/>.
*/
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import * as sinon from 'sinon';
import { verbose, debug, info, warn, error, fatal } from '@utils/logger';
import { ELoggingScope } from '@utils/types';
describe('verbose()', () => {
let spy: sinon.SinonStub<[message?: any, ...optionalParams: any[]], void>;
beforeEach(() => {
spy = sinon.stub(console, 'log');
});
it('check message is being logged', () => {
verbose('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch('Test Message')).to.be.true;
});
it('check if Logging Scopes are being logged', () => {
verbose('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch(/COMMAND/)).to.be.true;
});
afterEach(() => {
spy.restore();
});
});
describe('debug()', () => {
let spy: sinon.SinonStub<[message?: any, ...optionalParams: any[]], void>;
beforeEach(() => {
spy = sinon.stub(console, 'log');
});
it('check message is being logged', () => {
debug('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch('Test Message')).to.be.true;
});
it('check if Logging Scopes are being logged', () => {
debug('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch(/COMMAND/)).to.be.true;
});
afterEach(() => {
spy.restore();
});
});
describe('info()', () => {
let spy: sinon.SinonStub<[message?: any, ...optionalParams: any[]], void>;
beforeEach(() => {
spy = sinon.stub(console, 'log');
});
it('check message is being logged', () => {
info('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch('Test Message')).to.be.true;
});
it('check if Logging Scopes are being logged', () => {
info('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch(/COMMAND/)).to.be.true;
});
afterEach(() => {
spy.restore();
});
});
describe('warn()', () => {
let spy: sinon.SinonStub<[message?: any, ...optionalParams: any[]], void>;
beforeEach(() => {
spy = sinon.stub(console, 'log');
});
it('check message is being logged', () => {
warn('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch('Test Message')).to.be.true;
});
it('check if Logging Scopes are being logged', () => {
warn('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch(/COMMAND/)).to.be.true;
});
afterEach(() => {
spy.restore();
});
});
describe('error()', () => {
let spy: sinon.SinonStub<[message?: any, ...optionalParams: any[]], void>;
beforeEach(() => {
spy = sinon.stub(console, 'log');
});
it('check message is being logged', () => {
error('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch('Test Message')).to.be.true;
});
it('check if Logging Scopes are being logged', () => {
error('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch(/COMMAND/)).to.be.true;
});
afterEach(() => {
spy.restore();
});
});
describe('fatal()', () => {
let spy: sinon.SinonStub<[message?: any, ...optionalParams: any[]], void>;
beforeEach(() => {
spy = sinon.stub(console, 'log');
});
it('check message is being logged', () => {
fatal('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch('Test Message')).to.be.true;
});
it('check if Logging Scopes are being logged', () => {
fatal('Test Message', ELoggingScope.Command);
expect(spy.calledWithMatch(/COMMAND/)).to.be.true;
});
afterEach(() => {
spy.restore();
});
});