X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Flib%2Fcommon.js;h=3adb2e8e6f4d4f77556d8e1e8aa3cdd796c2ff17;hb=ddf28d2e4816d7c4e188f8dd510b48ad87aee478;hp=8b223dadc0ea9c429d7023f3ba1056f534e12aac;hpb=e648aedc1c912cd07da0b1dad7be3910248b25c9;p=squeep-indieauth-helper diff --git a/test/lib/common.js b/test/lib/common.js index 8b223da..3adb2e8 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -5,27 +5,6 @@ const assert = require('assert'); const common = require('../../lib/common'); describe('common', function () { - describe('fileScope', function () { - it('names a file path', function () { - const filename = 'lib/foo/bar.js'; - const result = common.fileScope(filename)('baz'); - assert.strictEqual(result, 'bar:baz'); - }); - it('names an index path', function () { - const filename = 'lib/foo/index.js'; - const result = common.fileScope(filename)('baz'); - assert.strictEqual(result, 'foo:baz'); - }); - }); // fileScope - - describe('base64ToBase64URL', function () { - it('works', function () { - const b64 = 'ab/cd+e='; - const expected = 'ab_cd-e'; - const result = common.base64ToBase64URL(b64); - assert.strictEqual(result, expected); - }); - }); // base64ToBase64URL describe('pick', function () { it('picks', function () { @@ -55,46 +34,152 @@ describe('common', function () { }); }); // logTruncate - describe('axiosResponseLogData', function () { + describe('gotResponseLogData', function () { it('covers', function () { const response = { - status: 200, - statusText: 'OK', + statusCode: 200, + statusMessage: 'OK', headers: { 'Content-Type': 'text/plain', }, otherData: 'blah', - data: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green Meadows," said Old Mother West Wind, “and there I saw the Best Thing in the World.”', + timings: { + phases: { + total: 89, + }, + }, + retryCount: 0, + redirectUrls: [], + body: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green Meadows," said Old Mother West Wind, “and there I saw the Best Thing in the World.”', + }; + const expected = { + statusCode: 200, + statusMessage: 'OK', + elapsedTimeMs: 89, + headers: { + 'Content-Type': 'text/plain', + }, + body: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green... (184 bytes)', + }; + const result = common.gotResponseLogData(response); + assert.deepStrictEqual(result, expected); + }); + it('covers no body', function () { + const response = { + statusCode: 200, + statusMessage: 'OK', + headers: { + 'Content-Type': 'text/plain', + }, + timings: { + phases: { + total: 89, + }, + }, + retryCount: 1, }; const expected = { - status: 200, - statusText: 'OK', + statusCode: 200, + statusMessage: 'OK', headers: { 'Content-Type': 'text/plain', }, - data: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green... (184 bytes)', + elapsedTimeMs: 89, + retryCount: 1, + }; + const result = common.gotResponseLogData(response); + assert.deepStrictEqual(result, expected); + }); + it('covers json', function () { + const response = { + statusCode: 200, + statusMessage: 'OK', + headers: { + 'Content-Type': 'application/json', + }, + timings: { + phases: { + total: 89, + }, + }, + body: { + foo: 'bar', + }, + redirectUrls: ['https://redirect.example.com/'], + }; + const expected = { + statusCode: 200, + statusMessage: 'OK', + headers: { + 'Content-Type': 'application/json', + }, + elapsedTimeMs: 89, + body: { + foo: 'bar', + }, + redirectUrls: ['https://redirect.example.com/'], }; - const result = common.axiosResponseLogData(response); + const result = common.gotResponseLogData(response); assert.deepStrictEqual(result, expected); }); - it('covers no data', function () { + it('covers buffer', function () { const response = { - status: 200, - statusText: 'OK', + statusCode: 200, + statusMessage: 'OK', headers: { 'Content-Type': 'text/plain', }, + timings: { + phases: { + total: 89, + }, + }, + body: Buffer.from('ᘛ⁐̤ᕐᐷ'), }; const expected = { - status: 200, - statusText: 'OK', + statusCode: 200, + statusMessage: 'OK', headers: { 'Content-Type': 'text/plain', }, + elapsedTimeMs: 89, + body: '', }; - const result = common.axiosResponseLogData(response); + const result = common.gotResponseLogData(response); + assert.deepStrictEqual(result, expected); + }); + }); // gotResponseLogData + + describe('setSymmetricDifference', function () { + it('covers difference', function () { + const setA = new Set([1, 2, 3]); + const setB = new Set([2, 3, 4]); + const expected = new Set([1, 4]); + const result = common.setSymmetricDifference(setA, setB); + assert(result.size); assert.deepStrictEqual(result, expected); }); - }); // axiosResponseLogData + it('covers no difference', function () { + const setA = new Set([1, 2, 3, 4]); + const setB = new Set([1, 2, 3, 4]); + const expected = new Set(); + const result = common.setSymmetricDifference(setA, setB); + assert(!result.size); + assert.deepStrictEqual(result, expected); + }); + }); // setSymmetricDifference + + describe('properURLComponentName', function () { + it('maps proper names', function () { + [ + ['hash', 'fragment'], + ['protocol', 'scheme'], + ['host', 'host'], + ].forEach(([name, expected]) => { + const result = common.properURLComponentName(name); + assert.strictEqual(result, expected); + }); + }); + }); // properURLComponentName -}); // common \ No newline at end of file +}); // common