X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Fcommon.js;h=45e9d2c71c80bc3b0e16ecc84a0405c7e4626de8;hb=8cd88ab4087a7fab2ccd6e231c64d7f0f1299f26;hp=a9b228c8d4df349e9047b026745c15608aa3ea30;hpb=cab7ebc31583981d0c235039afdfc9d63e730f02;p=websub-hub diff --git a/test/src/common.js b/test/src/common.js index a9b228c..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 expected = { + statusCode: 200, + statusMessage: 'OK', + body: '', }; - const result = common.axiosResponseLogData(response); + 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