update dependencies and remove now-redundant functions
[websub-hub] / test / src / service.js
1 /* eslint-env mocha */
2 /* eslint-disable capitalized-comments */
3
4 'use strict';
5
6 const assert = require('assert');
7 const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
8
9 const stubDb = require('../stub-db');
10 const stubLogger = require('../stub-logger');
11 const Service = require('../../src/service');
12 const Config = require('../../config');
13
14
15 describe('Service', function () {
16 let service, options;
17 let req, res, ctx;
18
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();
27 req = {
28 getHeader: sinon.stub(),
29 };
30 res = {
31 setHeader: sinon.stub(),
32 write: sinon.stub(),
33 end: sinon.stub(),
34 };
35 ctx = {
36 params: {},
37 };
38 });
39
40 afterEach(function () {
41 sinon.restore();
42 });
43
44 it('instantiates', function () {
45 assert(service);
46 });
47
48 describe('maybeIngestBody', function () {
49 beforeEach(function () {
50 sinon.stub(service, 'bodyData');
51 sinon.stub(service, 'parseBody').returns();
52 });
53 it('covers no body', async function() {
54 service.bodyData.resolves();
55 await service.maybeIngestBody(req, res, ctx);
56 });
57 it('covers body', async function() {
58 service.bodyData.resolves('data');
59 await service.maybeIngestBody(req, res, ctx);
60 });
61 }); // maybeIngestBody
62
63 describe('handlerPostRoot', function () {
64 it('covers public mode', async function () {
65 await service.handlerPostRoot(req, res, ctx);
66 assert(service.manager.postRoot.called);
67 });
68 }); // handlerPostRoot
69
70 describe('handlerGetRoot', function () {
71 it('covers', async function () {
72 await service.handlerGetRoot(req, res, ctx);
73 assert(service.manager.getRoot.called);
74 });
75 }); // handlerGetRoot
76
77 describe('handlerGetHealthcheck', function () {
78 it('covers', async function () {
79 await service.handlerGetHealthcheck(req, res, ctx);
80 assert(service.manager.getHealthcheck.called);
81 });
82 it('cover errors', async function () {
83 const expectedException = 'blah';
84 service.manager.getHealthcheck.rejects(expectedException);
85 try {
86 await service.handlerGetHealthcheck(req, res, ctx);
87 assert.fail('did not get expected exception');
88 } catch (e) {
89 assert.strictEqual(e.name, expectedException, 'did not get expected exception');
90 }
91 assert(service.manager.getHealthcheck.called);
92 });
93 }); // handlerGetHealthcheck
94
95 describe('handlerGetInfo', function () {
96 it('covers', async function() {
97 await service.handlerGetInfo(req, res, ctx);
98 assert(service.manager.getInfo.called);
99 });
100 }); // handlerGetInfo
101
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);
107 })
108 }); // handlerGetAdminOverview
109
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);
115 })
116 }); // handlerGetAdminTopicDetails
117
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);
124 });
125 }); // handlerPostAdminProcess
126
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);
133 });
134 }); // handlerUpdateTopic
135
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);
142 });
143 }); // handlerUpdateSubscription
144
145 });