bump package version to 1.3.2
[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 'topicSet',
42 'topicSetContent',
43 'topicUpdate',
44 'verificationClaim',
45 'verificationClaimById',
46 'verificationComplete',
47 'verificationGetById',
48 'verificationIncomplete',
49 'verificationInsert',
50 'verificationRelease',
51 'verificationUpdate',
52 'verificationValidated',
53 ];
54
55 const stubDatabase = {
56 _implementation: [ ...spyFns, ...stubFns ],
57 _reset: () => {
58 spyFns.forEach((fn) => sinon.spy(stubDatabase, fn));
59 stubFns.forEach((fn) => sinon.stub(stubDatabase, fn));
60 },
61 context: async (fn) => await fn({}),
62 transaction: async (dbCtx, fn) => await fn(dbCtx),
63 };
64
65 stubFns.forEach((fn) => {
66 stubDatabase[fn] = () => {};
67 });
68
69 module.exports = stubDatabase;