X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fservice.js;h=e55502913d3cccd917b94fe17a92aaeaa80c9ef8;hb=fba42a499fe1af051b0982c1f3e8b3873c9ed2fb;hp=d361df120b18b9891406f1bb7fe4e668f9124d75;hpb=6f9af8204a725b70fa65728cb0d627d8a5e5b348;p=squeep-indie-auther diff --git a/test/src/service.js b/test/src/service.js index d361df1..e555029 100644 --- a/test/src/service.js +++ b/test/src/service.js @@ -7,19 +7,23 @@ const assert = require('assert'); const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require const { AsyncLocalStorage } = require('node:async_hooks'); -const stubDb = require('../stub-db'); -const stubLogger = require('../stub-logger'); +const StubDb = require('../stub-db'); +const StubLogger = require('../stub-logger'); const Service = require('../../src/service'); const Config = require('../../config'); describe('Service', function () { - let service, options, asyncLocalStorage; + let service, stubLogger, stubDb, options, asyncLocalStorage; let req, res, ctx; beforeEach(function () { asyncLocalStorage = new AsyncLocalStorage(); options = new Config('test'); + stubDb = new StubDb(); + stubDb._reset(); + stubLogger = new StubLogger(); + stubLogger._reset(); service = new Service(stubLogger, stubDb, options, asyncLocalStorage); sinon.stub(service.manager); sinon.stub(service.sessionManager); @@ -102,6 +106,32 @@ describe('Service', function () { }); }); // handlerGetAdminLogout + describe('handlerGetAdminSettings', function () { + it('covers authenticated', async function () { + service.authenticator.sessionRequiredLocal.resolves(true); + await service.handlerGetAdminSettings(req, res, ctx); + assert(service.sessionManager.getAdminSettings.called); + }); + it('covers unauthenticated', async function () { + service.authenticator.sessionRequiredLocal.resolves(false); + await service.handlerGetAdminSettings(req, res, ctx); + assert(service.sessionManager.getAdminSettings.notCalled); + }); + }); // handlerGetAdminSettings + + describe('handlerPostAdminSettings', function () { + it('covers authenticated', async function () { + service.authenticator.sessionRequiredLocal.resolves(true); + await service.handlerPostAdminSettings(req, res, ctx); + assert(service.sessionManager.postAdminSettings.called); + }); + it('covers unauthenticated', async function () { + service.authenticator.sessionRequiredLocal.resolves(false); + await service.handlerPostAdminSettings(req, res, ctx); + assert(service.sessionManager.postAdminSettings.notCalled); + }); + }); // handlerPostAdminSettings + describe('handlerGetAdmin', function () { it('covers authenticated', async function () { service.authenticator.sessionRequiredLocal.resolves(true); @@ -287,4 +317,10 @@ describe('Service', function () { }); }); // handlerGetAdminMaintenance + describe('handlerWhaGwan', function () { + it('covers', async function () { + await assert.rejects(() => service.handlerWhaGwan(req. res, ctx)); + }); + }); // handlerWhaGwan + }); \ No newline at end of file