X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fservice.js;h=ab6646f19ae9ecccb817388cb8bbb71a18396e82;hb=e8dccf76ec2776f07eddd1ce2f1c4fc150a6f790;hp=7a5e349df4af710a90f2e18c9ee58eeebb008db3;hpb=8ed17e3fb2fe838398036aef5b2a9398fd608375;p=squeep-indie-auther diff --git a/test/src/service.js b/test/src/service.js index 7a5e349..ab6646f 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); @@ -187,21 +191,27 @@ describe('Service', function () { }); // handlerGetHealthcheck describe('handlerInternalServerError', function () { + let ServiceClass, DingusClass; + before(function () { + ServiceClass = Object.getPrototypeOf(service); + DingusClass = Object.getPrototypeOf(ServiceClass); + }); it('covers no redirect', async function () { - sinon.stub(service.__proto__.__proto__, 'handlerInternalServerError'); + sinon.stub(DingusClass, 'handlerInternalServerError'); await service.handlerInternalServerError(req, res, ctx); - assert(service.__proto__.__proto__.handlerInternalServerError.called); + assert(DingusClass.handlerInternalServerError.called); }); it('covers redirect', async function () { - sinon.stub(service.__proto__.__proto__, 'handlerInternalServerError'); + sinon.stub(DingusClass, 'handlerInternalServerError'); ctx.session = { redirectUri: new URL('https://client.example.com/app'), clientIdentifier: new URL('https://client.exmaple.com/'), state: '123456', }; await service.handlerInternalServerError(req, res, ctx); - assert(!service.__proto__.__proto__.handlerInternalServerError.called); - assert(res.setHeader); + assert(!DingusClass.handlerInternalServerError.called); + assert(res.setHeader.called); + assert.strictEqual(res.statusCode, 302); }); }); // handlerInternalServerError @@ -281,4 +291,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