X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fcommon.js;h=45e9d2c71c80bc3b0e16ecc84a0405c7e4626de8;hb=8cd88ab4087a7fab2ccd6e231c64d7f0f1299f26;hp=b64ecb4ee5d3a71a5c9c5d5d3f16d08c826c7aeb;hpb=9696c012e6b9a6c58904baa397ca0ebf78112316;p=websub-hub diff --git a/test/src/common.js b/test/src/common.js index b64ecb4..45e9d2c 100644 --- a/test/src/common.js +++ b/test/src/common.js @@ -1,7 +1,6 @@ -/* eslint-env mocha */ 'use strict'; -const assert = require('assert'); +const assert = require('node:assert'); const common = require('../../src/common'); describe('Common', function () { @@ -23,47 +22,71 @@ describe('Common', function () { }); }); // freezeDeep - 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.”', + 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.”', + timings: { + phases: { + total: 87, + }, + }, + retryCount: 2, + redirectUrls: ['https://example.com/clip/Thornton_Burgess'], }; 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)', + body: 'Old Mother West Wind had stopped to talk with the Slender Fir Tree. "I\'ve just come across the Green... (184 bytes)', + elapsedTimeMs: 87, + retryCount: 2, + redirectUrls: ['https://example.com/clip/Thornton_Burgess'], + }; + const result = common.gotResponseLogData(response); + assert.deepStrictEqual(result, expected); + }); + it('covers buffer data', function () { + const response = { + statusCode: 200, + statusMessage: 'OK', + body: Buffer.from('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 result = common.axiosResponseLogData(response); + const expected = { + statusCode: 200, + statusMessage: 'OK', + body: '', + }; + const result = common.gotResponseLogData(response); assert.deepStrictEqual(result, expected); }); it('covers no data', function () { const response = { - status: 200, - statusText: 'OK', + statusCode: 200, + statusMessage: 'OK', headers: { 'Content-Type': 'text/plain', }, }; const expected = { - status: 200, - statusText: 'OK', + statusCode: 200, + statusMessage: 'OK', headers: { 'Content-Type': 'text/plain', }, }; - const result = common.axiosResponseLogData(response); + const result = common.gotResponseLogData(response); assert.deepStrictEqual(result, expected); }); - }); // axiosResponseLogData + }); // gotResponseLogData describe('topicLeaseDefaults', function () { it('supplies necessary properties', function () { @@ -110,7 +133,7 @@ describe('Common', function () { it('covers default', function () { const result = common.attemptRetrySeconds(0); assert(result >= 60); - assert(result <= 60 * 1.618) + assert(result <= 60 * 1.618); }); }); // attemptRetrySeconds @@ -160,4 +183,21 @@ describe('Common', function () { }); }); // validHash + describe('ensureArray', function () { + it('returns empty array for no data', function () { + const result = common.ensureArray(); + assert.deepStrictEqual(result, []); + }); + it('returns same array passed in', function () { + const expected = [1, 2, 3, 'foo']; + const result = common.ensureArray(expected); + assert.deepStrictEqual(result, expected); + }); + it('returns array containing non-array data', function () { + const data = 'bar'; + const result = common.ensureArray(data); + assert.deepStrictEqual(result, [data]); + }); + }); // ensureArray + }); // Common