database migration 1.0.4, store topic fetch etag/last-modified, provide these when...
[websub-hub] / test / src / communication.js
index ca5f34e92c536458171c18fa8cd4f78976a5bf11..d5ebe54222664863411dd4fcf4898cf3a9028a6a 100644 (file)
@@ -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: '<https://example.com/hub/>; 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);