Skip to content
Snippets Groups Projects
Commit 53482272 authored by Xiao Gui's avatar Xiao Gui
Browse files

fix broken tests

parent a63cb889
No related branches found
No related tags found
No related merge requests found
const { expect, assert } = require('chai')
const fs = require('fs')
const express = require('express')
const got = require('got')
const sinon = require('sinon')
......@@ -16,9 +15,9 @@ describe('authentication', () => {
process.env['USE_DEFAULT_MEMORY_STORE'] = true
const fakeFunctionObj = {
fakeAuthConfigureAuth: (req, res, next) => next(),
fakeAuthConfigureAuth: sinon.stub().callsFake((req, res, next) => next()),
fakeAuthReady: async () => true,
fakeUserRouterFn: (req, res, next) => res.status(200).send()
fakeUserRouterFn: sinon.stub().callsFake((req, res, next) => res.status(200).send())
}
before(async () => {
......@@ -61,13 +60,26 @@ describe('authentication', () => {
after(() => {
server.close()
})
it('> auth middleware is called', async () => {
await got(`http://localhost:${PORT}/user`)
assert(
fakeFunctionObj.fakeAuthConfigureAuth.called,
'auth middleware should be called'
)
})
it('> user middleware called', async () => {
await got(`http://localhost:${PORT}/user`)
assert(
fakeFunctionObj.fakeUserRouterFn.called,
'user middleware is called'
)
})
it('fakeAuthConfigureAuth is called before user router', async () => {
const spyFakeAuthConfigureAuth = sinon.spy(fakeFunctionObj, 'fakeAuthConfigureAuth')
const spyFakeUserRouterFn = sinon.spy(fakeFunctionObj, 'fakeUserRouterFn')
await got(`http://localhost:${PORT}/user`)
assert(
spyFakeAuthConfigureAuth.calledBefore(spyFakeUserRouterFn),
fakeFunctionObj.fakeAuthConfigureAuth.calledBefore(fakeFunctionObj.fakeUserRouterFn),
'fakeAuthConfigureAuth is called before user router'
)
})
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment