1 /* eslint-disable sonarjs/no-identical-functions */
3 /* eslint-disable sonarjs/no-duplicate-string */
6 /* This provides implementation coverage, stubbing parts of better-sqlite3. */
8 const assert
= require('assert');
9 // eslint-disable-next-line node/no-unpublished-require
10 const sinon
= require('sinon');
11 const DBStub
= require('../../stub-db');
12 const stubLogger
= require('../../stub-logger');
13 const DB
= require('../../../src/db/sqlite');
14 const DBErrors
= require('../../../src/db/errors');
15 const common
= require('../../../src/common');
16 const Config
= require('../../../config');
18 const noExpectedException
= 'did not receive expected exception';
20 describe('DatabaseSQLite', function () {
22 let dbCtx
, claimant
, claimTimeoutSeconds
, callback
, subscriptionId
, topicId
, verificationId
;
23 let topicUrl
, leaseSeconds
, secret
, httpRemoteAddr
, httpFrom
, retryDelays
, wanted
;
25 options
= new Config('test');
26 options
.db
.connectionString
= 'sqlite://:memory:';
27 db
= new DB(stubLogger
, options
);
29 beforeEach(function () {
32 claimant
= '19af19b8-6be3-4a6f-8946-65f5f1ccc5d7';
33 claimTimeoutSeconds
= 300;
34 subscriptionId
= 'fbaf8f19-ed9c-4a21-89ae-98b7005e3bf6';
35 topicUrl
= 'https://example.com/blog';
36 callback
= 'https://example.com/callback?id=123';
37 topicId
= 'c59d4bda-10ad-41d9-99df-4ce8bc331424';
38 verificationId
= '55cd7748-d2d5-11eb-b355-0025905f714a';
42 httpRemoteAddr
= '127.0.0.1';
43 httpFrom
= 'user@example.com';
46 afterEach(function () {
50 // Ensure all interface methods are implemented
51 describe('Implementation', function () {
52 it('implements interface', async
function () {
53 const results
= await Promise
.allSettled(DBStub
._implementation
.map(async (fn
) => {
55 // eslint-disable-next-line security/detect-object-injection
58 assert(!(e
instanceof DBErrors
.NotImplemented
), `${fn} not implemented`);
61 const failures
= results
.filter((x
) => x
.status
=== 'rejected');
62 assert(!failures
.length
, failures
.map((x
) => {
63 x
= x
.reason
.toString();
64 return x
.slice(x
.indexOf(': '));
69 describe('_initTables', function () {
71 beforeEach(function () {
72 preparedGet
= sinon
.stub();
73 sinon
.stub(db
.db
, 'prepare').returns({
80 sinon
.stub(db
, '_currentSchema').returns(db
.schemaVersionsSupported
.min
);
81 sinon
.stub(db
.db
, 'exec');
83 it('covers migration', async
function() {
84 preparedGet
.returns({});
85 await db
._initTables();
86 assert(db
.db
.exec
.called
);
88 it('covers migration failure', async
function() {
89 const expected
= new Error('oh no');
90 preparedGet
.returns({});
91 db
.db
.exec
.throws(expected
);
93 await db
._initTables();
94 assert
.fail(noExpectedException
);
96 assert
.deepStrictEqual(e
, expected
);
101 describe('_currentSchema', function () {
102 it('covers', async
function () {
103 const version
= { major: 1, minor: 0, patch: 0 };
104 sinon
.stub(db
.db
, 'prepare').returns({
107 const result
= await db
._currentSchema();
108 assert
.deepStrictEqual(result
, version
);
110 }); // _currentSchema
112 describe('_closeConnection', function () {
113 it('success', async
function () {
114 sinon
.stub(db
.db
, 'close');
115 await db
._closeConnection();
116 assert(db
.db
.close
.called
);
118 it('failure', async
function () {
119 const expected
= new Error();
120 sinon
.stub(db
.db
, 'close').throws(expected
);
122 await db
._closeConnection();
123 assert
.fail(noExpectedException
);
125 assert
.deepStrictEqual(e
, expected
);
128 }); // _closeConnection
130 describe('_purgeTables', function () {
131 beforeEach(function () {
132 sinon
.stub(db
.db
, 'prepare').returns({
136 it('covers not really', async
function () {
137 await db
._purgeTables(false);
138 assert(!db
.db
.prepare
.called
);
140 it('success', async
function () {
141 await db
._purgeTables(true);
142 assert(db
.db
.prepare
.called
);
144 it('failure', async
function () {
145 const expected
= new Error();
146 db
.db
.prepare
.restore();
147 sinon
.stub(db
.db
, 'prepare').throws(expected
);
149 await db
._purgeTables(true);
150 assert
.fail(noExpectedException
);
152 assert
.deepStrictEqual(e
, expected
);
157 describe('_optimize', function () {
159 beforeEach(function () {
160 origOAC
= db
.optimizeAfterChanges
;
161 sinon
.stub(db
.statement
._optimize
, 'all');
162 sinon
.stub(db
.db
, 'pragma');
164 this.afterEach(function () {
165 db
.optimizeAfterChanges
= origOAC
;
167 it('covers', async
function () {
168 db
.optimizeAfterChanges
= 10;
169 db
.changesSinceLastOptimize
= BigInt(20);
170 await db
._optimize();
171 assert(db
.db
.pragma
.called
);
173 it('covers none', async
function () {
174 db
.optimizeAfterChanges
= 0;
175 await db
._optimize();
176 assert(!db
.db
.pragma
.called
);
178 it('covers not enough changes', async
function () {
179 db
.optimizeAfterChanges
= 10;
180 db
.changesSinceLastOptimize
= BigInt(5);
181 await db
._optimize();
182 assert(!db
.db
.pragma
.called
);
186 describe('_deOphidiate', function () {
187 it('covers non-array', function () {
194 const result
= DB
._deOphidiate(obj
);
195 assert
.deepStrictEqual(result
, expected
);
197 it('covers array', function () {
214 const result
= DB
._deOphidiate(rows
);
215 assert
.deepStrictEqual(result
, expected
);
219 describe('_topicDataToNative', function () {
220 it('covers', function () {
221 const now
= new Date();
222 const nowEpoch
= now
.getTime() / 1000;
227 lastPublish: nowEpoch
,
228 contentFetchNextAttempt: nowEpoch
,
229 contentUpdated: nowEpoch
,
230 url: 'https://example.com/',
237 contentFetchNextAttempt: now
,
241 const result
= DB
._topicDataToNative(topic
);
242 assert
.deepStrictEqual(result
, expected
);
244 it('covers empty', function () {
245 const topic
= undefined;
246 const result
= DB
._topicDataToNative(topic
);
247 assert
.deepStrictEqual(result
, topic
);
249 }); // _topicDataToNative
251 describe('healthCheck', function () {
253 beforeEach(function () {
256 afterEach(function () {
259 it('covers', function () {
262 it('covers failure', function () {
263 db
.db
= { open: false };
266 assert
.fail(noExpectedException
);
268 assert(e
instanceof DBErrors
.UnexpectedResult
);
273 describe('context', function () {
274 it('covers', async
function () {
275 await db
.context(common
.nop
);
279 describe('transaction', function () {
280 it('covers', async
function () {
281 await db
.transaction(db
.db
, common
.nop
);
283 it('covers no context', async
function () {
284 await db
.transaction(undefined, common
.nop
);
288 describe('authenticationSuccess', function () {
290 beforeEach(function () {
291 identifier
= 'username';
293 it('success', async
function() {
296 lastInsertRowid: undefined,
298 sinon
.stub(db
.statement
.authenticationSuccess
, 'run').returns(dbResult
);
299 await db
.authenticationSuccess(dbCtx
, identifier
);
301 it('failure', async
function () {
304 lastInsertRowid: undefined,
306 sinon
.stub(db
.statement
.authenticationSuccess
, 'run').returns(dbResult
);
308 await db
.authenticationSuccess(dbCtx
, identifier
);
309 assert
.fail(noExpectedException
);
311 assert(e
instanceof DBErrors
.UnexpectedResult
);
314 }); // authenticationSuccess
316 describe('authenticationGet', function () {
317 let identifier
, credential
;
318 beforeEach(function () {
319 identifier
= 'username';
320 credential
= '$z$foo';
322 it('success', async
function() {
327 sinon
.stub(db
.statement
.authenticationGet
, 'get').returns(expected
);
328 const result
= await db
.authenticationGet(dbCtx
, identifier
);
329 assert
.deepStrictEqual(result
, expected
);
331 it('failure', async
function () {
332 const expected
= new Error();
333 sinon
.stub(db
.statement
.authenticationGet
, 'get').throws(expected
);
335 await db
.authenticationGet(dbCtx
, identifier
);
336 assert
.fail(noExpectedException
);
338 assert
.deepStrictEqual(e
, expected
);
341 }); // authenticationGet
343 describe('authenticationUpsert', function () {
344 let identifier
, credential
;
345 beforeEach(function () {
346 identifier
= 'username';
347 credential
= '$z$foo';
349 it('success', async
function() {
352 lastInsertRowid: undefined,
354 sinon
.stub(db
.statement
.authenticationUpsert
, 'run').returns(dbResult
);
355 await db
.authenticationUpsert(dbCtx
, identifier
, credential
);
357 it('failure', async
function () {
360 lastInsertRowid: undefined,
362 sinon
.stub(db
.statement
.authenticationUpsert
, 'run').returns(dbResult
);
364 await db
.authenticationUpsert(dbCtx
, identifier
, credential
);
365 assert
.fail(noExpectedException
);
367 assert(e
instanceof DBErrors
.UnexpectedResult
);
370 }); // authenticationUpsert
372 describe('subscriptionsByTopicId', function () {
373 it('success', async
function () {
374 const expected
= [{ id: 3 }];
375 sinon
.stub(db
.statement
.subscriptionsByTopicId
, 'all').returns(expected
);
376 const result
= await db
.subscriptionsByTopicId(dbCtx
, topicUrl
);
377 assert
.deepStrictEqual(result
, expected
);
379 it('failure', async
function () {
380 const expected
= new Error();
381 sinon
.stub(db
.statement
.subscriptionsByTopicId
, 'all').throws(expected
);
383 await db
.subscriptionsByTopicId(dbCtx
, topicUrl
);
384 assert
.fail(noExpectedException
);
386 assert
.deepStrictEqual(e
, expected
);
389 }); // subscriptionsByTopicId
391 describe('subscriptionCountByTopicUrl', function () {
392 it('success', async
function () {
393 const expected
= { count: 3 };
394 sinon
.stub(db
.statement
.subscriptionCountByTopicUrl
, 'get').returns(expected
);
395 const result
= await db
.subscriptionCountByTopicUrl(dbCtx
, topicUrl
);
396 assert
.deepStrictEqual(result
, expected
);
398 it('failure', async
function () {
399 const expected
= new Error();
400 sinon
.stub(db
.statement
.subscriptionCountByTopicUrl
, 'get').throws(expected
);
402 await db
.subscriptionCountByTopicUrl(dbCtx
, topicUrl
);
403 assert
.fail(noExpectedException
);
405 assert
.deepStrictEqual(e
, expected
);
408 }); // subscriptionCountByTopicUrl
410 describe('subscriptionDelete', function () {
411 it('success', async
function() {
414 lastInsertRowid: undefined,
418 lastInsertRowid: undefined,
420 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
421 const result
= await db
.subscriptionDelete(dbCtx
, callback
, topicId
);
422 assert
.deepStrictEqual(result
, expected
);
424 it('failure', async
function () {
427 lastInsertRowid: undefined,
429 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
431 await db
.subscriptionDelete(dbCtx
, callback
, topicId
);
432 assert
.fail(noExpectedException
);
434 assert(e
instanceof DBErrors
.UnexpectedResult
);
437 }); // subscriptionDelete
439 describe('subscriptionDeleteExpired', function () {
440 it('success', async
function () {
443 lastInsertRowid: undefined,
447 lastInsertRowid: undefined,
449 sinon
.stub(db
.statement
.subscriptionDeleteExpired
, 'run').returns(dbResult
);
450 const result
= await db
.subscriptionDeleteExpired(dbCtx
, topicId
);
451 assert
.deepStrictEqual(result
, expected
);
453 it('failure', async
function () {
454 const expected
= new Error();
455 sinon
.stub(db
.statement
.subscriptionDeleteExpired
, 'run').throws(expected
);
457 await db
.subscriptionDeleteExpired(dbCtx
, topicId
);
458 assert
.fail(noExpectedException
);
460 assert
.deepStrictEqual(e
, expected
);
463 }); // subscriptionDeleteExpired
465 describe('subscriptionDeliveryClaim', function () {
466 it('success', async
function () {
467 const dbAllResult
= [
469 id: 'c2e254c5-aa6e-4a8f-b1a1-e474b07392bb',
472 const dbRunResult
= {
474 lastInsertRowid: undefined,
476 const expected
= ['c2e254c5-aa6e-4a8f-b1a1-e474b07392bb'];
477 sinon
.stub(db
.statement
.subscriptionDeliveryNeeded
, 'all').returns(dbAllResult
);
478 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbRunResult
);
479 const result
= await db
.subscriptionDeliveryClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
480 assert
.deepStrictEqual(result
, expected
);
482 it('failure', async
function () {
483 const dbAllResult
= [
485 id: 'c2e254c5-aa6e-4a8f-b1a1-e474b07392bb',
488 const dbRunResult
= {
490 lastInsertRowid: undefined,
492 sinon
.stub(db
.statement
.subscriptionDeliveryNeeded
, 'all').returns(dbAllResult
);
493 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbRunResult
);
495 await db
.subscriptionDeliveryClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
496 assert
.fail(noExpectedException
);
498 assert(e
instanceof DBErrors
.UnexpectedResult
);
501 }); // subscriptionDeliveryClaim
503 describe('subscriptionDeliveryClaimById', function () {
504 it('success', async
function() {
507 lastInsertRowid: undefined,
509 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbResult
);
510 const result
= await db
.subscriptionDeliveryClaimById(dbCtx
, subscriptionId
, claimTimeoutSeconds
, claimant
);
511 assert
.deepStrictEqual(result
, dbResult
);
513 it('failure', async
function () {
516 lastInsertRowid: undefined,
518 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbResult
);
520 await db
.subscriptionDeliveryClaimById(dbCtx
, subscriptionId
, claimTimeoutSeconds
, claimant
);
521 assert
.fail(noExpectedException
);
523 assert(e
instanceof DBErrors
.UnexpectedResult
);
526 }); // subscriptionDeliveryClaimById
528 describe('subscriptionDeliveryComplete', function () {
529 let topicContentUpdated
;
531 topicContentUpdated
= new Date();
533 it('success', async
function() {
537 sinon
.stub(db
.statement
.subscriptionDeliverySuccess
, 'run').returns(dbResult
);
538 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
539 await db
.subscriptionDeliveryComplete(dbCtx
, callback
, topicId
, topicContentUpdated
);
541 it('failure', async
function () {
545 sinon
.stub(db
.statement
.subscriptionDeliverySuccess
, 'run').returns(dbResult
);
546 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
548 await db
.subscriptionDeliveryComplete(dbCtx
, callback
, topicId
, topicContentUpdated
);
549 assert
.fail(noExpectedException
);
551 assert(e
instanceof DBErrors
.UnexpectedResult
);
554 it('second failure', async
function () {
561 sinon
.stub(db
.statement
.subscriptionDeliverySuccess
, 'run').returns(dbResult0
);
562 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult1
);
564 await db
.subscriptionDeliveryComplete(dbCtx
, callback
, topicId
, topicContentUpdated
);
565 assert
.fail(noExpectedException
);
567 assert(e
instanceof DBErrors
.UnexpectedResult
);
570 }); // subscriptionDeliveryComplete
572 describe('subscriptionDeliveryGone', function () {
573 it('success', async
function() {
577 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
578 await db
.subscriptionDeliveryGone(dbCtx
, callback
, topicId
);
580 it('failure', async
function () {
584 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
586 await db
.subscriptionDeliveryGone(dbCtx
, callback
, topicId
);
587 assert
.fail(noExpectedException
);
589 assert(e
instanceof DBErrors
.UnexpectedResult
);
592 }); // subscriptionDeliveryGone
594 describe('subscriptionDeliveryIncomplete', function () {
595 it('success', async
function() {
596 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
600 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
601 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult
);
602 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
603 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
, retryDelays
);
605 it('success covers default', async
function() {
606 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
610 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
611 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult
);
612 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
613 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
);
615 it('failure', async
function () {
616 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
620 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
621 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult
);
622 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
624 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
, retryDelays
);
625 assert
.fail(noExpectedException
);
627 assert(e
instanceof DBErrors
.UnexpectedResult
);
630 it('second failure', async
function () {
631 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
638 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
639 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult0
);
640 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult1
);
642 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
, retryDelays
);
643 assert
.fail(noExpectedException
);
645 assert(e
instanceof DBErrors
.UnexpectedResult
);
648 }); // subscriptionDeliveryIncomplete
650 describe('subscriptionGet', function () {
651 it('success', async
function() {
655 sinon
.stub(db
.statement
.subscriptionGet
, 'get').returns(expected
);
656 const result
= await db
.subscriptionGet(dbCtx
, callback
, topicId
);
657 assert
.deepStrictEqual(result
, expected
);
659 it('failure', async
function () {
660 const expected
= new Error();
661 sinon
.stub(db
.statement
.subscriptionGet
, 'get').throws(expected
);
663 await db
.subscriptionGet(dbCtx
, callback
, topicId
);
664 assert
.fail(noExpectedException
);
666 assert
.deepStrictEqual(e
, expected
);
669 }); // subscriptionGet
671 describe('subscriptionGetById', function () {
672 it('success', async
function() {
676 sinon
.stub(db
.statement
.subscriptionGetById
, 'get').returns(expected
);
677 const result
= await db
.subscriptionGetById(dbCtx
, subscriptionId
);
678 assert
.deepStrictEqual(result
, expected
);
680 it('failure', async
function () {
681 const expected
= new Error();
682 sinon
.stub(db
.statement
.subscriptionGetById
, 'get').throws(expected
);
684 await db
.subscriptionGetById(dbCtx
, subscriptionId
);
685 assert
.fail(noExpectedException
);
687 assert
.deepStrictEqual(e
, expected
);
690 }); // subscriptionGetById
692 describe('subscriptionUpdate', function () {
694 beforeEach(function () {
697 signatureAlgorithm: 'sha256',
700 it('success', async
function() {
703 lastInsertRowid: subscriptionId
,
705 sinon
.stub(db
.statement
.subscriptionUpdate
, 'run').returns(dbResult
);
706 await db
.subscriptionUpdate(dbCtx
, data
);
708 it('failure', async
function () {
712 sinon
.stub(db
.statement
.subscriptionUpdate
, 'run').returns(dbResult
);
714 await db
.subscriptionUpdate(dbCtx
, data
);
715 assert
.fail(noExpectedException
);
717 assert(e
instanceof DBErrors
.UnexpectedResult
, e
);
720 }); // subscriptionUpdate
722 describe('subscriptionUpsert', function () {
724 beforeEach(function () {
734 it('success', async
function() {
737 lastInsertRowid: subscriptionId
,
741 lastInsertRowid: subscriptionId
,
743 sinon
.stub(db
.statement
.subscriptionUpsert
, 'run').returns(dbResult
);
744 const result
= await db
.subscriptionUpsert(dbCtx
, data
);
745 assert
.deepStrictEqual(result
, expected
);
747 it('failure', async
function () {
751 sinon
.stub(db
.statement
.subscriptionUpsert
, 'run').returns(dbResult
);
753 await db
.subscriptionUpsert(dbCtx
, data
);
754 assert
.fail(noExpectedException
);
756 assert(e
instanceof DBErrors
.UnexpectedResult
);
759 }); // subscriptionUpsert
761 describe('topicDeleted', function () {
762 it('success', async
function () {
763 sinon
.stub(db
.statement
.topicDeleted
, 'run').returns({ changes: 1 });
764 await db
.topicDeleted(dbCtx
, { topicId
});
766 it('failure', async
function () {
767 sinon
.stub(db
.statement
.topicDeleted
, 'run').returns({ changes: 0 });
769 await db
.topicDeleted(dbCtx
, { topicId
});
770 assert
.fail(noExpectedException
);
772 assert(e
instanceof DBErrors
.UnexpectedResult
);
777 describe('topicFetchClaim', function () {
778 it('success', async
function() {
779 const dbAll
= [{ id: topicId
}];
783 const expected
= [topicId
];
784 sinon
.stub(db
.statement
.topicContentFetchNeeded
, 'all').returns(dbAll
);
785 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(dbResult
);
786 const result
= await db
.topicFetchClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
787 assert
.deepStrictEqual(result
, expected
);
789 it('failure', async
function () {
790 const dbAll
= [{ id: topicId
}];
794 sinon
.stub(db
.statement
.topicContentFetchNeeded
, 'all').returns(dbAll
);
795 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(dbResult
);
797 await db
.topicFetchClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
798 assert
.fail(noExpectedException
);
800 assert(e
instanceof DBErrors
.UnexpectedResult
);
803 }); // topicFetchClaim
805 describe('topicFetchClaimById', function () {
806 it('success', async
function() {
809 lastInsertRowid: undefined,
811 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(expected
);
812 const result
= await db
.topicFetchClaimById(dbCtx
, topicId
, claimTimeoutSeconds
, claimant
);
813 assert
.deepStrictEqual(result
, expected
);
815 it('failure', async
function () {
818 lastInsertRowid: undefined,
820 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(expected
);
822 await db
.topicFetchClaimById(dbCtx
, topicId
, claimTimeoutSeconds
, claimant
);
823 assert
.fail(noExpectedException
);
825 assert(e
instanceof DBErrors
.UnexpectedResult
);
828 }); // topicFetchClaimById
830 describe('topicFetchComplete', function () {
831 it('success', async
function() {
834 lastInsertRowid: undefined,
836 sinon
.stub(db
.statement
.topicAttemptsReset
, 'run').returns(dbResult
);
837 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult
);
838 await db
.topicFetchComplete(dbCtx
, topicId
);
840 it('failure', async
function () {
843 lastInsertRowid: undefined,
845 sinon
.stub(db
.statement
.topicAttemptsReset
, 'run').returns(dbResult
);
846 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult
);
848 await db
.topicFetchComplete(dbCtx
, topicId
);
849 assert
.fail(noExpectedException
);
851 assert(e
instanceof DBErrors
.UnexpectedResult
);
854 it('second failure', async
function () {
857 lastInsertRowid: undefined,
861 lastInsertRowid: undefined,
863 sinon
.stub(db
.statement
.topicAttemptsReset
, 'run').returns(dbResult0
);
864 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
866 await db
.topicFetchComplete(dbCtx
, topicId
);
867 assert
.fail(noExpectedException
);
869 assert(e
instanceof DBErrors
.UnexpectedResult
);
872 }); // topicFetchComplete
874 describe('topicFetchIncomplete', function () {
875 it('success', async
function() {
876 const dbGet
= { currentAttempt: 0 };
879 lastInsertRowid: undefined,
883 lastInsertRowid: undefined,
887 lastInsertRowid: undefined,
889 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
890 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
891 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
892 const result
= await db
.topicFetchIncomplete(dbCtx
, topicId
, retryDelays
);
893 assert
.deepStrictEqual(result
, expected
);
895 it('covers defaults', async
function() {
896 const dbGet
= { currentAttempt: 0 };
899 lastInsertRowid: undefined,
903 lastInsertRowid: undefined,
907 lastInsertRowid: undefined,
909 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
910 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
911 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
912 const result
= await db
.topicFetchIncomplete(dbCtx
, topicId
);
913 assert
.deepStrictEqual(result
, expected
);
915 it('failure', async
function () {
916 const dbGet
= { currentAttempt: 0 };
919 lastInsertRowid: undefined,
923 lastInsertRowid: undefined,
925 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
926 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
927 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
929 await db
.topicFetchIncomplete(dbCtx
, topicId
, retryDelays
);
930 assert
.fail(noExpectedException
);
932 assert(e
instanceof DBErrors
.UnexpectedResult
);
935 it('second failure', async
function () {
936 const dbGet
= { currentAttempt: 0 };
939 lastInsertRowid: undefined,
943 lastInsertRowid: undefined,
945 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
946 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
947 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
949 await db
.topicFetchIncomplete(dbCtx
, topicId
, retryDelays
);
950 assert
.fail(noExpectedException
);
952 assert(e
instanceof DBErrors
.UnexpectedResult
);
955 }); // topicFetchIncomplete
957 describe('topicFetchRequested', function () {
958 it('success', async
function() {
961 lastInsertRowid: undefined,
965 lastInsertRowid: undefined,
967 sinon
.stub(db
.statement
.topicContentFetchRequested
, 'run').returns(dbResult
);
968 const result
= await db
.topicFetchRequested(dbCtx
, topicId
);
969 assert
.deepStrictEqual(result
, expected
);
971 it('failure', async
function () {
974 lastInsertRowid: undefined,
976 sinon
.stub(db
.statement
.topicContentFetchRequested
, 'run').returns(dbResult
);
978 await db
.topicFetchRequested(dbCtx
, topicId
);
979 assert
.fail(noExpectedException
);
981 assert(e
instanceof DBErrors
.UnexpectedResult
);
984 }); // topicFetchRequested
986 describe('topicGetAll', function () {
987 it('success', async
function() {
988 const expected
= [{ id: topicId
}];
989 sinon
.stub(db
.statement
.topicGetInfoAll
, 'all').returns(expected
);
990 const result
= await db
.topicGetAll(dbCtx
);
991 assert
.deepStrictEqual(result
, expected
);
993 it('covers none', async
function() {
994 const expected
= undefined;
995 sinon
.stub(db
.statement
.topicGetInfoAll
, 'all').returns(expected
);
996 const result
= await db
.topicGetAll(dbCtx
);
997 assert
.deepStrictEqual(result
, expected
);
999 it('failure', async
function () {
1000 const expected
= new Error();
1001 sinon
.stub(db
.statement
.topicGetInfoAll
, 'all').throws(expected
);
1003 await db
.topicGetAll(dbCtx
);
1004 assert
.fail(noExpectedException
);
1006 assert
.deepStrictEqual(e
, expected
);
1011 describe('topicGetById', function () {
1012 it('success', async
function() {
1013 const expected
= { id: topicId
};
1014 sinon
.stub(db
.statement
.topicGetById
, 'get').returns(expected
);
1015 const result
= await db
.topicGetById(dbCtx
, topicId
);
1016 assert
.deepStrictEqual(result
, expected
);
1018 it('covers no defaults', async
function () {
1019 const expected
= { id: topicId
};
1020 sinon
.stub(db
.statement
.topicGetById
, 'get').returns(expected
);
1021 const result
= await db
.topicGetById(dbCtx
, topicId
, false);
1022 assert
.deepStrictEqual(result
, expected
);
1024 it('covers default', async
function() {
1025 const expected
= undefined;
1026 sinon
.stub(db
.statement
.topicGetById
, 'get').returns(expected
);
1027 const result
= await db
.topicGetById(dbCtx
, topicId
);
1028 assert
.deepStrictEqual(result
, expected
);
1030 it('failure', async
function () {
1031 const expected
= new Error();
1032 sinon
.stub(db
.statement
.topicGetById
, 'get').throws(expected
);
1034 await db
.topicGetById(dbCtx
, topicId
);
1035 assert
.fail(noExpectedException
);
1037 assert
.deepStrictEqual(e
, expected
);
1042 describe('topicGetByUrl', function () {
1043 it('success', async
function() {
1044 const expected
= [];
1045 sinon
.stub(db
.statement
.topicGetByUrl
, 'get').returns(expected
);
1046 const result
= await db
.topicGetByUrl(dbCtx
, topicUrl
);
1047 assert
.deepStrictEqual(result
, expected
);
1049 it('failure', async
function () {
1050 const expected
= new Error();
1051 sinon
.stub(db
.statement
.topicGetByUrl
, 'get').throws(expected
);
1053 await db
.topicGetByUrl(dbCtx
, topicUrl
);
1054 assert
.fail(noExpectedException
);
1056 assert
.deepStrictEqual(e
, expected
);
1059 }); // topicGetByUrl
1061 describe('topicGetContentById', function () {
1062 it('success', async
function() {
1063 const expected
= { id: topicId
};
1064 sinon
.stub(db
.statement
.topicGetContentById
, 'get').returns(expected
);
1065 const result
= await db
.topicGetContentById(dbCtx
, topicId
);
1066 assert
.deepStrictEqual(result
, expected
);
1068 it('covers default', async
function() {
1069 const expected
= undefined;
1070 sinon
.stub(db
.statement
.topicGetContentById
, 'get').returns(expected
);
1071 const result
= await db
.topicGetContentById(dbCtx
, topicId
);
1072 assert
.deepStrictEqual(result
, expected
);
1074 it('failure', async
function () {
1075 const expected
= new Error();
1076 sinon
.stub(db
.statement
.topicGetContentById
, 'get').throws(expected
);
1078 await db
.topicGetContentById(dbCtx
, topicId
);
1079 assert
.fail(noExpectedException
);
1081 assert
.deepStrictEqual(e
, expected
);
1084 }); // topicGetContentById
1086 describe('topicPendingDelete', function () {
1087 beforeEach(function () {
1088 sinon
.stub(db
.statement
.topicGetById
, 'get');
1089 sinon
.stub(db
.statement
.subscriptionCountByTopicUrl
, 'get');
1090 sinon
.stub(db
.statement
.topicDeleteById
, 'run');
1092 it('success', async
function () {
1093 db
.statement
.topicGetById
.get.returns({
1097 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1100 db
.statement
.topicDeleteById
.run
.returns({
1103 db
.topicPendingDelete(dbCtx
, topicId
);
1104 assert(db
.statement
.topicDeleteById
.run
.called
);
1106 it('does not delete non-deleted topic', async
function () {
1107 db
.statement
.topicGetById
.get.returns({
1111 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1114 db
.statement
.topicDeleteById
.run
.returns({
1117 db
.topicPendingDelete(dbCtx
, topicId
);
1118 assert(!db
.statement
.topicDeleteById
.run
.called
);
1120 it('does not delete topic with active subscriptions', async
function () {
1121 db
.statement
.topicGetById
.get.returns({
1125 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1128 db
.statement
.topicDeleteById
.run
.returns({
1131 db
.topicPendingDelete(dbCtx
, topicId
);
1132 assert(!db
.statement
.topicDeleteById
.run
.called
);
1134 it('covers no deletion', async
function () {
1135 db
.statement
.topicGetById
.get.returns({
1139 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1142 db
.statement
.topicDeleteById
.run
.returns({
1146 db
.topicPendingDelete(dbCtx
, topicId
);
1147 assert
.fail(noExpectedException
);
1150 assert(e
instanceof DBErrors
.UnexpectedResult
);
1152 assert(db
.statement
.topicDeleteById
.run
.called
);
1154 }); // topicPendingDelete
1156 describe('topicPublishHistory', function () {
1157 beforeEach(function () {
1158 sinon
.stub(db
.statement
.topicPublishHistory
, 'all');
1160 it('success', function () {
1161 db
.statement
.topicPublishHistory
.all
.returns([
1162 { daysAgo: 1, contentUpdates: 1 },
1163 { daysAgo: 3, contentUpdates: 2 },
1165 const result
= db
.topicPublishHistory(dbCtx
, topicId
, 7);
1166 const expected
= [0, 1, 0, 2, 0, 0, 0];
1167 assert
.deepStrictEqual(result
, expected
);
1169 }); // topicPublishHistory
1171 describe('topicSet', function () {
1173 beforeEach(function () {
1178 it('success', async
function() {
1181 lastInsertRowid: topicId
,
1185 lastInsertRowid: topicId
,
1187 sinon
.stub(db
.statement
.topicUpsert
, 'run').returns(dbResult
);
1188 const result
= await db
.topicSet(dbCtx
, data
);
1189 assert
.deepStrictEqual(result
, expected
);
1191 it('failure', async
function () {
1194 lastInsertRowid: undefined,
1196 sinon
.stub(db
.statement
.topicUpsert
, 'run').returns(dbResult
);
1198 await db
.topicSet(dbCtx
, data
);
1199 assert
.fail(noExpectedException
);
1201 assert(e
instanceof DBErrors
.UnexpectedResult
);
1204 it('fails invalid value', async
function () {
1205 sinon
.stub(db
.statement
.topicUpsert
, 'run');
1207 data
.leaseSecondsPreferred
= -100;
1208 await db
.topicSet(dbCtx
, data
);
1209 assert
.fail(noExpectedException
);
1211 assert(e
instanceof DBErrors
.DataValidation
);
1213 assert(!db
.statement
.topicUpsert
.run
.called
);
1215 it('fails invalid values', async
function () {
1216 sinon
.stub(db
.statement
.topicUpsert
, 'run');
1218 data
.leaseSecondsPreferred
= 10;
1219 data
.leaseSecondsMax
= 100;
1220 data
.leaseSecondsMin
= 50;
1221 await db
.topicSet(dbCtx
, data
);
1222 assert
.fail(noExpectedException
);
1224 assert(e
instanceof DBErrors
.DataValidation
);
1226 assert(!db
.statement
.topicUpsert
.run
.called
);
1230 describe('topicSetContent', function () {
1232 beforeEach(function () {
1235 contentType: 'text/plain',
1236 contentHash: 'abc123',
1238 sinon
.stub(db
.statement
.topicSetContent
, 'run');
1239 sinon
.stub(db
.statement
.topicSetContentHistory
, 'run');
1241 it('success', async
function() {
1244 lastInsertRowid: undefined,
1248 lastInsertRowid: undefined,
1250 db
.statement
.topicSetContent
.run
.returns(dbResult
);
1251 db
.statement
.topicSetContentHistory
.run
.returns(dbResult
);
1252 const result
= await db
.topicSetContent(dbCtx
, data
);
1253 assert
.deepStrictEqual(result
, expected
);
1255 it('failure', async
function () {
1258 lastInsertRowid: undefined,
1260 db
.statement
.topicSetContent
.run
.returns(dbResult
);
1262 await db
.topicSetContent(dbCtx
, data
);
1263 assert
.fail(noExpectedException
);
1265 assert(e
instanceof DBErrors
.UnexpectedResult
);
1268 it('failure 2', async
function () {
1269 const dbResultSuccess
= {
1271 lastInsertRowid: undefined,
1273 const dbResultFail
= {
1275 lastInsertRowid: undefined,
1277 db
.statement
.topicSetContent
.run
.returns(dbResultSuccess
);
1278 db
.statement
.topicSetContentHistory
.run
.returns(dbResultFail
);
1280 await db
.topicSetContent(dbCtx
, data
);
1281 assert
.fail(noExpectedException
);
1283 assert(e
instanceof DBErrors
.UnexpectedResult
);
1286 }); // topicSetContent
1288 describe('topicUpdate', function () {
1290 beforeEach(function () {
1293 leaseSecondsPreferred: 9999,
1294 leaseSecondsMax: 99999,
1295 leaseSecondsMin: 999,
1296 publisherValidationUrl: null,
1297 contentHashAlgorithm: 'sha256',
1300 it('success', async
function() {
1303 lastInsertRowid: topicId
,
1305 sinon
.stub(db
.statement
.topicUpdate
, 'run').returns(dbResult
);
1306 await db
.topicUpdate(dbCtx
, data
);
1308 it('failure', async
function () {
1311 lastInsertRowid: undefined,
1313 sinon
.stub(db
.statement
.topicUpdate
, 'run').returns(dbResult
);
1315 await db
.topicUpdate(dbCtx
, data
);
1316 assert
.fail(noExpectedException
);
1318 assert(e
instanceof DBErrors
.UnexpectedResult
, e
);
1321 it('fails invalid value', async
function () {
1322 sinon
.stub(db
.statement
.topicUpdate
, 'run');
1324 data
.leaseSecondsPreferred
= -100;
1325 await db
.topicUpdate(dbCtx
, data
);
1326 assert
.fail(noExpectedException
);
1328 assert(e
instanceof DBErrors
.DataValidation
, e
);
1330 assert(!db
.statement
.topicUpdate
.run
.called
);
1332 it('fails invalid values', async
function () {
1333 sinon
.stub(db
.statement
.topicUpdate
, 'run');
1335 data
.leaseSecondsPreferred
= 10;
1336 data
.leaseSecondsMax
= 100;
1337 data
.leaseSecondsMin
= 50;
1338 await db
.topicUpdate(dbCtx
, data
);
1339 assert
.fail(noExpectedException
);
1341 assert(e
instanceof DBErrors
.DataValidation
, e
);
1343 assert(!db
.statement
.topicUpdate
.run
.called
);
1347 describe('verificationClaim', function () {
1348 it('success', async
function() {
1349 const dbAll
= [{ id: verificationId
}];
1352 lastInsertRowid: undefined,
1354 const expected
= [verificationId
];
1355 sinon
.stub(db
.statement
.verificationNeeded
, 'all').returns(dbAll
);
1356 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1357 const result
= await db
.verificationClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
1358 assert
.deepStrictEqual(result
, expected
);
1360 it('failure', async
function () {
1361 const dbAll
= [{ id: verificationId
}];
1364 lastInsertRowid: undefined,
1366 sinon
.stub(db
.statement
.verificationNeeded
, 'all').returns(dbAll
);
1367 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1369 await db
.verificationClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
1370 assert
.fail(noExpectedException
);
1372 assert(e
instanceof DBErrors
.UnexpectedResult
);
1375 }); // verificationClaim
1377 describe('verificationClaimById', function () {
1378 it('success', async
function() {
1381 lastInsertRowid: undefined,
1383 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1384 const result
= await db
.verificationClaimById(dbCtx
, verificationId
, claimTimeoutSeconds
, claimant
);
1385 assert
.deepStrictEqual(result
, dbRun
);
1387 it('failure', async
function () {
1390 lastInsertRowid: undefined,
1392 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1394 await db
.verificationClaimById(dbCtx
, verificationId
, claimTimeoutSeconds
, claimant
);
1395 assert
.fail(noExpectedException
);
1397 assert(e
instanceof DBErrors
.UnexpectedResult
);
1400 }); // verificationClaimById
1402 describe('verificationComplete', function () {
1403 it('success', async
function() {
1406 lastInsertRowid: undefined,
1408 sinon
.stub(db
.statement
.verificationScrub
, 'run').returns(dbResult
);
1409 await db
.verificationComplete(dbCtx
, verificationId
, callback
, topicId
);
1411 it('failure', async
function () {
1414 lastInsertRowid: undefined,
1416 sinon
.stub(db
.statement
.verificationScrub
, 'run').returns(dbResult
);
1418 await db
.verificationComplete(dbCtx
, verificationId
, callback
, topicId
);
1419 assert
.fail(noExpectedException
);
1421 assert(e
instanceof DBErrors
.UnexpectedResult
);
1424 }); // verificationComplete
1426 describe('verificationGetById', function () {
1427 it('success', async
function() {
1428 const dbOneOrNone
= { id: verificationId
, isPublisherValidated: 1 };
1429 const expected
= { id: verificationId
, isPublisherValidated: true };
1430 sinon
.stub(db
.statement
.verificationGetById
, 'get').returns(dbOneOrNone
);
1431 const result
= await db
.verificationGetById(dbCtx
, verificationId
);
1432 assert
.deepStrictEqual(result
, expected
);
1434 it('failure', async
function () {
1435 const expected
= new Error();
1436 sinon
.stub(db
.statement
.verificationGetById
, 'get').throws(expected
);
1438 await db
.verificationGetById(dbCtx
, verificationId
);
1439 assert
.fail(noExpectedException
);
1441 assert
.deepStrictEqual(e
, expected
);
1444 }); // verificationGetById
1446 describe('verificationIncomplete', function () {
1447 it('success', async
function() {
1448 const dbOne
= { attempts: 0 };
1451 lastInsertRowid: undefined,
1455 lastInsertRowid: undefined,
1457 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1458 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1459 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1460 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1462 it('covers defaults', async
function() {
1463 const dbOne
= { attempts: 0 };
1466 lastInsertRowid: undefined,
1470 lastInsertRowid: undefined,
1472 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1473 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1474 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1475 await db
.verificationIncomplete(dbCtx
, verificationId
);
1477 it('failure', async
function () {
1478 const dbOne
= { attempts: 0 };
1481 lastInsertRowid: undefined,
1485 lastInsertRowid: undefined,
1487 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1488 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1489 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1491 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1492 assert
.fail(noExpectedException
);
1494 assert(e
instanceof DBErrors
.UnexpectedResult
);
1497 it('second failure', async
function () {
1498 const dbOne
= { attempts: 0 };
1501 lastInsertRowid: undefined,
1505 lastInsertRowid: undefined,
1507 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1508 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1509 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1511 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1512 assert
.fail(noExpectedException
);
1514 assert(e
instanceof DBErrors
.UnexpectedResult
);
1517 }); // verificationIncomplete
1519 describe('_verificationDataToEngine', function () {
1520 it('covers no data', function () {
1521 DB
._verificationDataToEngine();
1523 it('covers true', function () {
1525 isPublisherValidated: true,
1527 DB
._verificationDataToEngine(data
);
1528 assert
.strictEqual(data
.isPublisherValidated
, 1);
1530 it('covers false', function () {
1532 isPublisherValidated: false,
1534 DB
._verificationDataToEngine(data
);
1535 assert
.strictEqual(data
.isPublisherValidated
, 0);
1537 }) // _verificationDataToEngine
1539 describe('verificationInsert', function () {
1541 beforeEach(function () {
1546 isPublisherValidated: true,
1547 leaseSeconds: 86400,
1550 it('success', async
function() {
1553 lastInsertRowid: verificationId
,
1555 const expected
= verificationId
;
1556 sinon
.stub(db
.statement
.verificationInsert
, 'run').returns(dbResult
);
1557 const result
= await db
.verificationInsert(dbCtx
, verification
);
1558 assert
.deepStrictEqual(result
, expected
);
1560 it('failure', async
function () {
1563 lastInsertRowid: undefined,
1565 sinon
.stub(db
.statement
.verificationInsert
, 'run').returns(dbResult
);
1567 await db
.verificationInsert(dbCtx
, verification
);
1568 assert
.fail(noExpectedException
);
1570 assert(e
instanceof DBErrors
.UnexpectedResult
);
1573 it('fails validation', async
function () {
1574 delete verification
.leaseSeconds
;
1576 await db
.verificationInsert(dbCtx
, verification
);
1577 assert
.fail(noExpectedException
);
1579 assert(e
instanceof DBErrors
.DataValidation
);
1582 }); // verificationInsert
1584 describe('verificationRelease', function () {
1585 it('success', async
function() {
1588 lastInsertRowid: undefined,
1590 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult
);
1591 await db
.verificationRelease(dbCtx
, verificationId
);
1593 it('failure', async
function () {
1596 lastInsertRowid: undefined,
1598 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult
);
1600 await db
.verificationRelease(dbCtx
, verificationId
);
1601 assert
.fail(noExpectedException
);
1603 assert(e
instanceof DBErrors
.UnexpectedResult
);
1606 }); // verificationRelease
1608 describe('verificationUpdate', function () {
1610 beforeEach(function () {
1613 isPublisherValidated: true,
1616 it('success', async
function() {
1619 lastInsertRowid: undefined,
1621 sinon
.stub(db
.statement
.verificationUpdate
, 'run').returns(dbResult
);
1622 await db
.verificationUpdate(dbCtx
, verificationId
, data
);
1624 it('failure', async
function () {
1627 lastInsertRowid: undefined,
1629 sinon
.stub(db
.statement
.verificationUpdate
, 'run').returns(dbResult
);
1631 await db
.verificationUpdate(dbCtx
, verificationId
, data
);
1632 assert
.fail(noExpectedException
);
1634 assert(e
instanceof DBErrors
.UnexpectedResult
, e
.name
);
1637 it('fails validation', async
function () {
1640 await db
.verificationUpdate(dbCtx
, data
);
1641 assert
.fail(noExpectedException
);
1643 assert(e
instanceof DBErrors
.DataValidation
);
1646 }); // verificationUpdate
1648 describe('verificationValidated', function () {
1649 it('success', async
function() {
1652 lastInsertRowid: undefined,
1654 sinon
.stub(db
.statement
.verificationValidate
, 'run').returns(dbResult
);
1655 await db
.verificationValidated(dbCtx
, verificationId
);
1657 it('failure', async
function () {
1660 lastInsertRowid: undefined,
1662 sinon
.stub(db
.statement
.verificationValidate
, 'run').returns(dbResult
);
1664 await db
.verificationValidated(dbCtx
, verificationId
);
1665 assert
.fail(noExpectedException
);
1667 assert(e
instanceof DBErrors
.UnexpectedResult
);
1670 }); // verificationValidated
1672 }); // DatabaseSQLite