X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fmanager.js;h=ed057c429b586a6e96373e4ff58fa349a1112adc;hb=8cd88ab4087a7fab2ccd6e231c64d7f0f1299f26;hp=67283d76b82c992058e39b2926bd699cd1d43830;hpb=3bc885c4b6ef8e5ced2ee9708194523a41ebfe7a;p=websub-hub diff --git a/test/src/manager.js b/test/src/manager.js index 67283d7..ed057c4 100644 --- a/test/src/manager.js +++ b/test/src/manager.js @@ -1,10 +1,7 @@ -/* eslint-env mocha */ -/* eslint-disable capitalized-comments, sonarjs/no-duplicate-string, sonarjs/no-identical-functions */ - 'use strict'; -const assert = require('assert'); -const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require +const assert = require('node:assert'); +const sinon = require('sinon'); const Manager = require('../../src/manager'); const Config = require('../../config'); @@ -33,6 +30,7 @@ describe('Manager', function () { }; ctx = { params: {}, + queryParams: {}, }; manager = new Manager(stubLogger, stubDb, options); sinon.stub(manager.communication, 'verificationProcess'); @@ -137,6 +135,31 @@ describe('Manager', function () { }); }); // getInfo + describe('_historyBarCaption', function () { + it('covers today, none', function () { + const result = Manager._historyBarCaption(0, 0); + assert.strictEqual(result, 'today, no updates'); + }); + it('covers yesterday, singular', function () { + const result = Manager._historyBarCaption(1, 1); + assert.strictEqual(result, 'yesterday, 1 update'); + }); + it('covers older, plural', function () { + const result = Manager._historyBarCaption(7, 3); + assert.strictEqual(result, '7 days ago, 3 updates'); + }); + }); // _historyBarCaption + + describe('getHistorySVG', function () { + beforeEach(function () { + manager.db.topicPublishHistory.resolves([0, 1, 2, 1, 0, 1, 2, 0, 1]); + }); + it('covers', async function () { + await manager.getHistorySVG(res, ctx); + assert(res.end.called); + }); + }); // getHistorySVG + describe('getAdminOverview', function () { beforeEach(function () { manager.db.topicGetAll.resolves([ @@ -181,7 +204,7 @@ describe('Manager', function () { manager.db.topicGetById.resolves({ id: '56c557ce-e667-11eb-bd80-0025905f714a', created: new Date(), - url: 'https://example.com/', + url: 'https://example.com/topic', leaseSecondsPreferred: 123, leaseSecondsMin: 12, leaseSecondsMax: 123456789, @@ -212,6 +235,7 @@ describe('Manager', function () { deliveryAttemptsSinceSuccess: 0, deliveryNextAttempt: new Date(-Infinity), }]); + manager.db.topicPublishHistory.resolves([0, 1, 0, 1, 0]); }); it('covers', async function() { await manager.getTopicDetails(res, ctx); @@ -227,7 +251,7 @@ describe('Manager', function () { }); it('covers matching profile', async function () { ctx.session = { - authenticatedProfile: 'https://example.com/profile', + authenticatedProfile: 'https://example.com/', }; await manager.getTopicDetails(res, ctx); assert(ctx.topic); @@ -340,10 +364,38 @@ describe('Manager', function () { }); }); // postRoot + describe('_profileControlsTopic', function () { + let profileUrlObj, topicUrlObj; + it('allows exact match', function () { + profileUrlObj = new URL('https://profile.example.com/'); + topicUrlObj = new URL('https://profile.example.com/'); + const result = Manager._profileControlsTopic(profileUrlObj, topicUrlObj); + assert.strictEqual(result, true); + }); + it('allows descendent-path match', function () { + profileUrlObj = new URL('https://profile.example.com/'); + topicUrlObj = new URL('https://profile.example.com/feed/atom'); + const result = Manager._profileControlsTopic(profileUrlObj, topicUrlObj); + assert.strictEqual(result, true); + }); + it('disallows non-descendent-path', function () { + profileUrlObj = new URL('https://profile.example.com/itsame'); + topicUrlObj = new URL('https://profile.example.com/'); + const result = Manager._profileControlsTopic(profileUrlObj, topicUrlObj); + assert.strictEqual(result, false); + }); + it('disallows non-matched host', function () { + profileUrlObj = new URL('https://profile.example.com/itsame'); + topicUrlObj = new URL('https://elsewhere.example.com/itsame/feed'); + const result = Manager._profileControlsTopic(profileUrlObj, topicUrlObj); + assert.strictEqual(result, false); + }); + }); // _profileControlsTopic + describe('_getRootData', function () { it('extracts expected values', function () { req.getHeader.returns('user@example.com'); - ctx = Object.assign({}, testData.validSubscribeCtx) + ctx = Object.assign({}, testData.validSubscribeCtx); const result = Manager._getRootData(req, ctx); assert.deepStrictEqual(result, testData.validRootData); }); @@ -736,7 +788,7 @@ describe('Manager', function () { assert(manager.db.topicFetchRequested.called); assert.strictEqual(res.statusCode, 202); assert(res.end.called); - assert(manager.communication.topicFetchClaimAndProcessById.called) + assert(manager.communication.topicFetchClaimAndProcessById.called); }); it('covers no immediate processing', async function() { manager.options.manager.processImmediately = false; @@ -748,7 +800,7 @@ describe('Manager', function () { assert(manager.db.topicFetchRequested.called); assert.strictEqual(res.statusCode, 202); assert(res.end.called); - assert(!manager.communication.topicFetchClaimAndProcessById.called) + assert(!manager.communication.topicFetchClaimAndProcessById.called); }); }); // _publishRequest