X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fmanager.js;h=9d8c380ff3b300b25d2841de4dffea19b6b05cf5;hb=4d71e429a0d0890184635727e227759876347fed;hp=89e3d65fca2b8370f12de13c02e46553cdaea404;hpb=cab7ebc31583981d0c235039afdfc9d63e730f02;p=websub-hub diff --git a/test/src/manager.js b/test/src/manager.js index 89e3d65..9d8c380 100644 --- a/test/src/manager.js +++ b/test/src/manager.js @@ -33,6 +33,7 @@ describe('Manager', function () { }; ctx = { params: {}, + queryParams: {}, }; manager = new Manager(stubLogger, stubDb, options); sinon.stub(manager.communication, 'verificationProcess'); @@ -59,18 +60,6 @@ describe('Manager', function () { await manager.getRoot(req, res, ctx); assert(res.end.called); }); - it('repeat response', async function () { - manager.startTime = (new Date()).toGMTString(); - common.isClientCached.returns(true); - await manager.getRoot(req, res, ctx); - assert(res.end.called); - }); - it('cached response', async function () { - common.isClientCached.returns(true); - await manager.getRoot(req, res, ctx); - assert(res.end.called); - assert.strictEqual(res.statusCode, 304); - }); }); // getRoot describe('getHealthcheck', function () { @@ -149,8 +138,33 @@ describe('Manager', function () { }); }); // getInfo - describe('getAdminOverview', function () { + 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([ { id: '56c557ce-e667-11eb-bd80-0025905f714a', @@ -172,18 +186,28 @@ describe('Manager', function () { subscribers: 12, }, ]); + }); + it('covers', async function () { + await manager.getAdminOverview(res, ctx); + assert(res.end.called); + }); + it('covers non-matching profile', async function () { + ctx.session = { + authenticatedProfile: 'https://different.example.com/profile', + }; await manager.getAdminOverview(res, ctx); + assert.deepStrictEqual(ctx.topics, []); assert(res.end.called); }); }); // getAdminOverview describe('getTopicDetails', function () { - it('covers', async function() { + beforeEach(function () { ctx.params.topicId = '56c557ce-e667-11eb-bd80-0025905f714a'; 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, @@ -214,9 +238,28 @@ 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); assert(res.end.called); }); + it('covers non-matching profile', async function () { + ctx.session = { + authenticatedProfile: 'https://different.example.com/profile', + }; + await manager.getTopicDetails(res, ctx); + assert.strictEqual(ctx.topic, null); + assert(res.end.called); + }); + it('covers matching profile', async function () { + ctx.session = { + authenticatedProfile: 'https://example.com/', + }; + await manager.getTopicDetails(res, ctx); + assert(ctx.topic); + assert(res.end.called); + }); }); // getTopicDetails describe('postRoot', function () { @@ -324,6 +367,34 @@ 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');