X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fservice.js;h=2de3b52c4595772834636f38be58b10fb54f9f6a;hb=f7e70910f579079d04c4cbeff750c8721a51fbe6;hp=62c0059553a0cbce037a75909d01902063e9178d;hpb=3839577f7cdab67b4591bc827e037d6c173c9dae;p=websub-hub diff --git a/test/src/service.js b/test/src/service.js index 62c0059..2de3b52 100644 --- a/test/src/service.js +++ b/test/src/service.js @@ -10,15 +10,17 @@ const stubDb = require('../stub-db'); const stubLogger = require('../stub-logger'); const Service = require('../../src/service'); const Config = require('../../config'); +const { AsyncLocalStorage } = require('node:async_hooks'); describe('Service', function () { - let service, options; + let service, options, asyncLocalStorage; let req, res, ctx; beforeEach(function () { + asyncLocalStorage = new AsyncLocalStorage(); options = new Config('test'); - service = new Service(stubLogger, stubDb, options); + service = new Service(stubLogger, stubDb, options, asyncLocalStorage); sinon.stub(service.manager); sinon.stub(service.sessionManager); sinon.stub(service.authenticator); @@ -46,6 +48,17 @@ describe('Service', function () { assert(service); }); + describe('preHandler', function () { + it('logs requestId', async () => { + sinon.stub(service.__proto__.__proto__, 'preHandler').resolves(); + await service.asyncLocalStorage.run({}, async () => { + await service.preHandler(req, res, ctx); + const logObject = service.asyncLocalStorage.getStore(); + assert('requestId' in logObject); + }); + }); + }); // preHandler + describe('maybeIngestBody', function () { beforeEach(function () { sinon.stub(service, 'bodyData');