Skip to content

Instantly share code, notes, and snippets.

@fforres
Created December 6, 2018 21:25
Show Gist options
  • Save fforres/43fd55937d4292c312197fd5f12077e3 to your computer and use it in GitHub Desktop.
Save fforres/43fd55937d4292c312197fd5f12077e3 to your computer and use it in GitHub Desktop.
Middleware
import 'jest'
import { enrichment, IEnrichmentRequest } from '../../src/middlewares/enrichment'
import { mockReq, mockRes } from 'sinon-express-mock'
import * as sinon from 'sinon'
const enrichmentMiddleware = enrichment()
jest.mock('../../src/middlewares/enrichment/api.ts')
let req: IEnrichmentRequest
let res
let next: sinon.SinonSpy
describe(`Enrichment Middleware`, () => {
beforeEach(() => {
req = mockReq({
cookies: {}
})
res = mockRes()
next = sinon.fake()
})
it('Should not cotinue if request path is /healthcheck', async () => {
// Override the "beforeEachMockReq"
req = mockReq({
path: '/healthcheck',
cookies: {}
})
await enrichmentMiddleware(req, res, next)
next.calledWith({ msg: 'internal health check skip reveal' })
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment