change devDependency html linter to resolve audit issue, fix lint issues
[websub-hub] / test / src / link-helper.js
index 535d4c9d6e94a0e9553d6878ebd7860d98212a0b..5f84362e4f1ebff5b58615f46f8febd603da5d4d 100644 (file)
@@ -1,8 +1,7 @@
-/* eslint-env mocha */
 '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 LinkHelper = require('../../src/link-helper');
 const stubLogger = require('../stub-logger');
 const testData = require('../test-data/link-helper');
@@ -63,6 +62,15 @@ describe('LinkHelper', function () {
       const result = await lh.validHub(url, headers, body);
       assert.strictEqual(result, expected);
     });
+    it('covers link in HTML body with charset translation', async function () {
+      headers = {
+        'content-type': 'text/html; charset=ASCII',
+      };
+      body = '<html><head><link rel="hub" href="https://example.com/hub/"></head></html>';
+      const expected = true;
+      const result = await lh.validHub(url, headers, body);
+      assert.strictEqual(result, expected);
+    });
     it('covers parser failure', async function () {
       headers = {
         link: 'Invalid Link Header',
@@ -78,6 +86,46 @@ describe('LinkHelper', function () {
     });
   }); // validHub
 
+  describe('parseContentType', function () {
+    it('handles no data', function () {
+      const expected = {
+        mediaType: 'application/octet-stream',
+        params: {},
+      };
+      const result = LinkHelper.parseContentType();
+      assert.deepStrictEqual(result, expected);
+    });
+    it('handles only media type', function () {
+      const expected = {
+        mediaType: 'application/json',
+        params: {},
+      };
+      const result = LinkHelper.parseContentType('application/json');
+      assert.deepStrictEqual(result, expected);
+    });
+    it('handles parameters', function () {
+      const expected = {
+        mediaType: 'text/html',
+        params: {
+          charset: 'ISO-8859-4',
+        },
+      };
+      const result = LinkHelper.parseContentType('text/html; charset=ISO-8859-4');
+      assert.deepStrictEqual(result, expected);
+    });
+    it('handles more parameters', function () {
+      const expected = {
+        mediaType: 'multipart/form-data',
+        params: {
+          boundary: '--123--',
+          other: 'foo',
+        },
+      };
+      const result = LinkHelper.parseContentType('multipart/form-data; boundary="--123--"; other=foo');
+      assert.deepStrictEqual(result, expected);
+    });
+  }); // parseContentType
+
   describe('absoluteURI', function () {
     it('success', function () {
       const uri = '../rel';
@@ -136,6 +184,23 @@ describe('LinkHelper', function () {
     it('parses rss', async function () {
       const feedData = testData.rssFeedBody;
       const feedUrl = testData.rssFeedUrl;
+      const expected = [
+        {
+          attributes: [
+            {
+              name: 'rel',
+              value: 'hub',
+            },
+          ],
+          target: 'https://hub.squeep.com/',
+        },
+      ];
+      const result = await lh.linksFromFeedBody(feedUrl, feedData);
+      assert.deepStrictEqual(result, expected);
+    });
+    it('parses more rss', async function () {
+      const feedData = testData.rssFeedBody2;
+      const feedUrl = testData.rssFeedUrl2;
       const expected = [
         {
           attributes: [