X-Git-Url: http://git.squeep.com/?p=websub-hub;a=blobdiff_plain;f=test%2Fsrc%2Flink-helper.js;h=1f914935735f70abc1b0acceed37c534d5a4bc64;hp=535d4c9d6e94a0e9553d6878ebd7860d98212a0b;hb=5399cb751765f7c81ab5d4fab33f873eb3866f61;hpb=8608e06bddd511e1df62be64b484bc297f84d47b diff --git a/test/src/link-helper.js b/test/src/link-helper.js index 535d4c9..1f91493 100644 --- a/test/src/link-helper.js +++ b/test/src/link-helper.js @@ -63,6 +63,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 = ''; + 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 +87,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 +185,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: [