3 /* This provides implementation coverage, stubbing parts of better-sqlite3. */
5 const assert
= require('node:assert');
6 const sinon
= require('sinon');
7 const DBStub
= require('../../stub-db');
8 const stubLogger
= require('../../stub-logger');
9 const DB
= require('../../../src/db/sqlite');
10 const DBErrors
= require('../../../src/db/errors');
11 const common
= require('../../../src/common');
12 const Config
= require('../../../config');
14 const noExpectedException
= 'did not receive expected exception';
16 describe('DatabaseSQLite', function () {
18 let dbCtx
, claimant
, claimTimeoutSeconds
, callback
, subscriptionId
, topicId
, verificationId
;
19 let topicUrl
, leaseSeconds
, secret
, httpRemoteAddr
, httpFrom
, retryDelays
, wanted
;
21 options
= new Config('test');
22 options
.db
.connectionString
= 'sqlite://:memory:';
23 db
= new DB(stubLogger
, options
);
25 beforeEach(function () {
28 claimant
= '19af19b8-6be3-4a6f-8946-65f5f1ccc5d7';
29 claimTimeoutSeconds
= 300;
30 subscriptionId
= 'fbaf8f19-ed9c-4a21-89ae-98b7005e3bf6';
31 topicUrl
= 'https://example.com/blog';
32 callback
= 'https://example.com/callback?id=123';
33 topicId
= 'c59d4bda-10ad-41d9-99df-4ce8bc331424';
34 verificationId
= '55cd7748-d2d5-11eb-b355-0025905f714a';
38 httpRemoteAddr
= '127.0.0.1';
39 httpFrom
= 'user@example.com';
42 afterEach(function () {
46 // Ensure all interface methods are implemented
47 describe('Implementation', function () {
48 it('implements interface', async
function () {
49 const results
= await Promise
.allSettled(DBStub
._implementation
.map(async (fn
) => {
51 // eslint-disable-next-line security/detect-object-injection
54 assert(!(e
instanceof DBErrors
.NotImplemented
), `${fn} not implemented`);
57 const failures
= results
.filter((x
) => x
.status
=== 'rejected');
58 assert(!failures
.length
, failures
.map((x
) => {
59 x
= x
.reason
.toString();
60 return x
.slice(x
.indexOf(': '));
65 describe('_initTables', function () {
67 beforeEach(function () {
68 preparedGet
= sinon
.stub();
69 sinon
.stub(db
.db
, 'prepare').returns({
76 sinon
.stub(db
, '_currentSchema').returns(db
.schemaVersionsSupported
.min
);
77 sinon
.stub(db
.db
, 'exec');
79 it('covers migration', async
function() {
80 preparedGet
.returns({});
81 await db
._initTables();
82 assert(db
.db
.exec
.called
);
84 it('covers migration failure', async
function() {
85 const expected
= new Error('oh no');
86 preparedGet
.returns({});
87 db
.db
.exec
.throws(expected
);
89 await db
._initTables();
90 assert
.fail(noExpectedException
);
92 assert
.deepStrictEqual(e
, expected
);
97 describe('_currentSchema', function () {
98 it('covers', async
function () {
99 const version
= { major: 1, minor: 0, patch: 0 };
100 sinon
.stub(db
.db
, 'prepare').returns({
103 const result
= await db
._currentSchema();
104 assert
.deepStrictEqual(result
, version
);
106 }); // _currentSchema
108 describe('_closeConnection', function () {
109 it('success', async
function () {
110 sinon
.stub(db
.db
, 'close');
111 await db
._closeConnection();
112 assert(db
.db
.close
.called
);
114 it('failure', async
function () {
115 const expected
= new Error();
116 sinon
.stub(db
.db
, 'close').throws(expected
);
118 await db
._closeConnection();
119 assert
.fail(noExpectedException
);
121 assert
.deepStrictEqual(e
, expected
);
124 }); // _closeConnection
126 describe('_purgeTables', function () {
127 beforeEach(function () {
128 sinon
.stub(db
.db
, 'prepare').returns({
132 it('covers not really', async
function () {
133 await db
._purgeTables(false);
134 assert(!db
.db
.prepare
.called
);
136 it('success', async
function () {
137 await db
._purgeTables(true);
138 assert(db
.db
.prepare
.called
);
140 it('failure', async
function () {
141 const expected
= new Error();
142 db
.db
.prepare
.restore();
143 sinon
.stub(db
.db
, 'prepare').throws(expected
);
145 await db
._purgeTables(true);
146 assert
.fail(noExpectedException
);
148 assert
.deepStrictEqual(e
, expected
);
153 describe('_optimize', function () {
155 beforeEach(function () {
156 origOAC
= db
.optimizeAfterChanges
;
157 sinon
.stub(db
.statement
._optimize
, 'all');
158 sinon
.stub(db
.db
, 'pragma');
160 this.afterEach(function () {
161 db
.optimizeAfterChanges
= origOAC
;
163 it('covers', async
function () {
164 db
.optimizeAfterChanges
= 10;
165 db
.changesSinceLastOptimize
= BigInt(20);
166 await db
._optimize();
167 assert(db
.db
.pragma
.called
);
169 it('covers none', async
function () {
170 db
.optimizeAfterChanges
= 0;
171 await db
._optimize();
172 assert(!db
.db
.pragma
.called
);
174 it('covers not enough changes', async
function () {
175 db
.optimizeAfterChanges
= 10;
176 db
.changesSinceLastOptimize
= BigInt(5);
177 await db
._optimize();
178 assert(!db
.db
.pragma
.called
);
182 describe('_deOphidiate', function () {
183 it('covers non-array', function () {
190 const result
= DB
._deOphidiate(obj
);
191 assert
.deepStrictEqual(result
, expected
);
193 it('covers array', function () {
210 const result
= DB
._deOphidiate(rows
);
211 assert
.deepStrictEqual(result
, expected
);
215 describe('_topicDataToNative', function () {
216 it('covers', function () {
217 const now
= new Date();
218 const nowEpoch
= now
.getTime() / 1000;
223 lastPublish: nowEpoch
,
224 contentFetchNextAttempt: nowEpoch
,
225 contentUpdated: nowEpoch
,
226 url: 'https://example.com/',
233 contentFetchNextAttempt: now
,
237 const result
= DB
._topicDataToNative(topic
);
238 assert
.deepStrictEqual(result
, expected
);
240 it('covers empty', function () {
241 const topic
= undefined;
242 const result
= DB
._topicDataToNative(topic
);
243 assert
.deepStrictEqual(result
, topic
);
245 }); // _topicDataToNative
247 describe('healthCheck', function () {
249 beforeEach(function () {
252 afterEach(function () {
255 it('covers', function () {
258 it('covers failure', function () {
259 db
.db
= { open: false };
262 assert
.fail(noExpectedException
);
264 assert(e
instanceof DBErrors
.UnexpectedResult
);
269 describe('context', function () {
270 it('covers', async
function () {
271 await db
.context(common
.nop
);
275 describe('transaction', function () {
276 it('covers', async
function () {
277 await db
.transaction(db
.db
, common
.nop
);
279 it('covers no context', async
function () {
280 await db
.transaction(undefined, common
.nop
);
284 describe('authenticationSuccess', function () {
286 beforeEach(function () {
287 identifier
= 'username';
289 it('success', async
function() {
292 lastInsertRowid: undefined,
294 sinon
.stub(db
.statement
.authenticationSuccess
, 'run').returns(dbResult
);
295 await db
.authenticationSuccess(dbCtx
, identifier
);
297 it('failure', async
function () {
300 lastInsertRowid: undefined,
302 sinon
.stub(db
.statement
.authenticationSuccess
, 'run').returns(dbResult
);
304 await db
.authenticationSuccess(dbCtx
, identifier
);
305 assert
.fail(noExpectedException
);
307 assert(e
instanceof DBErrors
.UnexpectedResult
);
310 }); // authenticationSuccess
312 describe('authenticationGet', function () {
313 let identifier
, credential
;
314 beforeEach(function () {
315 identifier
= 'username';
316 credential
= '$z$foo';
318 it('success', async
function() {
323 sinon
.stub(db
.statement
.authenticationGet
, 'get').returns(expected
);
324 const result
= await db
.authenticationGet(dbCtx
, identifier
);
325 assert
.deepStrictEqual(result
, expected
);
327 it('failure', async
function () {
328 const expected
= new Error();
329 sinon
.stub(db
.statement
.authenticationGet
, 'get').throws(expected
);
331 await db
.authenticationGet(dbCtx
, identifier
);
332 assert
.fail(noExpectedException
);
334 assert
.deepStrictEqual(e
, expected
);
337 }); // authenticationGet
339 describe('authenticationUpsert', function () {
340 let identifier
, credential
;
341 beforeEach(function () {
342 identifier
= 'username';
343 credential
= '$z$foo';
345 it('success', async
function() {
348 lastInsertRowid: undefined,
350 sinon
.stub(db
.statement
.authenticationUpsert
, 'run').returns(dbResult
);
351 await db
.authenticationUpsert(dbCtx
, identifier
, credential
);
353 it('failure', async
function () {
356 lastInsertRowid: undefined,
358 sinon
.stub(db
.statement
.authenticationUpsert
, 'run').returns(dbResult
);
360 await db
.authenticationUpsert(dbCtx
, identifier
, credential
);
361 assert
.fail(noExpectedException
);
363 assert(e
instanceof DBErrors
.UnexpectedResult
);
366 }); // authenticationUpsert
368 describe('subscriptionsByTopicId', function () {
369 it('success', async
function () {
370 const expected
= [{ id: 3 }];
371 sinon
.stub(db
.statement
.subscriptionsByTopicId
, 'all').returns(expected
);
372 const result
= await db
.subscriptionsByTopicId(dbCtx
, topicUrl
);
373 assert
.deepStrictEqual(result
, expected
);
375 it('failure', async
function () {
376 const expected
= new Error();
377 sinon
.stub(db
.statement
.subscriptionsByTopicId
, 'all').throws(expected
);
379 await db
.subscriptionsByTopicId(dbCtx
, topicUrl
);
380 assert
.fail(noExpectedException
);
382 assert
.deepStrictEqual(e
, expected
);
385 }); // subscriptionsByTopicId
387 describe('subscriptionCountByTopicUrl', function () {
388 it('success', async
function () {
389 const expected
= { count: 3 };
390 sinon
.stub(db
.statement
.subscriptionCountByTopicUrl
, 'get').returns(expected
);
391 const result
= await db
.subscriptionCountByTopicUrl(dbCtx
, topicUrl
);
392 assert
.deepStrictEqual(result
, expected
);
394 it('failure', async
function () {
395 const expected
= new Error();
396 sinon
.stub(db
.statement
.subscriptionCountByTopicUrl
, 'get').throws(expected
);
398 await db
.subscriptionCountByTopicUrl(dbCtx
, topicUrl
);
399 assert
.fail(noExpectedException
);
401 assert
.deepStrictEqual(e
, expected
);
404 }); // subscriptionCountByTopicUrl
406 describe('subscriptionDelete', function () {
407 it('success', async
function() {
410 lastInsertRowid: undefined,
414 lastInsertRowid: undefined,
416 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
417 const result
= await db
.subscriptionDelete(dbCtx
, callback
, topicId
);
418 assert
.deepStrictEqual(result
, expected
);
420 it('failure', async
function () {
423 lastInsertRowid: undefined,
425 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
427 await db
.subscriptionDelete(dbCtx
, callback
, topicId
);
428 assert
.fail(noExpectedException
);
430 assert(e
instanceof DBErrors
.UnexpectedResult
);
433 }); // subscriptionDelete
435 describe('subscriptionDeleteExpired', function () {
436 it('success', async
function () {
439 lastInsertRowid: undefined,
443 lastInsertRowid: undefined,
445 sinon
.stub(db
.statement
.subscriptionDeleteExpired
, 'run').returns(dbResult
);
446 const result
= await db
.subscriptionDeleteExpired(dbCtx
, topicId
);
447 assert
.deepStrictEqual(result
, expected
);
449 it('failure', async
function () {
450 const expected
= new Error();
451 sinon
.stub(db
.statement
.subscriptionDeleteExpired
, 'run').throws(expected
);
453 await db
.subscriptionDeleteExpired(dbCtx
, topicId
);
454 assert
.fail(noExpectedException
);
456 assert
.deepStrictEqual(e
, expected
);
459 }); // subscriptionDeleteExpired
461 describe('subscriptionDeliveryClaim', function () {
462 it('success', async
function () {
463 const dbAllResult
= [
465 id: 'c2e254c5-aa6e-4a8f-b1a1-e474b07392bb',
468 const dbRunResult
= {
470 lastInsertRowid: undefined,
472 const expected
= ['c2e254c5-aa6e-4a8f-b1a1-e474b07392bb'];
473 sinon
.stub(db
.statement
.subscriptionDeliveryNeeded
, 'all').returns(dbAllResult
);
474 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbRunResult
);
475 const result
= await db
.subscriptionDeliveryClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
476 assert
.deepStrictEqual(result
, expected
);
478 it('failure', async
function () {
479 const dbAllResult
= [
481 id: 'c2e254c5-aa6e-4a8f-b1a1-e474b07392bb',
484 const dbRunResult
= {
486 lastInsertRowid: undefined,
488 sinon
.stub(db
.statement
.subscriptionDeliveryNeeded
, 'all').returns(dbAllResult
);
489 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbRunResult
);
491 await db
.subscriptionDeliveryClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
492 assert
.fail(noExpectedException
);
494 assert(e
instanceof DBErrors
.UnexpectedResult
);
497 }); // subscriptionDeliveryClaim
499 describe('subscriptionDeliveryClaimById', function () {
500 it('success', async
function() {
503 lastInsertRowid: undefined,
505 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbResult
);
506 const result
= await db
.subscriptionDeliveryClaimById(dbCtx
, subscriptionId
, claimTimeoutSeconds
, claimant
);
507 assert
.deepStrictEqual(result
, dbResult
);
509 it('failure', async
function () {
512 lastInsertRowid: undefined,
514 sinon
.stub(db
.statement
.subscriptionDeliveryClaimById
, 'run').returns(dbResult
);
516 await db
.subscriptionDeliveryClaimById(dbCtx
, subscriptionId
, claimTimeoutSeconds
, claimant
);
517 assert
.fail(noExpectedException
);
519 assert(e
instanceof DBErrors
.UnexpectedResult
);
522 }); // subscriptionDeliveryClaimById
524 describe('subscriptionDeliveryComplete', function () {
525 let topicContentUpdated
;
527 topicContentUpdated
= new Date();
529 it('success', async
function() {
533 sinon
.stub(db
.statement
.subscriptionDeliverySuccess
, 'run').returns(dbResult
);
534 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
535 await db
.subscriptionDeliveryComplete(dbCtx
, callback
, topicId
, topicContentUpdated
);
537 it('failure', async
function () {
541 sinon
.stub(db
.statement
.subscriptionDeliverySuccess
, 'run').returns(dbResult
);
542 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
544 await db
.subscriptionDeliveryComplete(dbCtx
, callback
, topicId
, topicContentUpdated
);
545 assert
.fail(noExpectedException
);
547 assert(e
instanceof DBErrors
.UnexpectedResult
);
550 it('second failure', async
function () {
557 sinon
.stub(db
.statement
.subscriptionDeliverySuccess
, 'run').returns(dbResult0
);
558 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult1
);
560 await db
.subscriptionDeliveryComplete(dbCtx
, callback
, topicId
, topicContentUpdated
);
561 assert
.fail(noExpectedException
);
563 assert(e
instanceof DBErrors
.UnexpectedResult
);
566 }); // subscriptionDeliveryComplete
568 describe('subscriptionDeliveryGone', function () {
569 it('success', async
function() {
573 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
574 await db
.subscriptionDeliveryGone(dbCtx
, callback
, topicId
);
576 it('failure', async
function () {
580 sinon
.stub(db
.statement
.subscriptionDelete
, 'run').returns(dbResult
);
582 await db
.subscriptionDeliveryGone(dbCtx
, callback
, topicId
);
583 assert
.fail(noExpectedException
);
585 assert(e
instanceof DBErrors
.UnexpectedResult
);
588 }); // subscriptionDeliveryGone
590 describe('subscriptionDeliveryIncomplete', function () {
591 it('success', async
function() {
592 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
596 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
597 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult
);
598 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
599 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
, retryDelays
);
601 it('success covers default', async
function() {
602 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
606 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
607 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult
);
608 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
609 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
);
611 it('failure', async
function () {
612 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
616 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
617 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult
);
618 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult
);
620 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
, retryDelays
);
621 assert
.fail(noExpectedException
);
623 assert(e
instanceof DBErrors
.UnexpectedResult
);
626 it('second failure', async
function () {
627 const dbGet
= { deliveryAttemptsSinceSuccess: 0 };
634 sinon
.stub(db
.statement
.subscriptionDeliveryAttempts
, 'get').returns(dbGet
);
635 sinon
.stub(db
.statement
.subscriptionDeliveryFailure
, 'run').returns(dbResult0
);
636 sinon
.stub(db
.statement
.subscriptionDeliveryDone
, 'run').returns(dbResult1
);
638 await db
.subscriptionDeliveryIncomplete(dbCtx
, callback
, topicId
, retryDelays
);
639 assert
.fail(noExpectedException
);
641 assert(e
instanceof DBErrors
.UnexpectedResult
);
644 }); // subscriptionDeliveryIncomplete
646 describe('subscriptionGet', function () {
647 it('success', async
function() {
651 sinon
.stub(db
.statement
.subscriptionGet
, 'get').returns(expected
);
652 const result
= await db
.subscriptionGet(dbCtx
, callback
, topicId
);
653 assert
.deepStrictEqual(result
, expected
);
655 it('failure', async
function () {
656 const expected
= new Error();
657 sinon
.stub(db
.statement
.subscriptionGet
, 'get').throws(expected
);
659 await db
.subscriptionGet(dbCtx
, callback
, topicId
);
660 assert
.fail(noExpectedException
);
662 assert
.deepStrictEqual(e
, expected
);
665 }); // subscriptionGet
667 describe('subscriptionGetById', function () {
668 it('success', async
function() {
672 sinon
.stub(db
.statement
.subscriptionGetById
, 'get').returns(expected
);
673 const result
= await db
.subscriptionGetById(dbCtx
, subscriptionId
);
674 assert
.deepStrictEqual(result
, expected
);
676 it('failure', async
function () {
677 const expected
= new Error();
678 sinon
.stub(db
.statement
.subscriptionGetById
, 'get').throws(expected
);
680 await db
.subscriptionGetById(dbCtx
, subscriptionId
);
681 assert
.fail(noExpectedException
);
683 assert
.deepStrictEqual(e
, expected
);
686 }); // subscriptionGetById
688 describe('subscriptionUpdate', function () {
690 beforeEach(function () {
693 signatureAlgorithm: 'sha256',
696 it('success', async
function() {
699 lastInsertRowid: subscriptionId
,
701 sinon
.stub(db
.statement
.subscriptionUpdate
, 'run').returns(dbResult
);
702 await db
.subscriptionUpdate(dbCtx
, data
);
704 it('failure', async
function () {
708 sinon
.stub(db
.statement
.subscriptionUpdate
, 'run').returns(dbResult
);
710 await db
.subscriptionUpdate(dbCtx
, data
);
711 assert
.fail(noExpectedException
);
713 assert(e
instanceof DBErrors
.UnexpectedResult
, e
);
716 }); // subscriptionUpdate
718 describe('subscriptionUpsert', function () {
720 beforeEach(function () {
730 it('success', async
function() {
733 lastInsertRowid: subscriptionId
,
737 lastInsertRowid: subscriptionId
,
739 sinon
.stub(db
.statement
.subscriptionUpsert
, 'run').returns(dbResult
);
740 const result
= await db
.subscriptionUpsert(dbCtx
, data
);
741 assert
.deepStrictEqual(result
, expected
);
743 it('failure', async
function () {
747 sinon
.stub(db
.statement
.subscriptionUpsert
, 'run').returns(dbResult
);
749 await db
.subscriptionUpsert(dbCtx
, data
);
750 assert
.fail(noExpectedException
);
752 assert(e
instanceof DBErrors
.UnexpectedResult
);
755 }); // subscriptionUpsert
757 describe('topicDeleted', function () {
758 it('success', async
function () {
759 sinon
.stub(db
.statement
.topicDeleted
, 'run').returns({ changes: 1 });
760 await db
.topicDeleted(dbCtx
, { topicId
});
762 it('failure', async
function () {
763 sinon
.stub(db
.statement
.topicDeleted
, 'run').returns({ changes: 0 });
765 await db
.topicDeleted(dbCtx
, { topicId
});
766 assert
.fail(noExpectedException
);
768 assert(e
instanceof DBErrors
.UnexpectedResult
);
773 describe('topicFetchClaim', function () {
774 it('success', async
function() {
775 const dbAll
= [{ id: topicId
}];
779 const expected
= [topicId
];
780 sinon
.stub(db
.statement
.topicContentFetchNeeded
, 'all').returns(dbAll
);
781 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(dbResult
);
782 const result
= await db
.topicFetchClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
783 assert
.deepStrictEqual(result
, expected
);
785 it('failure', async
function () {
786 const dbAll
= [{ id: topicId
}];
790 sinon
.stub(db
.statement
.topicContentFetchNeeded
, 'all').returns(dbAll
);
791 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(dbResult
);
793 await db
.topicFetchClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
794 assert
.fail(noExpectedException
);
796 assert(e
instanceof DBErrors
.UnexpectedResult
);
799 }); // topicFetchClaim
801 describe('topicFetchClaimById', function () {
802 it('success', async
function() {
805 lastInsertRowid: undefined,
807 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(expected
);
808 const result
= await db
.topicFetchClaimById(dbCtx
, topicId
, claimTimeoutSeconds
, claimant
);
809 assert
.deepStrictEqual(result
, expected
);
811 it('failure', async
function () {
814 lastInsertRowid: undefined,
816 sinon
.stub(db
.statement
.topicContentFetchClaimById
, 'run').returns(expected
);
818 await db
.topicFetchClaimById(dbCtx
, topicId
, claimTimeoutSeconds
, claimant
);
819 assert
.fail(noExpectedException
);
821 assert(e
instanceof DBErrors
.UnexpectedResult
);
824 }); // topicFetchClaimById
826 describe('topicFetchComplete', function () {
827 it('success', async
function() {
830 lastInsertRowid: undefined,
832 sinon
.stub(db
.statement
.topicAttemptsReset
, 'run').returns(dbResult
);
833 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult
);
834 await db
.topicFetchComplete(dbCtx
, topicId
);
836 it('failure', async
function () {
839 lastInsertRowid: undefined,
841 sinon
.stub(db
.statement
.topicAttemptsReset
, 'run').returns(dbResult
);
842 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult
);
844 await db
.topicFetchComplete(dbCtx
, topicId
);
845 assert
.fail(noExpectedException
);
847 assert(e
instanceof DBErrors
.UnexpectedResult
);
850 it('second failure', async
function () {
853 lastInsertRowid: undefined,
857 lastInsertRowid: undefined,
859 sinon
.stub(db
.statement
.topicAttemptsReset
, 'run').returns(dbResult0
);
860 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
862 await db
.topicFetchComplete(dbCtx
, topicId
);
863 assert
.fail(noExpectedException
);
865 assert(e
instanceof DBErrors
.UnexpectedResult
);
868 }); // topicFetchComplete
870 describe('topicFetchIncomplete', function () {
871 it('success', async
function() {
872 const dbGet
= { currentAttempt: 0 };
875 lastInsertRowid: undefined,
879 lastInsertRowid: undefined,
883 lastInsertRowid: undefined,
885 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
886 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
887 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
888 const result
= await db
.topicFetchIncomplete(dbCtx
, topicId
, retryDelays
);
889 assert
.deepStrictEqual(result
, expected
);
891 it('covers defaults', async
function() {
892 const dbGet
= { currentAttempt: 0 };
895 lastInsertRowid: undefined,
899 lastInsertRowid: undefined,
903 lastInsertRowid: undefined,
905 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
906 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
907 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
908 const result
= await db
.topicFetchIncomplete(dbCtx
, topicId
);
909 assert
.deepStrictEqual(result
, expected
);
911 it('failure', async
function () {
912 const dbGet
= { currentAttempt: 0 };
915 lastInsertRowid: undefined,
919 lastInsertRowid: undefined,
921 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
922 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
923 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
925 await db
.topicFetchIncomplete(dbCtx
, topicId
, retryDelays
);
926 assert
.fail(noExpectedException
);
928 assert(e
instanceof DBErrors
.UnexpectedResult
);
931 it('second failure', async
function () {
932 const dbGet
= { currentAttempt: 0 };
935 lastInsertRowid: undefined,
939 lastInsertRowid: undefined,
941 sinon
.stub(db
.statement
.topicAttempts
, 'get').returns(dbGet
);
942 sinon
.stub(db
.statement
.topicAttemptsIncrement
, 'run').returns(dbResult0
);
943 sinon
.stub(db
.statement
.topicContentFetchDone
, 'run').returns(dbResult1
);
945 await db
.topicFetchIncomplete(dbCtx
, topicId
, retryDelays
);
946 assert
.fail(noExpectedException
);
948 assert(e
instanceof DBErrors
.UnexpectedResult
);
951 }); // topicFetchIncomplete
953 describe('topicFetchRequested', function () {
954 it('success', async
function() {
957 lastInsertRowid: undefined,
961 lastInsertRowid: undefined,
963 sinon
.stub(db
.statement
.topicContentFetchRequested
, 'run').returns(dbResult
);
964 const result
= await db
.topicFetchRequested(dbCtx
, topicId
);
965 assert
.deepStrictEqual(result
, expected
);
967 it('failure', async
function () {
970 lastInsertRowid: undefined,
972 sinon
.stub(db
.statement
.topicContentFetchRequested
, 'run').returns(dbResult
);
974 await db
.topicFetchRequested(dbCtx
, topicId
);
975 assert
.fail(noExpectedException
);
977 assert(e
instanceof DBErrors
.UnexpectedResult
);
980 }); // topicFetchRequested
982 describe('topicGetAll', function () {
983 it('success', async
function() {
984 const expected
= [{ id: topicId
}];
985 sinon
.stub(db
.statement
.topicGetInfoAll
, 'all').returns(expected
);
986 const result
= await db
.topicGetAll(dbCtx
);
987 assert
.deepStrictEqual(result
, expected
);
989 it('covers none', async
function() {
990 const expected
= undefined;
991 sinon
.stub(db
.statement
.topicGetInfoAll
, 'all').returns(expected
);
992 const result
= await db
.topicGetAll(dbCtx
);
993 assert
.deepStrictEqual(result
, expected
);
995 it('failure', async
function () {
996 const expected
= new Error();
997 sinon
.stub(db
.statement
.topicGetInfoAll
, 'all').throws(expected
);
999 await db
.topicGetAll(dbCtx
);
1000 assert
.fail(noExpectedException
);
1002 assert
.deepStrictEqual(e
, expected
);
1007 describe('topicGetById', function () {
1008 it('success', async
function() {
1009 const expected
= { id: topicId
};
1010 sinon
.stub(db
.statement
.topicGetById
, 'get').returns(expected
);
1011 const result
= await db
.topicGetById(dbCtx
, topicId
);
1012 assert
.deepStrictEqual(result
, expected
);
1014 it('covers no defaults', async
function () {
1015 const expected
= { id: topicId
};
1016 sinon
.stub(db
.statement
.topicGetById
, 'get').returns(expected
);
1017 const result
= await db
.topicGetById(dbCtx
, topicId
, false);
1018 assert
.deepStrictEqual(result
, expected
);
1020 it('covers default', async
function() {
1021 const expected
= undefined;
1022 sinon
.stub(db
.statement
.topicGetById
, 'get').returns(expected
);
1023 const result
= await db
.topicGetById(dbCtx
, topicId
);
1024 assert
.deepStrictEqual(result
, expected
);
1026 it('failure', async
function () {
1027 const expected
= new Error();
1028 sinon
.stub(db
.statement
.topicGetById
, 'get').throws(expected
);
1030 await db
.topicGetById(dbCtx
, topicId
);
1031 assert
.fail(noExpectedException
);
1033 assert
.deepStrictEqual(e
, expected
);
1038 describe('topicGetByUrl', function () {
1039 it('success', async
function() {
1040 const expected
= [];
1041 sinon
.stub(db
.statement
.topicGetByUrl
, 'get').returns(expected
);
1042 const result
= await db
.topicGetByUrl(dbCtx
, topicUrl
);
1043 assert
.deepStrictEqual(result
, expected
);
1045 it('failure', async
function () {
1046 const expected
= new Error();
1047 sinon
.stub(db
.statement
.topicGetByUrl
, 'get').throws(expected
);
1049 await db
.topicGetByUrl(dbCtx
, topicUrl
);
1050 assert
.fail(noExpectedException
);
1052 assert
.deepStrictEqual(e
, expected
);
1055 }); // topicGetByUrl
1057 describe('topicGetContentById', function () {
1058 it('success', async
function() {
1059 const expected
= { id: topicId
};
1060 sinon
.stub(db
.statement
.topicGetContentById
, 'get').returns(expected
);
1061 const result
= await db
.topicGetContentById(dbCtx
, topicId
);
1062 assert
.deepStrictEqual(result
, expected
);
1064 it('covers default', async
function() {
1065 const expected
= undefined;
1066 sinon
.stub(db
.statement
.topicGetContentById
, 'get').returns(expected
);
1067 const result
= await db
.topicGetContentById(dbCtx
, topicId
);
1068 assert
.deepStrictEqual(result
, expected
);
1070 it('failure', async
function () {
1071 const expected
= new Error();
1072 sinon
.stub(db
.statement
.topicGetContentById
, 'get').throws(expected
);
1074 await db
.topicGetContentById(dbCtx
, topicId
);
1075 assert
.fail(noExpectedException
);
1077 assert
.deepStrictEqual(e
, expected
);
1080 }); // topicGetContentById
1082 describe('topicPendingDelete', function () {
1083 beforeEach(function () {
1084 sinon
.stub(db
.statement
.topicGetById
, 'get');
1085 sinon
.stub(db
.statement
.subscriptionCountByTopicUrl
, 'get');
1086 sinon
.stub(db
.statement
.topicDeleteById
, 'run');
1088 it('success', async
function () {
1089 db
.statement
.topicGetById
.get.returns({
1093 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1096 db
.statement
.topicDeleteById
.run
.returns({
1099 db
.topicPendingDelete(dbCtx
, topicId
);
1100 assert(db
.statement
.topicDeleteById
.run
.called
);
1102 it('does not delete non-deleted topic', async
function () {
1103 db
.statement
.topicGetById
.get.returns({
1107 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1110 db
.statement
.topicDeleteById
.run
.returns({
1113 db
.topicPendingDelete(dbCtx
, topicId
);
1114 assert(!db
.statement
.topicDeleteById
.run
.called
);
1116 it('does not delete topic with active subscriptions', async
function () {
1117 db
.statement
.topicGetById
.get.returns({
1121 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1124 db
.statement
.topicDeleteById
.run
.returns({
1127 db
.topicPendingDelete(dbCtx
, topicId
);
1128 assert(!db
.statement
.topicDeleteById
.run
.called
);
1130 it('covers no deletion', async
function () {
1131 db
.statement
.topicGetById
.get.returns({
1135 db
.statement
.subscriptionCountByTopicUrl
.get.returns({
1138 db
.statement
.topicDeleteById
.run
.returns({
1142 db
.topicPendingDelete(dbCtx
, topicId
);
1143 assert
.fail(noExpectedException
);
1146 assert(e
instanceof DBErrors
.UnexpectedResult
);
1148 assert(db
.statement
.topicDeleteById
.run
.called
);
1150 }); // topicPendingDelete
1152 describe('topicPublishHistory', function () {
1153 beforeEach(function () {
1154 sinon
.stub(db
.statement
.topicPublishHistory
, 'all');
1156 it('success', function () {
1157 db
.statement
.topicPublishHistory
.all
.returns([
1158 { daysAgo: 1, contentUpdates: 1 },
1159 { daysAgo: 3, contentUpdates: 2 },
1161 const result
= db
.topicPublishHistory(dbCtx
, topicId
, 7);
1162 const expected
= [0, 1, 0, 2, 0, 0, 0];
1163 assert
.deepStrictEqual(result
, expected
);
1165 }); // topicPublishHistory
1167 describe('topicSet', function () {
1169 beforeEach(function () {
1174 it('success', async
function() {
1177 lastInsertRowid: topicId
,
1181 lastInsertRowid: topicId
,
1183 sinon
.stub(db
.statement
.topicUpsert
, 'run').returns(dbResult
);
1184 const result
= await db
.topicSet(dbCtx
, data
);
1185 assert
.deepStrictEqual(result
, expected
);
1187 it('failure', async
function () {
1190 lastInsertRowid: undefined,
1192 sinon
.stub(db
.statement
.topicUpsert
, 'run').returns(dbResult
);
1194 await db
.topicSet(dbCtx
, data
);
1195 assert
.fail(noExpectedException
);
1197 assert(e
instanceof DBErrors
.UnexpectedResult
);
1200 it('fails invalid value', async
function () {
1201 sinon
.stub(db
.statement
.topicUpsert
, 'run');
1203 data
.leaseSecondsPreferred
= -100;
1204 await db
.topicSet(dbCtx
, data
);
1205 assert
.fail(noExpectedException
);
1207 assert(e
instanceof DBErrors
.DataValidation
);
1209 assert(!db
.statement
.topicUpsert
.run
.called
);
1211 it('fails invalid values', async
function () {
1212 sinon
.stub(db
.statement
.topicUpsert
, 'run');
1214 data
.leaseSecondsPreferred
= 10;
1215 data
.leaseSecondsMax
= 100;
1216 data
.leaseSecondsMin
= 50;
1217 await db
.topicSet(dbCtx
, data
);
1218 assert
.fail(noExpectedException
);
1220 assert(e
instanceof DBErrors
.DataValidation
);
1222 assert(!db
.statement
.topicUpsert
.run
.called
);
1226 describe('topicSetContent', function () {
1228 beforeEach(function () {
1231 contentType: 'text/plain',
1232 contentHash: 'abc123',
1234 sinon
.stub(db
.statement
.topicSetContent
, 'run');
1235 sinon
.stub(db
.statement
.topicSetContentHistory
, 'run');
1237 it('success', async
function() {
1240 lastInsertRowid: undefined,
1244 lastInsertRowid: undefined,
1246 db
.statement
.topicSetContent
.run
.returns(dbResult
);
1247 db
.statement
.topicSetContentHistory
.run
.returns(dbResult
);
1248 const result
= await db
.topicSetContent(dbCtx
, data
);
1249 assert
.deepStrictEqual(result
, expected
);
1251 it('failure', async
function () {
1254 lastInsertRowid: undefined,
1256 db
.statement
.topicSetContent
.run
.returns(dbResult
);
1258 await db
.topicSetContent(dbCtx
, data
);
1259 assert
.fail(noExpectedException
);
1261 assert(e
instanceof DBErrors
.UnexpectedResult
);
1264 it('failure 2', async
function () {
1265 const dbResultSuccess
= {
1267 lastInsertRowid: undefined,
1269 const dbResultFail
= {
1271 lastInsertRowid: undefined,
1273 db
.statement
.topicSetContent
.run
.returns(dbResultSuccess
);
1274 db
.statement
.topicSetContentHistory
.run
.returns(dbResultFail
);
1276 await db
.topicSetContent(dbCtx
, data
);
1277 assert
.fail(noExpectedException
);
1279 assert(e
instanceof DBErrors
.UnexpectedResult
);
1282 }); // topicSetContent
1284 describe('topicUpdate', function () {
1286 beforeEach(function () {
1289 leaseSecondsPreferred: 9999,
1290 leaseSecondsMax: 99999,
1291 leaseSecondsMin: 999,
1292 publisherValidationUrl: null,
1293 contentHashAlgorithm: 'sha256',
1296 it('success', async
function() {
1299 lastInsertRowid: topicId
,
1301 sinon
.stub(db
.statement
.topicUpdate
, 'run').returns(dbResult
);
1302 await db
.topicUpdate(dbCtx
, data
);
1304 it('failure', async
function () {
1307 lastInsertRowid: undefined,
1309 sinon
.stub(db
.statement
.topicUpdate
, 'run').returns(dbResult
);
1311 await db
.topicUpdate(dbCtx
, data
);
1312 assert
.fail(noExpectedException
);
1314 assert(e
instanceof DBErrors
.UnexpectedResult
, e
);
1317 it('fails invalid value', async
function () {
1318 sinon
.stub(db
.statement
.topicUpdate
, 'run');
1320 data
.leaseSecondsPreferred
= -100;
1321 await db
.topicUpdate(dbCtx
, data
);
1322 assert
.fail(noExpectedException
);
1324 assert(e
instanceof DBErrors
.DataValidation
, e
);
1326 assert(!db
.statement
.topicUpdate
.run
.called
);
1328 it('fails invalid values', async
function () {
1329 sinon
.stub(db
.statement
.topicUpdate
, 'run');
1331 data
.leaseSecondsPreferred
= 10;
1332 data
.leaseSecondsMax
= 100;
1333 data
.leaseSecondsMin
= 50;
1334 await db
.topicUpdate(dbCtx
, data
);
1335 assert
.fail(noExpectedException
);
1337 assert(e
instanceof DBErrors
.DataValidation
, e
);
1339 assert(!db
.statement
.topicUpdate
.run
.called
);
1343 describe('verificationClaim', function () {
1344 it('success', async
function() {
1345 const dbAll
= [{ id: verificationId
}];
1348 lastInsertRowid: undefined,
1350 const expected
= [verificationId
];
1351 sinon
.stub(db
.statement
.verificationNeeded
, 'all').returns(dbAll
);
1352 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1353 const result
= await db
.verificationClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
1354 assert
.deepStrictEqual(result
, expected
);
1356 it('failure', async
function () {
1357 const dbAll
= [{ id: verificationId
}];
1360 lastInsertRowid: undefined,
1362 sinon
.stub(db
.statement
.verificationNeeded
, 'all').returns(dbAll
);
1363 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1365 await db
.verificationClaim(dbCtx
, wanted
, claimTimeoutSeconds
, claimant
);
1366 assert
.fail(noExpectedException
);
1368 assert(e
instanceof DBErrors
.UnexpectedResult
);
1371 }); // verificationClaim
1373 describe('verificationClaimById', function () {
1374 it('success', async
function() {
1377 lastInsertRowid: undefined,
1379 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1380 const result
= await db
.verificationClaimById(dbCtx
, verificationId
, claimTimeoutSeconds
, claimant
);
1381 assert
.deepStrictEqual(result
, dbRun
);
1383 it('failure', async
function () {
1386 lastInsertRowid: undefined,
1388 sinon
.stub(db
.statement
.verificationClaimById
, 'run').returns(dbRun
);
1390 await db
.verificationClaimById(dbCtx
, verificationId
, claimTimeoutSeconds
, claimant
);
1391 assert
.fail(noExpectedException
);
1393 assert(e
instanceof DBErrors
.UnexpectedResult
);
1396 }); // verificationClaimById
1398 describe('verificationComplete', function () {
1399 it('success', async
function() {
1402 lastInsertRowid: undefined,
1404 sinon
.stub(db
.statement
.verificationScrub
, 'run').returns(dbResult
);
1405 await db
.verificationComplete(dbCtx
, verificationId
, callback
, topicId
);
1407 it('failure', async
function () {
1410 lastInsertRowid: undefined,
1412 sinon
.stub(db
.statement
.verificationScrub
, 'run').returns(dbResult
);
1414 await db
.verificationComplete(dbCtx
, verificationId
, callback
, topicId
);
1415 assert
.fail(noExpectedException
);
1417 assert(e
instanceof DBErrors
.UnexpectedResult
);
1420 }); // verificationComplete
1422 describe('verificationGetById', function () {
1423 it('success', async
function() {
1424 const dbOneOrNone
= { id: verificationId
, isPublisherValidated: 1 };
1425 const expected
= { id: verificationId
, isPublisherValidated: true };
1426 sinon
.stub(db
.statement
.verificationGetById
, 'get').returns(dbOneOrNone
);
1427 const result
= await db
.verificationGetById(dbCtx
, verificationId
);
1428 assert
.deepStrictEqual(result
, expected
);
1430 it('failure', async
function () {
1431 const expected
= new Error();
1432 sinon
.stub(db
.statement
.verificationGetById
, 'get').throws(expected
);
1434 await db
.verificationGetById(dbCtx
, verificationId
);
1435 assert
.fail(noExpectedException
);
1437 assert
.deepStrictEqual(e
, expected
);
1440 }); // verificationGetById
1442 describe('verificationIncomplete', function () {
1443 it('success', async
function() {
1444 const dbOne
= { attempts: 0 };
1447 lastInsertRowid: undefined,
1451 lastInsertRowid: undefined,
1453 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1454 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1455 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1456 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1458 it('covers defaults', async
function() {
1459 const dbOne
= { attempts: 0 };
1462 lastInsertRowid: undefined,
1466 lastInsertRowid: undefined,
1468 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1469 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1470 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1471 await db
.verificationIncomplete(dbCtx
, verificationId
);
1473 it('failure', async
function () {
1474 const dbOne
= { attempts: 0 };
1477 lastInsertRowid: undefined,
1481 lastInsertRowid: undefined,
1483 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1484 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1485 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1487 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1488 assert
.fail(noExpectedException
);
1490 assert(e
instanceof DBErrors
.UnexpectedResult
);
1493 it('second failure', async
function () {
1494 const dbOne
= { attempts: 0 };
1497 lastInsertRowid: undefined,
1501 lastInsertRowid: undefined,
1503 sinon
.stub(db
.statement
.verificationAttempts
, 'get').returns(dbOne
);
1504 sinon
.stub(db
.statement
.verificationAttemptsIncrement
, 'run').returns(dbResult0
);
1505 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult1
);
1507 await db
.verificationIncomplete(dbCtx
, verificationId
, retryDelays
);
1508 assert
.fail(noExpectedException
);
1510 assert(e
instanceof DBErrors
.UnexpectedResult
);
1513 }); // verificationIncomplete
1515 describe('_verificationDataToEngine', function () {
1516 it('covers no data', function () {
1517 DB
._verificationDataToEngine();
1519 it('covers true', function () {
1521 isPublisherValidated: true,
1523 DB
._verificationDataToEngine(data
);
1524 assert
.strictEqual(data
.isPublisherValidated
, 1);
1526 it('covers false', function () {
1528 isPublisherValidated: false,
1530 DB
._verificationDataToEngine(data
);
1531 assert
.strictEqual(data
.isPublisherValidated
, 0);
1533 }); // _verificationDataToEngine
1535 describe('verificationInsert', function () {
1537 beforeEach(function () {
1542 isPublisherValidated: true,
1543 leaseSeconds: 86400,
1546 it('success', async
function() {
1549 lastInsertRowid: verificationId
,
1551 const expected
= verificationId
;
1552 sinon
.stub(db
.statement
.verificationInsert
, 'run').returns(dbResult
);
1553 const result
= await db
.verificationInsert(dbCtx
, verification
);
1554 assert
.deepStrictEqual(result
, expected
);
1556 it('failure', async
function () {
1559 lastInsertRowid: undefined,
1561 sinon
.stub(db
.statement
.verificationInsert
, 'run').returns(dbResult
);
1563 await db
.verificationInsert(dbCtx
, verification
);
1564 assert
.fail(noExpectedException
);
1566 assert(e
instanceof DBErrors
.UnexpectedResult
);
1569 it('fails validation', async
function () {
1570 delete verification
.leaseSeconds
;
1572 await db
.verificationInsert(dbCtx
, verification
);
1573 assert
.fail(noExpectedException
);
1575 assert(e
instanceof DBErrors
.DataValidation
);
1578 }); // verificationInsert
1580 describe('verificationRelease', function () {
1581 it('success', async
function() {
1584 lastInsertRowid: undefined,
1586 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult
);
1587 await db
.verificationRelease(dbCtx
, verificationId
);
1589 it('failure', async
function () {
1592 lastInsertRowid: undefined,
1594 sinon
.stub(db
.statement
.verificationDone
, 'run').returns(dbResult
);
1596 await db
.verificationRelease(dbCtx
, verificationId
);
1597 assert
.fail(noExpectedException
);
1599 assert(e
instanceof DBErrors
.UnexpectedResult
);
1602 }); // verificationRelease
1604 describe('verificationUpdate', function () {
1606 beforeEach(function () {
1609 isPublisherValidated: true,
1612 it('success', async
function() {
1615 lastInsertRowid: undefined,
1617 sinon
.stub(db
.statement
.verificationUpdate
, 'run').returns(dbResult
);
1618 await db
.verificationUpdate(dbCtx
, verificationId
, data
);
1620 it('failure', async
function () {
1623 lastInsertRowid: undefined,
1625 sinon
.stub(db
.statement
.verificationUpdate
, 'run').returns(dbResult
);
1627 await db
.verificationUpdate(dbCtx
, verificationId
, data
);
1628 assert
.fail(noExpectedException
);
1630 assert(e
instanceof DBErrors
.UnexpectedResult
, e
.name
);
1633 it('fails validation', async
function () {
1636 await db
.verificationUpdate(dbCtx
, data
);
1637 assert
.fail(noExpectedException
);
1639 assert(e
instanceof DBErrors
.DataValidation
);
1642 }); // verificationUpdate
1644 describe('verificationValidated', function () {
1645 it('success', async
function() {
1648 lastInsertRowid: undefined,
1650 sinon
.stub(db
.statement
.verificationValidate
, 'run').returns(dbResult
);
1651 await db
.verificationValidated(dbCtx
, verificationId
);
1653 it('failure', async
function () {
1656 lastInsertRowid: undefined,
1658 sinon
.stub(db
.statement
.verificationValidate
, 'run').returns(dbResult
);
1660 await db
.verificationValidated(dbCtx
, verificationId
);
1661 assert
.fail(noExpectedException
);
1663 assert(e
instanceof DBErrors
.UnexpectedResult
);
1666 }); // verificationValidated
1668 }); // DatabaseSQLite