UNPKG

thunder-log

Version:

The logger used for Shared Services Logging.

201 lines (186 loc) 8.9 kB
const Logging = require('./../index') const devLogger = Logging.getLogger('development') const awsLogger = Logging.getLogger('production') const testLogger = Logging.getLogger('test') const chai = require('chai') describe('Logger unit testing: ', () => { describe('Testing development logger: ', () => { describe('Testing failures: ', () => { it('should fail due to not having Summary', () => { try { devLogger.write('info',{}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having Summary', () => { try { devLogger.info({}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having proper Severity, not implemented', () => { try { devLogger.write('log',{Summary:'summary'}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having proper Severity, not a string', () => { try { devLogger.write(000,{Summary:'summary'}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) }) describe('Testing passing cases: ', () => { it('should pass with valid info statement', () => { chai.expect(devLogger.write('info',{Summary:'summary'})).to.be.function }) it('should pass with valid debug statement', () => { chai.expect(devLogger.write('debug',{Summary:'summary'})).to.be.function }) it('should pass with valid warn statement', () => { chai.expect(devLogger.write('warn',{Summary:'summary'})).to.be.function }) it('should pass with valid error statement', () => { chai.expect(devLogger.write('error',{Summary:'summary',ExceptionDetails:'some details'})).to.be.function }) it('should pass using logger shorthand', () => { chai.expect(devLogger.write('info','This is my message')).to.be.function }) it('should pass with valid info statement', () => { chai.expect(devLogger.info({Summary:'summary'})).to.be.function }) it('should pass with valid debug statement', () => { chai.expect(devLogger.debug({Summary:'summary'})).to.be.function }) it('should pass with valid warn statement', () => { chai.expect(devLogger.warn({Summary:'summary'})).to.be.function }) it('should pass with valid error statement', () => { chai.expect(devLogger.error({Summary:'summary',ExceptionDetails:'some details'})).to.be.function }) it('should pass using logger shorthand', () => { chai.expect(devLogger.info('This is my message')).to.be.function }) }) }) describe('Testing the AWS Logger', () => { describe('Testing failing cases: ', () => { it('should fail due to not having Summary', () => { try { awsLogger.write('info',{}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having Summary', () => { try { awsLogger.info({}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having proper Severity, not implemented', () => { try { awsLogger.write('log',{Summary:'summary'}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having proper Severity, not a string', () => { try { awsLogger.write(000,{Summary:'summary'}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) }) describe('Testing passing cases: ', () => { it('should pass with valid info statement', () => { chai.expect(awsLogger.write('info',{Summary:'summary'})).to.be.function }) it('should pass with valid debug statement', () => { chai.expect(awsLogger.write('debug',{Summary:'summary'})).to.be.function }) it('should pass with valid warn statement', () => { chai.expect(awsLogger.write('warn',{Summary:'summary'})).to.be.function }) it('should pass with valid error statement', () => { chai.expect(awsLogger.write('error',{Summary:'summary',ExceptionDetails:'some details'})).to.be.function }) it('should pass using logger shorthand', () => { chai.expect(awsLogger.write('info','This is my message')).to.be.function }) it('should pass with valid info statement', () => { chai.expect(awsLogger.info({Summary:'summary'})).to.be.function }) it('should pass with valid debug statement', () => { chai.expect(awsLogger.debug({Summary:'summary'})).to.be.function }) it('should pass with valid warn statement', () => { chai.expect(awsLogger.warn({Summary:'summary'})).to.be.function }) it('should pass with valid error statement', () => { chai.expect(awsLogger.error({Summary:'summary',ExceptionDetails:'some details'})).to.be.function }) it('should pass using logger shorthand', () => { chai.expect(awsLogger.info('This is my message')).to.be.function }) }) }) describe('Testing the mock logger: ', () => { describe('Testing failing cases: ', () => { it('should fail due to not having Summary', () => { try { testLogger.write('info',{}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having proper Severity, not implemented', () => { try { testLogger.write('log',{Summary:'summary'}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) it('should fail due to not having proper Severity, not a string', () => { try { testLogger.write(000,{Summary:'summary'}) } catch (err) { chai.expect(err).to.deep.equal(new Error('Invalid Logging Statement')) } }) }) describe('Testing passing cases: ', () => { it('should return 1 for an info log', () => { chai.expect(testLogger.write('info',{Summary:'summary'})).to.equal(1) }) it('should return 2 for an debug log', () => { chai.expect(testLogger.write('debug',{Summary:'summary'})).to.equal(2) }) it('should return 3 for an warn log', () => { chai.expect(testLogger.write('warn',{Summary:'summary'})).to.equal(3) }) it('should return 4 for an error log', () => { chai.expect(testLogger.write('error',{Summary:'summary',ExceptionDetails:'some details'})).to.equal(4) }) it('should return 1 for an info log', () => { chai.expect(testLogger.info('summary')).to.equal(1) }) it('should return 2 for an debug log', () => { chai.expect(testLogger.debug('summary')).to.equal(2) }) it('should return 3 for an warn log', () => { chai.expect(testLogger.warn('summary')).to.equal(3) }) it('should return 4 for an error log', () => { chai.expect(testLogger.error({Summary:'summary',ExceptionDetails:'some details'})).to.equal(4) }) }) }) })