X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fintegration.js;h=b92202d41b0e30a04e759872ee984e756f95a13c;hb=737fbd003d5c4dfea81b667ef906f1c106a60612;hp=e6f632c897280586c404ebe2962fc747e08e7923;hpb=38aba0869dc3ade99d439e74cbc6239b4fa1f632;p=websub-hub diff --git a/test/src/db/integration.js b/test/src/db/integration.js index e6f632c..b92202d 100644 --- a/test/src/db/integration.js +++ b/test/src/db/integration.js @@ -79,6 +79,11 @@ describe('Database Integration', function () { assert(db); }); + it('is healthy', async function () { + const result = await db.healthCheck(); + assert(result); + }); + describe('Authentication', function () { let identifier, credential; beforeEach(function () { @@ -114,6 +119,7 @@ describe('Database Integration', function () { }); // Authentication describe('Topic', function () { + let anotherTopicId; step('requires data', async function () { try { await db.context(async (dbCtx) => { @@ -219,10 +225,18 @@ describe('Database Integration', function () { assert.strictEqual(Number(topic.contentFetchAttemptsSinceSuccess), 0); }); }); + step('gets publish history', async function () { + await db.context(async (dbCtx) => { + const result = (await db.topicPublishHistory(dbCtx, topicId, 7)) + .map((x) => Number(x)); + const expected = [1, 0, 0, 0, 0, 0, 0]; + assert.deepStrictEqual(result, expected); + }); + }); step('deletes a topic', async function () { await db.context(async (dbCtx) => { const result = await db.topicSet(dbCtx, testData.anotherTopicSet); - const anotherTopicId = result.lastInsertRowid; + anotherTopicId = result.lastInsertRowid; await db.topicDeleted(dbCtx, anotherTopicId); const topic = await db.topicGetById(dbCtx, anotherTopicId); assert.strictEqual(topic.isDeleted, true); @@ -231,7 +245,7 @@ describe('Database Integration', function () { step('update un-deletes a topic', async function () { await db.context(async (dbCtx) => { const result = await db.topicSet(dbCtx, testData.anotherTopicSet); - const anotherTopicId = result.lastInsertRowid; + assert.strictEqual(result.lastInsertRowid, anotherTopicId); const topic = await db.topicGetById(dbCtx, anotherTopicId); assert.strictEqual(topic.isDeleted, false); }); @@ -242,6 +256,15 @@ describe('Database Integration', function () { assert(topics.length); }); }); + // pending delete of deleted topic with no subscriptions + step('really deletes unsubscribed deleted topic', async function() { + await db.context(async (dbCtx) => { + await db.topicDeleted(dbCtx, anotherTopicId); + await db.topicPendingDelete(dbCtx, anotherTopicId); + const topic = await db.topicGetById(dbCtx, anotherTopicId); + assert(!topic); + }); + }); }); // Topic describe('Subscription', function () { @@ -318,7 +341,8 @@ describe('Database Integration', function () { step('complete subscription', async function () { const { callback } = testData.subscriptionUpsert; await db.context(async (dbCtx) => { - await db.subscriptionDeliveryComplete(dbCtx, callback, topicId); + const topic = await db.topicGetById(dbCtx, topicId); + await db.subscriptionDeliveryComplete(dbCtx, callback, topicId, topic.contentUpdated); const subscription = await db.subscriptionGetById(dbCtx, subscriptionId); assert.strictEqual(Number(subscription.deliveryAttemptsSinceSuccess), 0); }); @@ -372,6 +396,28 @@ describe('Database Integration', function () { assert(!subscription); }); }); + step('create expired subscription', async function () { + const data = { + ...testData.subscriptionUpsert, + secret: 'newSecret', + topicId, + leaseSeconds: -1, + }; + await db.context(async (dbCtx) => { + const result = await db.subscriptionUpsert(dbCtx, data); + assert(result.lastInsertRowid); + assert.notStrictEqual(result.lastInsertRowid, subscriptionId); + subscriptionId = result.lastInsertRowid; + assert.strictEqual(result.changes, 1); + }); + }); + step('delete expired subscriptions', async function() { + await db.context(async (dbCtx) => { + await db.subscriptionDeleteExpired(dbCtx, topicId) + const subscription = await db.subscriptionGet(dbCtx, testData.subscriptionUpsert.callback, topicId); + assert(!subscription); + }); + }); }); // Subscription describe('Verification', function () {