X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fdb%2Fintegration.js;h=7eb7d91670295b0f4bafad18f15b2e8bb31e7f56;hb=1c37a7c533a5530390489ea9a49dcca492db1074;hp=8d5b61553d24f3b72e4ec6d39fd73534de7617cd;hpb=085b55f507dedc16016bb491d520c556acd60643;p=websub-hub diff --git a/test/src/db/integration.js b/test/src/db/integration.js index 8d5b615..7eb7d91 100644 --- a/test/src/db/integration.js +++ b/test/src/db/integration.js @@ -1,5 +1,3 @@ -/* eslint-env mocha */ -/* eslint-disable sonarjs/no-identical-functions */ 'use strict'; /** @@ -16,8 +14,8 @@ * */ -const assert = require('assert'); -const { step } = require('mocha-steps'); // eslint-disable-line node/no-unpublished-require +const assert = require('node:assert'); +const { step } = require('mocha-steps'); const stubLogger = require('../../stub-logger'); const DBErrors = require('../../../src/db/errors'); const testData = require('../../test-data/db-integration'); @@ -79,6 +77,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 () { @@ -148,12 +151,15 @@ describe('Database Integration', function () { const data = { topicId, leaseSecondsMin: 60, - } + }; await db.context(async(dbCtx) => { - let topic = await db.topicGetByUrl(dbCtx, testData.topicSet.url); + const expected = await db.topicGetByUrl(dbCtx, testData.topicSet.url, true); + expected.leaseSecondsMin = data.leaseSecondsMin; + let topic = await db.topicGetByUrl(dbCtx, testData.topicSet.url, false); await db.topicUpdate(dbCtx, { ...topic, ...data }); topic = await db.topicGetByUrl(dbCtx, testData.topicSet.url); assert.strictEqual(Number(topic.leaseSecondsMin), data.leaseSecondsMin); + assert.deepEqual(topic, expected); }); }); step('gets topic by id', async function () { @@ -220,6 +226,14 @@ 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); @@ -269,7 +283,7 @@ describe('Database Integration', function () { const data = { ...testData.subscriptionUpsert, topicId, - } + }; await db.context(async (dbCtx) => { const result = await db.subscriptionUpsert(dbCtx, data); assert(result.lastInsertRowid); @@ -328,7 +342,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); }); @@ -347,7 +362,7 @@ describe('Database Integration', function () { ...testData.subscriptionUpsert, secret: 'newSecret', topicId, - } + }; await db.context(async (dbCtx) => { const result = await db.subscriptionUpsert(dbCtx, data); assert(result.lastInsertRowid); @@ -399,7 +414,7 @@ describe('Database Integration', function () { }); step('delete expired subscriptions', async function() { await db.context(async (dbCtx) => { - await db.subscriptionDeleteExpired(dbCtx, topicId) + await db.subscriptionDeleteExpired(dbCtx, topicId); const subscription = await db.subscriptionGet(dbCtx, testData.subscriptionUpsert.callback, topicId); assert(!subscription); });