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
);
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
);
1156 describe('topicSet', function () {
1158 beforeEach(function () {
1163 it('success', async
function() {
1166 lastInsertRowid: topicId
,
1170 lastInsertRowid: topicId
,
1172 sinon
.stub(db
.statement
.topicUpsert
, 'run').returns(dbResult
);
1173 const result
= await db
.topicSet(dbCtx
, data
);
1174 assert
.deepStrictEqual(result
, expected
);
1176 it('failure', async
function () {
1179 lastInsertRowid: undefined,
1181 sinon
.stub(db
.statement
.topicUpsert
, 'run').returns(dbResult
);
1183 await db
.topicSet(dbCtx
, data
);
1184 assert
.fail(noExpectedException
);
1186 assert(e
instanceof DBErrors
.UnexpectedResult
);
1189 it('fails invalid value', async
function () {
1190 sinon
.stub(db
.statement
.topicUpsert
, 'run');
1192 data
.leaseSecondsPreferred
= -100;
1193 await db
.topicSet(dbCtx
, data
);
1194 assert
.fail(noExpectedException
);
1196 assert(e
instanceof DBErrors
.DataValidation
);
1198 assert(!db
.statement
.topicUpsert
.run
.called
);
1200 it('fails invalid values', async
function () {
1201 sinon
.stub(db
.statement
.topicUpsert
, 'run');
1203 data
.leaseSecondsPreferred
= 10;
1204 data
.leaseSecondsMax
= 100;
1205 data
.leaseSecondsMin
= 50;
1206 await db
.topicSet(dbCtx
, data
);
1207 assert
.fail(noExpectedException
);
1209 assert(e
instanceof DBErrors
.DataValidation
);
1211 assert(!db
.statement
.topicUpsert
.run
.called
);
1215 describe('topicSetContent', function () {
1217 beforeEach(function () {
1220 contentType: 'text/plain',
1221 contentHash: 'abc123',
1224 it('success', async
function() {
1227 lastInsertRowid: undefined,
1231 lastInsertRowid: undefined,
1233 sinon
.stub(db
.statement
.topicSetContent
, 'run').returns(dbResult
);
1234 const result
= await db
.topicSetContent(dbCtx
, data
);
1235 assert
.deepStrictEqual(result
, expected
);
1237 it('failure', async
function () {
1240 lastInsertRowid: undefined,
1242 sinon
.stub(db
.statement
.topicSetContent
, 'run').returns(dbResult
);
1244 await db
.topicSetContent(dbCtx
, data
);
1245 assert
.fail(noExpectedException
);
1247 assert(e
instanceof DBErrors
.UnexpectedResult
);
1250 }); // topicSetContent
1252 describe('topicUpdate', function () {
1254 beforeEach(function () {
1257 leaseSecondsPreferred: 9999,
1258 leaseSecondsMax: 99999,
1259 leaseSecondsMin: 999,
1260 publisherValidationUrl: null,
1261 contentHashAlgorithm: 'sha256',
1264 it('success', async
function() {
1267 lastInsertRowid: topicId
,
1269 sinon
.stub(db
.statement
.topicUpdate
, 'run').returns(dbResult
);
1270 await db
.topicUpdate(dbCtx
, data
);
1272 it('failure', async
function () {
1275 lastInsertRowid: undefined,
1277 sinon
.stub(db
.statement
.topicUpdate
, 'run').returns(dbResult
);
1279 await db
.topicUpdate(dbCtx
, data
);
1280 assert
.fail(noExpectedException
);
1282 assert(e
instanceof DBErrors
.UnexpectedResult
, e
);
1285 it('fails invalid value', async
function () {
1286 sinon
.stub(db
.statement
.topicUpdate
, 'run');
1288 data
.leaseSecondsPreferred
= -100;
1289 await db
.topicUpdate(dbCtx
, data
);
1290 assert
.fail(noExpectedException
);
1292 assert(e
instanceof DBErrors
.DataValidation
, e
);
1294 assert(!db
.statement
.topicUpdate
.run
.called
);
1296 it('fails invalid values', async
function () {
1297 sinon
.stub(db
.statement
.topicUpdate
, 'run');
1299 data
.leaseSecondsPreferred
= 10;
1300 data
.leaseSecondsMax
= 100;
1301 data
.leaseSecondsMin
= 50;
1302 await db
.topicUpdate(dbCtx
, data
);
1303 assert
.fail(noExpectedException
);
1305 assert(e
instanceof DBErrors
.DataValidation
, e
);
1307 assert(!db
.statement
.topicUpdate
.run
.called
);
1311 describe('verificationClaim', function () {
1312 it('success', async
function() {
1313 const dbAll
= [{ id: verificationId
}];
1316 lastInsertRowid: undefined,
1318 const expected
= [verificationId
];
1319 sinon
.stub(db
.statement
.verificationNeeded
, 'all').returns(dbAll
);
1320 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1321 const result
= await db
.verificationClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
1322 assert
.deepStrictEqual(result
, expected
);
1324 it('failure', async
function () {
1325 const dbAll
= [{ id: verificationId
}];
1328 lastInsertRowid: undefined,
1330 sinon
.stub(db
.statement
.verificationNeeded
, 'all').returns(dbAll
);
1331 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1333 await db
.verificationClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
1334 assert
.fail(noExpectedException
);
1336 assert(e
instanceof DBErrors
.UnexpectedResult
);
1339 }); // verificationClaim
1341 describe('verificationClaimById', function () {
1342 it('success', async
function() {
1345 lastInsertRowid: undefined,
1347 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1348 const result
= await db
.verificationClaimById(dbCtx
, verificationId
, claimTimeoutSeconds
, claimant
);
1349 assert
.deepStrictEqual(result
, dbRun
);
1351 it('failure', async
function () {
1354 lastInsertRowid: undefined,
1356 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1358 await db
.verificationClaimById(dbCtx
, verificationId
, claimTimeoutSeconds
, claimant
);
1359 assert
.fail(noExpectedException
);
1361 assert(e
instanceof DBErrors
.UnexpectedResult
);
1364 }); // verificationClaimById
1366 describe('verificationComplete', function () {
1367 it('success', async
function() {
1370 lastInsertRowid: undefined,
1372 sinon
.stub(db
.statement
.verificationScrub
, 'run').returns(dbResult
);
1373 await db
.verificationComplete(dbCtx
, verificationId
, callback
, topicId
);
1375 it('failure', async
function () {
1378 lastInsertRowid: undefined,
1380 sinon
.stub(db
.statement
.verificationScrub
, 'run').returns(dbResult
);
1382 await db
.verificationComplete(dbCtx
, verificationId
, callback
, topicId
);
1383 assert
.fail(noExpectedException
);
1385 assert(e
instanceof DBErrors
.UnexpectedResult
);
1388 }); // verificationComplete
1390 describe('verificationGetById', function () {
1391 it('success', async
function() {
1392 const dbOneOrNone
= { id: verificationId
, isPublisherValidated: 1 };
1393 const expected
= { id: verificationId
, isPublisherValidated: true };
1394 sinon
.stub(db
.statement
.verificationGetById
, 'get').returns(dbOneOrNone
);
1395 const result
= await db
.verificationGetById(dbCtx
, verificationId
);
1396 assert
.deepStrictEqual(result
, expected
);
1398 it('failure', async
function () {
1399 const expected
= new Error();
1400 sinon
.stub(db
.statement
.verificationGetById
, 'get').throws(expected
);
1402 await db
.verificationGetById(dbCtx
, verificationId
);
1403 assert
.fail(noExpectedException
);
1405 assert
.deepStrictEqual(e
, expected
);
1408 }); // verificationGetById
1410 describe('verificationIncomplete', function () {
1411 it('success', async
function() {
1412 const dbOne
= { attempts: 0 };
1415 lastInsertRowid: undefined,
1419 lastInsertRowid: undefined,
1421 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1422 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1423 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1424 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1426 it('covers defaults', async
function() {
1427 const dbOne
= { attempts: 0 };
1430 lastInsertRowid: undefined,
1434 lastInsertRowid: undefined,
1436 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1437 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1438 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1439 await db
.verificationIncomplete(dbCtx
, verificationId
);
1441 it('failure', async
function () {
1442 const dbOne
= { attempts: 0 };
1445 lastInsertRowid: undefined,
1449 lastInsertRowid: undefined,
1451 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1452 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1453 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1455 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1456 assert
.fail(noExpectedException
);
1458 assert(e
instanceof DBErrors
.UnexpectedResult
);
1461 it('second failure', async
function () {
1462 const dbOne
= { attempts: 0 };
1465 lastInsertRowid: undefined,
1469 lastInsertRowid: undefined,
1471 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1472 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1473 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1475 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1476 assert
.fail(noExpectedException
);
1478 assert(e
instanceof DBErrors
.UnexpectedResult
);
1481 }); // verificationIncomplete
1483 describe('_verificationDataToEngine', function () {
1484 it('covers no data', function () {
1485 DB
._verificationDataToEngine();
1487 it('covers true', function () {
1489 isPublisherValidated: true,
1491 DB
._verificationDataToEngine(data
);
1492 assert
.strictEqual(data
.isPublisherValidated
, 1);
1494 it('covers false', function () {
1496 isPublisherValidated: false,
1498 DB
._verificationDataToEngine(data
);
1499 assert
.strictEqual(data
.isPublisherValidated
, 0);
1501 }) // _verificationDataToEngine
1503 describe('verificationInsert', function () {
1505 beforeEach(function () {
1510 isPublisherValidated: true,
1511 leaseSeconds: 86400,
1514 it('success', async
function() {
1517 lastInsertRowid: verificationId
,
1519 const expected
= verificationId
;
1520 sinon
.stub(db
.statement
.verificationInsert
, 'run').returns(dbResult
);
1521 const result
= await db
.verificationInsert(dbCtx
, verification
);
1522 assert
.deepStrictEqual(result
, expected
);
1524 it('failure', async
function () {
1527 lastInsertRowid: undefined,
1529 sinon
.stub(db
.statement
.verificationInsert
, 'run').returns(dbResult
);
1531 await db
.verificationInsert(dbCtx
, verification
);
1532 assert
.fail(noExpectedException
);
1534 assert(e
instanceof DBErrors
.UnexpectedResult
);
1537 it('fails validation', async
function () {
1538 delete verification
.leaseSeconds
;
1540 await db
.verificationInsert(dbCtx
, verification
);
1541 assert
.fail(noExpectedException
);
1543 assert(e
instanceof DBErrors
.DataValidation
);
1546 }); // verificationInsert
1548 describe('verificationRelease', function () {
1549 it('success', async
function() {
1552 lastInsertRowid: undefined,
1554 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult
);
1555 await db
.verificationRelease(dbCtx
, verificationId
);
1557 it('failure', async
function () {
1560 lastInsertRowid: undefined,
1562 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult
);
1564 await db
.verificationRelease(dbCtx
, verificationId
);
1565 assert
.fail(noExpectedException
);
1567 assert(e
instanceof DBErrors
.UnexpectedResult
);
1570 }); // verificationRelease
1572 describe('verificationUpdate', function () {
1574 beforeEach(function () {
1577 isPublisherValidated: true,
1580 it('success', async
function() {
1583 lastInsertRowid: undefined,
1585 sinon
.stub(db
.statement
.verificationUpdate
, 'run').returns(dbResult
);
1586 await db
.verificationUpdate(dbCtx
, verificationId
, data
);
1588 it('failure', async
function () {
1591 lastInsertRowid: undefined,
1593 sinon
.stub(db
.statement
.verificationUpdate
, 'run').returns(dbResult
);
1595 await db
.verificationUpdate(dbCtx
, verificationId
, data
);
1596 assert
.fail(noExpectedException
);
1598 assert(e
instanceof DBErrors
.UnexpectedResult
, e
.name
);
1601 it('fails validation', async
function () {
1604 await db
.verificationUpdate(dbCtx
, data
);
1605 assert
.fail(noExpectedException
);
1607 assert(e
instanceof DBErrors
.DataValidation
);
1610 }); // verificationUpdate
1612 describe('verificationValidated', function () {
1613 it('success', async
function() {
1616 lastInsertRowid: undefined,
1618 sinon
.stub(db
.statement
.verificationValidate
, 'run').returns(dbResult
);
1619 await db
.verificationValidated(dbCtx
, verificationId
);
1621 it('failure', async
function () {
1624 lastInsertRowid: undefined,
1626 sinon
.stub(db
.statement
.verificationValidate
, 'run').returns(dbResult
);
1628 await db
.verificationValidated(dbCtx
, verificationId
);
1629 assert
.fail(noExpectedException
);
1631 assert(e
instanceof DBErrors
.UnexpectedResult
);
1634 }); // verificationValidated
1636 }); // DatabaseSQLite