add caching for topic content db calls (Postgres only)
[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 'subscriptionDeliveryClaim',
21 'subscriptionDeliveryClaimById',
22 'subscriptionDeliveryComplete',
23 'subscriptionDeliveryGone',
24 'subscriptionDeliveryIncomplete',
25 'subscriptionGet',
26 'subscriptionGetById',
27 'subscriptionUpdate',
28 'subscriptionUpsert',
29 'topicDeleted',
30 'topicFetchClaim',
31 'topicFetchClaimById',
32 'topicFetchComplete',
33 'topicFetchIncomplete',
34 'topicFetchRequested',
35 'topicGetAll',
36 'topicGetById',
37 'topicGetByUrl',
38 'topicGetContentById',
39 'topicSet',
40 'topicSetContent',
41 'topicUpdate',
42 'verificationClaim',
43 'verificationClaimById',
44 'verificationComplete',
45 'verificationGetById',
46 'verificationIncomplete',
47 'verificationInsert',
48 'verificationRelease',
49 'verificationUpdate',
50 'verificationValidated',
51 ];
52
53 const stubDatabase = {
54 _implementation: [ ...spyFns, ...stubFns ],
55 _reset: () => {
56 spyFns.forEach((fn) => sinon.spy(stubDatabase, fn));
57 stubFns.forEach((fn) => sinon.stub(stubDatabase, fn));
58 },
59 context: async (fn) => await fn({}),
60 transaction: async (dbCtx, fn) => await fn(dbCtx),
61 };
62
63 stubFns.forEach((fn) => {
64 stubDatabase[fn] = () => {};
65 });
66
67 module.exports = stubDatabase;