X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fsqlite.js;h=deb0ee244fbbb0811f0f6b62b66bebe41aac8ff6;hb=737fbd003d5c4dfea81b667ef906f1c106a60612;hp=bd6612030b3cae08e5d1e1858e8234644033d598;hpb=d5e7908d3e60ee0cb3149163d4749563cdfafeb3;p=websub-hub diff --git a/test/src/db/sqlite.js b/test/src/db/sqlite.js index bd66120..deb0ee2 100644 --- a/test/src/db/sqlite.js +++ b/test/src/db/sqlite.js @@ -460,7 +460,7 @@ describe('DatabaseSQLite', function () { assert.deepStrictEqual(e, expected); } }); - }); + }); // subscriptionDeleteExpired describe('subscriptionDeliveryClaim', function () { it('success', async function () { @@ -1151,7 +1151,22 @@ describe('DatabaseSQLite', function () { } assert(db.statement.topicDeleteById.run.called); }); - }); + }); // topicPendingDelete + + describe('topicPublishHistory', function () { + beforeEach(function () { + sinon.stub(db.statement.topicPublishHistory, 'all'); + }); + it('success', function () { + db.statement.topicPublishHistory.all.returns([ + { daysAgo: 1, contentUpdates: 1 }, + { daysAgo: 3, contentUpdates: 2 }, + ]); + const result = db.topicPublishHistory(dbCtx, topicId, 7); + const expected = [0, 1, 0, 2, 0, 0, 0]; + assert.deepStrictEqual(result, expected); + }); + }); // topicPublishHistory describe('topicSet', function () { let data; @@ -1220,6 +1235,8 @@ describe('DatabaseSQLite', function () { contentType: 'text/plain', contentHash: 'abc123', }; + sinon.stub(db.statement.topicSetContent, 'run'); + sinon.stub(db.statement.topicSetContentHistory, 'run'); }); it('success', async function() { const dbResult = { @@ -1230,7 +1247,8 @@ describe('DatabaseSQLite', function () { changes: 1, lastInsertRowid: undefined, }; - sinon.stub(db.statement.topicSetContent, 'run').returns(dbResult); + db.statement.topicSetContent.run.returns(dbResult); + db.statement.topicSetContentHistory.run.returns(dbResult); const result = await db.topicSetContent(dbCtx, data); assert.deepStrictEqual(result, expected); }); @@ -1239,7 +1257,25 @@ describe('DatabaseSQLite', function () { changes: 0, lastInsertRowid: undefined, }; - sinon.stub(db.statement.topicSetContent, 'run').returns(dbResult); + db.statement.topicSetContent.run.returns(dbResult); + try { + await db.topicSetContent(dbCtx, data); + assert.fail(noExpectedException); + } catch (e) { + assert(e instanceof DBErrors.UnexpectedResult); + } + }); + it('failure 2', async function () { + const dbResultSuccess = { + changes: 1, + lastInsertRowid: undefined, + }; + const dbResultFail = { + changes: 0, + lastInsertRowid: undefined, + }; + db.statement.topicSetContent.run.returns(dbResultSuccess); + db.statement.topicSetContentHistory.run.returns(dbResultFail); try { await db.topicSetContent(dbCtx, data); assert.fail(noExpectedException);