1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

adds admin middleware tests

This commit is contained in:
aaronmyatt 2020-12-04 23:00:31 +08:00
parent 78f1cb8a66
commit 50dd0354d1

View File

@ -96,4 +96,21 @@ describe("api/index", function() {
request(api.httpAdmin).get("/auth/login").expect(200).end(done)
})
});
describe('initialises api with admin middleware', function(done) {
it('ignores non-function values',function(done) {
api.init({ httpAdminRoot: true, httpAdminMiddleware: undefined },{},{},{});
const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'testMiddleware')
should(middlewareFound).be.empty();
done();
});
it('only accepts functions as middleware',function(done) {
const testMiddleware = function(req, res, next){ next(); };
api.init({ httpAdminRoot: true, httpAdminMiddleware: testMiddleware },{},{},{});
const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'testMiddleware')
should(middlewareFound).be.length(1);
done();
});
});
});