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
.sessionManager
);
24 sinon
.stub(service
.authenticator
);
25 sinon
.stub(service
, 'setResponseType');
26 sinon
.stub(service
, 'serveFile');
27 sinon
.stub(service
, 'ingestBody').resolves();
29 getHeader: sinon
.stub(),
32 setHeader: sinon
.stub(),
41 afterEach(function () {
45 it('instantiates', function () {
49 describe('maybeIngestBody', function () {
50 beforeEach(function () {
51 sinon
.stub(service
, 'bodyData');
52 sinon
.stub(service
, 'parseBody').returns();
54 it('covers no body', async
function() {
55 service
.bodyData
.resolves();
56 await service
.maybeIngestBody(req
, res
, ctx
);
58 it('covers body', async
function() {
59 service
.bodyData
.resolves('data');
60 await service
.maybeIngestBody(req
, res
, ctx
);
62 }); // maybeIngestBody
64 describe('handlerPostRoot', function () {
65 it('covers public mode', async
function () {
66 await service
.handlerPostRoot(req
, res
, ctx
);
67 assert(service
.manager
.postRoot
.called
);
69 }); // handlerPostRoot
71 describe('handlerGetRoot', function () {
72 it('covers', async
function () {
73 await service
.handlerGetRoot(req
, res
, ctx
);
74 assert(service
.manager
.getRoot
.called
);
78 describe('handlerGetHealthcheck', function () {
79 it('covers', async
function () {
80 await service
.handlerGetHealthcheck(req
, res
, ctx
);
81 assert(service
.manager
.getHealthcheck
.called
);
83 it('cover errors', async
function () {
84 const expectedException
= 'blah';
85 service
.manager
.getHealthcheck
.rejects(expectedException
);
87 await service
.handlerGetHealthcheck(req
, res
, ctx
);
88 assert
.fail('did not get expected exception');
90 assert
.strictEqual(e
.name
, expectedException
, 'did not get expected exception');
92 assert(service
.manager
.getHealthcheck
.called
);
94 }); // handlerGetHealthcheck
96 describe('handlerGetInfo', function () {
97 it('covers', async
function () {
98 await service
.handlerGetInfo(req
, res
, ctx
);
99 assert(service
.manager
.getInfo
.called
);
101 }); // handlerGetInfo
103 describe('handlerGetHistorySVG', function () {
104 it('covers', async
function () {
105 await service
.handlerGetHistorySVG(req
, res
, ctx
);
106 assert(service
.manager
.getHistorySVG
.called
);
108 }); // handlerGetHistorySVG
110 describe('handlerGetAdminOverview', function () {
111 it('covers', async
function () {
112 await service
.handlerGetAdminOverview(req
, res
, ctx
);
113 assert(service
.authenticator
.sessionRequired
.called
);
114 assert(service
.manager
.getAdminOverview
.called
);
116 }); // handlerGetAdminOverview
118 describe('handlerGetAdminTopicDetails', function () {
119 it('covers', async
function () {
120 await service
.handlerGetAdminTopicDetails(req
, res
, ctx
);
121 assert(service
.authenticator
.sessionRequired
.called
);
122 assert(service
.manager
.getTopicDetails
.called
);
124 }); // handlerGetAdminTopicDetails
126 describe('handlerPostAdminProcess', function () {
127 it('covers', async
function () {
128 service
.serveFile
.resolves();
129 await service
.handlerPostAdminProcess(req
, res
, ctx
);
130 assert(service
.authenticator
.apiRequiredLocal
.called
);
131 assert(service
.manager
.processTasks
.called
);
133 }); // handlerPostAdminProcess
135 describe('handlerUpdateTopic', function () {
136 it('covers', async
function () {
137 sinon
.stub(service
, 'bodyData').resolves();
138 await service
.handlerUpdateTopic(req
, res
, ctx
);
139 assert(service
.authenticator
.apiRequiredLocal
.called
);
140 assert(service
.manager
.updateTopic
.called
);
142 }); // handlerUpdateTopic
144 describe('handlerUpdateSubscription', function () {
145 it('covers', async
function () {
146 sinon
.stub(service
, 'bodyData').resolves();
147 await service
.handlerUpdateSubscription(req
, res
, ctx
);
148 assert(service
.authenticator
.apiRequiredLocal
.called
);
149 assert(service
.manager
.updateSubscription
.called
);
151 }); // handlerUpdateSubscription
153 describe('handlerGetAdminLogin', function () {
154 it('covers', async
function () {
155 await service
.handlerGetAdminLogin(req
, res
, ctx
);
156 assert(service
.sessionManager
.getAdminLogin
.called
);
158 }); // handlerGetAdminLogin
160 describe('handlerPostAdminLogin', function () {
161 it('covers', async
function () {
162 sinon
.stub(service
, 'bodyData').resolves();
163 await service
.handlerPostAdminLogin(req
, res
, ctx
);
164 assert(service
.sessionManager
.postAdminLogin
.called
);
166 }); // handlerPostAdminLogin
168 describe('handlerGetAdminLogout', function () {
169 it('covers', async
function () {
170 await service
.handlerGetAdminLogout(req
, res
, ctx
);
171 assert(service
.sessionManager
.getAdminLogout
.called
);
173 }); // handlerGetAdminLogout
175 describe('handlerGetAdminIA', function () {
176 it('covers', async
function () {
177 await service
.handlerGetAdminIA(req
, res
, ctx
);
178 assert(service
.sessionManager
.getAdminIA
.called
);
180 }); // handlerGetAdminIA