update dependencies and devDependencies
[websub-hub] / test / stub-db.js
1 /* eslint-disable security/detect-object-injection */
2 'use strict';
3
4 const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
5
6 const spyFns = [
7 'context',
8 'transaction',
9 ];
10
11 const stubFns = [
12 'authenticationSuccess',
13 'authenticationGet',
14 'authenticationUpsert',
15 'healthCheck',
16 'initialize',
17 'subscriptionsByTopicId',
18 'subscriptionCountByTopicUrl',
19 'subscriptionDelete',
20 'subscriptionDeleteExpired',
21 'subscriptionDeliveryClaim',
22 'subscriptionDeliveryClaimById',
23 'subscriptionDeliveryComplete',
24 'subscriptionDeliveryGone',
25 'subscriptionDeliveryIncomplete',
26 'subscriptionGet',
27 'subscriptionGetById',
28 'subscriptionUpdate',
29 'subscriptionUpsert',
30 'topicDeleted',
31 'topicFetchClaim',
32 'topicFetchClaimById',
33 'topicFetchComplete',
34 'topicFetchIncomplete',
35 'topicFetchRequested',
36 'topicGetAll',
37 'topicGetById',
38 'topicGetByUrl',
39 'topicGetContentById',
40 'topicPendingDelete',
41 'topicPublishHistory',
42 'topicSet',
43 'topicSetContent',
44 'topicUpdate',
45 'verificationClaim',
46 'verificationClaimById',
47 'verificationComplete',
48 'verificationGetById',
49 'verificationIncomplete',
50 'verificationInsert',
51 'verificationRelease',
52 'verificationUpdate',
53 'verificationValidated',
54 ];
55
56 const stubDatabase = {
57 _implementation: [ ...spyFns, ...stubFns ],
58 _reset: () => {
59 spyFns.forEach((fn) => sinon.spy(stubDatabase, fn));
60 stubFns.forEach((fn) => sinon.stub(stubDatabase, fn));
61 },
62 context: async (fn) => await fn({}),
63 transaction: async (dbCtx, fn) => await fn(dbCtx),
64 };
65
66 stubFns.forEach((fn) => {
67 stubDatabase[fn] = () => {};
68 });
69
70 module.exports = stubDatabase;