X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Flib%2Fcommon.js;h=3adb2e8e6f4d4f77556d8e1e8aa3cdd796c2ff17;hb=HEAD;hp=20911c1d5d745eb0749df5dd69a58cbd173163f2;hpb=3d41f4dd33d59d0c11c97ddeb51ab22d851b93e6;p=squeep-indieauth-helper diff --git a/test/lib/common.js b/test/lib/common.js index 20911c1..3adb2e8 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -5,18 +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(result.endsWith(':bar:baz')); - }); - it('names an index path', function () { - const filename = 'lib/foo/index.js'; - const result = common.fileScope(filename)('baz'); - assert(result.endsWith(':foo:baz')); - }); - }); // fileScope describe('pick', function () { it('picks', function () { @@ -46,47 +34,121 @@ 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 = { - status: 200, - statusText: 'OK', + statusCode: 200, + statusMessage: 'OK', + elapsedTimeMs: 89, 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)', + 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 = { + statusCode: 200, + statusMessage: 'OK', + headers: { + 'Content-Type': 'text/plain', + }, + 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 result = common.axiosResponseLogData(response); + const expected = { + statusCode: 200, + statusMessage: 'OK', + headers: { + 'Content-Type': 'application/json', + }, + elapsedTimeMs: 89, + body: { + foo: 'bar', + }, + redirectUrls: ['https://redirect.example.com/'], + }; + 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); }); - }); // axiosResponseLogData + }); // gotResponseLogData describe('setSymmetricDifference', function () { it('covers difference', function () { @@ -120,14 +182,4 @@ describe('common', function () { }); }); // properURLComponentName - describe('formData', function () { - it('covers', function () { - const result = common.formData({ - key: 'value', - foo: 'bar', - }); - assert.strictEqual(result, 'key=value&foo=bar'); - }); - }); // formData - -}); // common \ No newline at end of file +}); // common