X-Git-Url: http://git.squeep.com/?p=websub-hub;a=blobdiff_plain;f=test%2Fsrc%2Fcommunication.js;h=d5ebe54222664863411dd4fcf4898cf3a9028a6a;hp=7c622274a8dfa0d00e2350c168bc356559d6eb24;hb=71efac9dcd7dc219cb83799391e7adc63cd4c662;hpb=9696c012e6b9a6c58904baa397ca0ebf78112316 diff --git a/test/src/communication.js b/test/src/communication.js index 7c62227..d5ebe54 100644 --- a/test/src/communication.js +++ b/test/src/communication.js @@ -405,6 +405,23 @@ describe('Communication', function () { assert(communication.db.verificationComplete.called); }); + it('unsubscription from deleted topic deletes topic', async function () { + communication.db.verificationGetById.restore(); + verification.mode = 'unsubscribe'; + sinon.stub(communication.db, 'verificationGetById').resolves(verification); + communication.db.topicGetById.restore(); + sinon.stub(communication.db, 'topicGetById').resolves({ + ...topic, + isDeleted: true, + }); + + await communication.verificationProcess(dbCtx, callback, topicId, requestId); + + assert(communication.db.subscriptionDelete.called); + assert(communication.db.verificationComplete.called); + assert(communication.db.topicPendingDelete.called); + }); + it('unsubscription denial succeeds', async function () { communication.db.verificationGetById.restore(); verification.mode = 'unsubscribe'; @@ -535,6 +552,8 @@ describe('Communication', function () { headers: { 'content-type': 'text/plain', link: '; rel="hub"', + 'last-modified': 'Thu, 18 Nov 2021 20:34:35 GMT', + 'etag': '"9c104-1673e-5d1161636d742"', }, data: 'Jackdaws love my big sphinx of quartz.', }); @@ -614,6 +633,20 @@ describe('Communication', function () { assert(!communication.db.topicSetContent.called); }); + it('recognizes 304 response', async function () { + topic.httpLastModified = 'Thu, 18 Nov 2021 20:34:35 GMT'; + topic.httpEtag = '"9c104-1673e-5d1161636d742"'; + communication.db.topicGetById.resolves(topic); + communication.axios.resolves({ + status: 304, + }); + + await communication.topicFetchProcess(dbCtx, topicId, requestId); + + assert(communication.db.topicFetchComplete.called); + assert(!communication.db.topicSetContent.called); + }); + it('updates content', async function () { await communication.topicFetchProcess(dbCtx, topicId, requestId); @@ -837,8 +870,9 @@ describe('Communication', function () { }); // verificationClaimAndProcessById describe('workFeed', function () { - let wanted; + let stubCtx, wanted; beforeEach(function () { + stubCtx = {}; sinon.stub(communication, 'topicFetchProcess'); sinon.stub(communication, 'verificationProcess'); sinon.stub(communication, 'subscriptionDeliveryProcess'); @@ -853,12 +887,13 @@ describe('Communication', function () { const expectedLength = [topicIds, verificationIds, subscriptionIds].map((x) => x.length).reduce((a, b) => a + b, 0); wanted = 10; - const result = await communication.workFeed(wanted); + const result = await communication.workFeed(stubCtx, wanted); assert.strictEqual(result.length, expectedLength); }); it('covers no wanted work', async function () { - const result = await communication.workFeed(0); + wanted = 0; + const result = await communication.workFeed(stubCtx, wanted); assert.strictEqual(result.length, 0); assert(!communication.db.topicFetchClaim.called); assert(!communication.db.verificationClaim.called); @@ -871,7 +906,7 @@ describe('Communication', function () { const expectedLength = topicIds.length; wanted = 10; - const result = await communication.workFeed(wanted); + const result = await communication.workFeed(stubCtx, wanted); assert.strictEqual(result.length, expectedLength); });