UNPKG

airpay-correlationid-middleware

Version:

correlationid middleware

50 lines (37 loc) 1.33 kB
const chai = require('chai'); const middleware = require('../index'); const { expect } = chai; const noopFn = () => {}; describe('Middleware', () => { it('should not be undefined', () => { expect(middleware).not.undefined; }); it('should be a equal to function', () => { expect(typeof (middleware)).to.eq('function'); }); it('should return true x-coreplatform-correlationid is defined in header', async () => { const request = { headers: { 'x-coreplatform-correlationid': 'b7be7d00-6b20-11e8-84b4-b5b4862f001b', }, }; const isBoolean = middleware(request, {}, noopFn); expect(isBoolean).equal(true); }); it('should return x-coreplatform-correlationid value in headers if already exists', async () => { const request = { headers: { 'x-coreplatform-correlationid': 'b7be7d00-6b20-11e8-84b4-b5b4862f001b', }, }; middleware(request, {}, noopFn); expect(request.headers['x-coreplatform-correlationid']).to.be.equal('b7be7d00-6b20-11e8-84b4-b5b4862f001b'); }); it('should return new x-coreplatform-correlationid value if not exists in headers', () => { const request = { headers: {}, }; middleware(request, {}, noopFn); expect(request.headers['x-coreplatform-correlationid']).not.to.be.undefined; }); });