X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fservice.js;h=2cfe38d66ed4b55115ebb070dcc4301c1f7b9f1d;hb=3ca7fccb306d0b23626befc3791ffa360b3db1e7;hp=2de3b52c4595772834636f38be58b10fb54f9f6a;hpb=a11a8b4c83e3de5b5cf4c7d0687d7b7db932aa6e;p=websub-hub diff --git a/test/src/service.js b/test/src/service.js index 2de3b52..2cfe38d 100644 --- a/test/src/service.js +++ b/test/src/service.js @@ -1,10 +1,7 @@ -/* eslint-env mocha */ -/* eslint-disable capitalized-comments */ - 'use strict'; -const assert = require('assert'); -const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require +const assert = require('node:assert'); +const sinon = require('sinon'); const stubDb = require('../stub-db'); const stubLogger = require('../stub-logger'); @@ -21,6 +18,7 @@ describe('Service', function () { asyncLocalStorage = new AsyncLocalStorage(); options = new Config('test'); service = new Service(stubLogger, stubDb, options, asyncLocalStorage); + stubLogger._reset(); sinon.stub(service.manager); sinon.stub(service.sessionManager); sinon.stub(service.authenticator); @@ -49,7 +47,7 @@ describe('Service', function () { }); describe('preHandler', function () { - it('logs requestId', async () => { + it('logs requestId', async function () { sinon.stub(service.__proto__.__proto__, 'preHandler').resolves(); await service.asyncLocalStorage.run({}, async () => { await service.preHandler(req, res, ctx); @@ -57,6 +55,12 @@ describe('Service', function () { assert('requestId' in logObject); }); }); + it('covers weird async context failure', async function () { + sinon.stub(service.__proto__.__proto__, 'preHandler').resolves(); + sinon.stub(service.asyncLocalStorage, 'getStore').returns(); + await service.preHandler(req, res, ctx); + assert(service.logger.debug.called); + }); }); // preHandler describe('maybeIngestBody', function () { @@ -184,6 +188,34 @@ describe('Service', function () { }); }); // handlerGetAdminLogin + describe('handlerGetAdminSettings', function () { + it('covers logged in', async function () { + service.authenticator.sessionRequiredLocal.resolves(true); + await service.handlerGetAdminSettings(req, res, ctx); + assert(service.sessionManager.getAdminSettings.called); + }); + it('covers not logged in', async function () { + service.authenticator.sessionRequiredLocal.resolves(false); + await service.handlerGetAdminSettings(req, res, ctx); + assert(service.sessionManager.getAdminSettings.notCalled); + }); + }); // handlerGetAdminSettings + + describe('handlerPostAdminSettings', function () { + it('covers logged in', async function () { + service.authenticator.sessionRequiredLocal.resolves(true); + sinon.stub(service, 'bodyData').resolves(); + await service.handlerPostAdminSettings(req, res, ctx); + assert(service.sessionManager.postAdminSettings.called); + }); + it('covers logged outo', async function () { + service.authenticator.sessionRequiredLocal.resolves(false); + sinon.stub(service, 'bodyData').resolves(); + await service.handlerPostAdminSettings(req, res, ctx); + assert(service.sessionManager.postAdminSettings.notCalled); + }); + }); // handlerPostAdminSettings + describe('handlerPostAdminLogin', function () { it('covers', async function () { sinon.stub(service, 'bodyData').resolves(); @@ -197,7 +229,7 @@ describe('Service', function () { await service.handlerGetAdminLogout(req, res, ctx); assert(service.sessionManager.getAdminLogout.called); }); -}); // handlerGetAdminLogout + }); // handlerGetAdminLogout describe('handlerGetAdminIA', function () { it('covers', async function () {