2 /* eslint-disable capitalized-comments */
6 const assert
= require('assert');
7 const sinon
= require('sinon'); // eslint-disable-line node/no-unpublished-require
9 const stubDb
= require('../stub-db');
10 const stubLogger
= require('../stub-logger');
11 const Service
= require('../../src/service');
12 const Config
= require('../../config');
15 describe('Service', function () {
19 beforeEach(function () {
20 options
= new Config('test');
21 service
= new Service(stubLogger
, stubDb
, options
);
22 sinon
.stub(service
.manager
);
23 sinon
.stub(service
.authenticator
);
24 sinon
.stub(service
, 'setResponseType');
25 sinon
.stub(service
, 'serveFile');
26 sinon
.stub(service
, 'ingestBody').resolves();
28 getHeader: sinon
.stub(),
31 setHeader: sinon
.stub(),
40 afterEach(function () {
44 it('instantiates', function () {
48 describe('maybeIngestBody', function () {
49 beforeEach(function () {
50 sinon
.stub(service
, 'bodyData');
51 sinon
.stub(service
, 'parseBody').returns();
53 it('covers no body', async
function() {
54 service
.bodyData
.resolves();
55 await service
.maybeIngestBody(req
, res
, ctx
);
57 it('covers body', async
function() {
58 service
.bodyData
.resolves('data');
59 await service
.maybeIngestBody(req
, res
, ctx
);
61 }); // maybeIngestBody
63 describe('handlerPostRoot', function () {
64 it('covers public mode', async
function () {
65 await service
.handlerPostRoot(req
, res
, ctx
);
66 assert(service
.manager
.postRoot
.called
);
68 }); // handlerPostRoot
70 describe('handlerGetRoot', function () {
71 it('covers', async
function () {
72 await service
.handlerGetRoot(req
, res
, ctx
);
73 assert(service
.manager
.getRoot
.called
);
77 describe('handlerGetHealthcheck', function () {
78 it('covers', async
function () {
79 await service
.handlerGetHealthcheck(req
, res
, ctx
);
80 assert(service
.manager
.getHealthcheck
.called
);
82 it('cover errors', async
function () {
83 const expectedException
= 'blah';
84 service
.manager
.getHealthcheck
.rejects(expectedException
);
86 await service
.handlerGetHealthcheck(req
, res
, ctx
);
87 assert
.fail('did not get expected exception');
89 assert
.strictEqual(e
.name
, expectedException
, 'did not get expected exception');
91 assert(service
.manager
.getHealthcheck
.called
);
93 }); // handlerGetHealthcheck
95 describe('handlerGetInfo', function () {
96 it('covers', async
function() {
97 await service
.handlerGetInfo(req
, res
, ctx
);
98 assert(service
.manager
.getInfo
.called
);
100 }); // handlerGetInfo
102 describe('handlerGetAdminOverview', function () {
103 it('covers', async
function () {
104 await service
.handlerGetAdminOverview(req
, res
, ctx
);
105 assert(service
.authenticator
.required
.called
);
106 assert(service
.manager
.getAdminOverview
.called
);
108 }); // handlerGetAdminOverview
110 describe('handlerGetAdminTopicDetails', function () {
111 it('covers', async
function () {
112 await service
.handlerGetAdminTopicDetails(req
, res
, ctx
);
113 assert(service
.authenticator
.required
.called
);
114 assert(service
.manager
.getTopicDetails
.called
);
116 }); // handlerGetAdminTopicDetails
118 describe('handlerPostAdminProcess', function () {
119 it('covers', async
function () {
120 service
.serveFile
.resolves();
121 await service
.handlerPostAdminProcess(req
, res
, ctx
);
122 assert(service
.authenticator
.required
.called
);
123 assert(service
.manager
.processTasks
.called
);
125 }); // handlerPostAdminProcess
127 describe('handlerUpdateTopic', function () {
128 it('covers', async
function () {
129 sinon
.stub(service
, 'bodyData').resolves();
130 await service
.handlerUpdateTopic(req
, res
, ctx
);
131 assert(service
.authenticator
.required
.called
);
132 assert(service
.manager
.updateTopic
.called
);
134 }); // handlerUpdateTopic
136 describe('handlerUpdateSubscription', function () {
137 it('covers', async
function () {
138 sinon
.stub(service
, 'bodyData').resolves();
139 await service
.handlerUpdateSubscription(req
, res
, ctx
);
140 assert(service
.authenticator
.required
.called
);
141 assert(service
.manager
.updateSubscription
.called
);
143 }); // handlerUpdateSubscription