+ describe('topicPendingDelete', function () {
+ beforeEach(function () {
+ sinon.stub(db.statement.topicGetById, 'get');
+ sinon.stub(db.statement.subscriptionCountByTopicUrl, 'get');
+ sinon.stub(db.statement.topicDeleteById, 'run');
+ });
+ it('success', async function () {
+ db.statement.topicGetById.get.returns({
+ id: topicId,
+ isDeleted: true,
+ });
+ db.statement.subscriptionCountByTopicUrl.get.returns({
+ count: 0,
+ });
+ db.statement.topicDeleteById.run.returns({
+ changes: 1,
+ });
+ db.topicPendingDelete(dbCtx, topicId);
+ assert(db.statement.topicDeleteById.run.called);
+ });
+ it('does not delete non-deleted topic', async function () {
+ db.statement.topicGetById.get.returns({
+ id: topicId,
+ isDeleted: false,
+ });
+ db.statement.subscriptionCountByTopicUrl.get.returns({
+ count: 0,
+ });
+ db.statement.topicDeleteById.run.returns({
+ changes: 1,
+ });
+ db.topicPendingDelete(dbCtx, topicId);
+ assert(!db.statement.topicDeleteById.run.called);
+ });
+ it('does not delete topic with active subscriptions', async function () {
+ db.statement.topicGetById.get.returns({
+ id: topicId,
+ isDeleted: true,
+ });
+ db.statement.subscriptionCountByTopicUrl.get.returns({
+ count: 10,
+ });
+ db.statement.topicDeleteById.run.returns({
+ changes: 1,
+ });
+ db.topicPendingDelete(dbCtx, topicId);
+ assert(!db.statement.topicDeleteById.run.called);
+ });
+ it('covers no deletion', async function () {
+ db.statement.topicGetById.get.returns({
+ id: topicId,
+ isDeleted: true,
+ });
+ db.statement.subscriptionCountByTopicUrl.get.returns({
+ count: 0,
+ });
+ db.statement.topicDeleteById.run.returns({
+ changes: 0,
+ });
+ try {
+ db.topicPendingDelete(dbCtx, topicId);
+ assert.fail(noExpectedException);
+
+ } catch (e) {
+ assert(e instanceof DBErrors.UnexpectedResult);
+ }
+ 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
+