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('handlerRedirect', function () {
64 it('covers', async
function () {
65 await service
.handlerRedirect(req
, res
, ctx
, '/');
66 assert(res
.end
.called
);
67 assert
.strictEqual(res
.statusCode
, 307);
69 }); // handlerRedirect
71 describe('handlerPostRoot', function () {
72 it('covers public mode', async
function () {
73 await service
.handlerPostRoot(req
, res
, ctx
);
74 assert(service
.manager
.postRoot
.called
);
76 }); // handlerPostRoot
78 describe('handlerGetRoot', function () {
79 it('covers', async
function () {
80 await service
.handlerGetRoot(req
, res
, ctx
);
81 assert(service
.manager
.getRoot
.called
);
85 describe('handlerGetHealthcheck', function () {
86 it('covers', async
function () {
87 await service
.handlerGetHealthcheck(req
, res
, ctx
);
88 assert(service
.manager
.getHealthcheck
.called
);
90 it('cover errors', async
function () {
91 const expectedException
= 'blah';
92 service
.manager
.getHealthcheck
.rejects(expectedException
);
94 await service
.handlerGetHealthcheck(req
, res
, ctx
);
95 assert
.fail('did not get expected exception');
97 assert
.strictEqual(e
.name
, expectedException
, 'did not get expected exception');
99 assert(service
.manager
.getHealthcheck
.called
);
101 }); // handlerGetHealthcheck
103 describe('handlerGetInfo', function () {
104 it('covers', async
function() {
105 await service
.handlerGetInfo(req
, res
, ctx
);
106 assert(service
.manager
.getInfo
.called
);
108 }); // handlerGetInfo
110 describe('handlerGetAdminOverview', function () {
111 it('covers', async
function () {
112 await service
.handlerGetAdminOverview(req
, res
, ctx
);
113 assert(service
.authenticator
.required
.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
.required
.called
);
122 assert(service
.manager
.getTopicDetails
.called
);
124 }); // handlerGetAdminTopicDetails
126 describe('handlerGetStaticFile', function () {
127 it('covers', async
function () {
128 service
.serveFile
.resolves();
129 await service
.handlerGetStaticFile(req
, res
, ctx
);
130 assert(service
.serveFile
.called
);
132 }); // handlerGetStaticFile
134 describe('handlerPostAdminProcess', function () {
135 it('covers', async
function () {
136 service
.serveFile
.resolves();
137 await service
.handlerPostAdminProcess(req
, res
, ctx
);
138 assert(service
.authenticator
.required
.called
);
139 assert(service
.manager
.processTasks
.called
);
141 }); // handlerPostAdminProcess
143 describe('handlerUpdateTopic', function () {
144 it('covers', async
function () {
145 sinon
.stub(service
, 'bodyData').resolves();
146 await service
.handlerUpdateTopic(req
, res
, ctx
);
147 assert(service
.authenticator
.required
.called
);
148 assert(service
.manager
.updateTopic
.called
);
150 }); // handlerUpdateTopic
152 describe('handlerUpdateSubscription', function () {
153 it('covers', async
function () {
154 sinon
.stub(service
, 'bodyData').resolves();
155 await service
.handlerUpdateSubscription(req
, res
, ctx
);
156 assert(service
.authenticator
.required
.called
);
157 assert(service
.manager
.updateSubscription
.called
);
159 }); // handlerUpdateSubscription