From c437f1f6ad6008b646f30300fc02a288a164f820 Mon Sep 17 00:00:00 2001 From: achettyiitr Date: Wed, 3 Jan 2024 18:40:21 +0530 Subject: [PATCH] chore: review comments --- src/warehouse/config/helpers.js | 2 +- test/__tests__/warehouse.test.js | 52 +++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/warehouse/config/helpers.js b/src/warehouse/config/helpers.js index c51fb3a43d..ef00d7ee73 100644 --- a/src/warehouse/config/helpers.js +++ b/src/warehouse/config/helpers.js @@ -10,7 +10,7 @@ const isBlank = (value) => { try { return _.isEmpty(_.toString(value)); } catch (e) { - logger.error(`Error in isBlank: ${e}`); + logger.error(`Error in isBlank: ${e.message}`); return false; } }; diff --git a/test/__tests__/warehouse.test.js b/test/__tests__/warehouse.test.js index 16f3404826..772e59e65a 100644 --- a/test/__tests__/warehouse.test.js +++ b/test/__tests__/warehouse.test.js @@ -1097,99 +1097,117 @@ describe("Integration options", () => { describe("validTimestamp", () => { const testCases = [ { + name: "undefined input should return false", input: undefined, expected: false, }, { + name: "negative year and time input should return false #1", input: '-0001-11-30T00:00:00+0000', expected: false, }, { + name: "negative year and time input should return false #2", input: '-2023-06-14T05:23:59.244Z', expected: false, }, { + name: "negative year and time input should return false #3", + input: '-1900-06-14T05:23:59.244Z', + expected: false, + }, + { + name: "positive year and time input should return false", input: '+2023-06-14T05:23:59.244Z', expected: false, }, { + name: "valid timestamp input should return true", input: '2023-06-14T05:23:59.244Z', expected: true, }, { - input: '-1900-06-14T05:23:59.244Z', - expected: false, - }, - { + name: "non-date string input should return false", input: 'abc', expected: false, }, { - input: '%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216Windows%u2216win%u002ein', + name: "malicious string input should return false", + input: '%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216%u002e%u002e%u2216Windows%u2216win%u002ein', expected: false, }, { + name: "empty string input should return false", input: '', expected: false, }, { + name: "valid date input should return true", input: '2023-06-14', expected: true, }, { + name: "time-only input should return false", input: '05:23:59.244Z', expected: false, }, { - input: {abc: 123}, + name: "non-string input should return false", + input: { abc: 123 }, expected: false, }, { + name: "object with toString method input should return false", input: { toString: '2023-06-14T05:23:59.244Z' }, expected: false, - } - ] + }, + ]; - for (let i = 0; i < testCases.length; i++) { - const testCase = testCases[i]; - it(`should return ${testCase.expected} for testcase ${i + 1}`, () => { + for (const testCase of testCases) { + it(`should return ${testCase.expected} for ${testCase.name}`, () => { expect(validTimestamp(testCase.input)).toEqual(testCase.expected); }); } }); + + describe("isBlank", () => { const testCases = [ { + name: "null", input: null, expected: true }, { + name: "empty string", input: "", expected: true }, { + name: "non-empty string", input: "test", expected: false }, { + name: "numeric value", input: 1634762544, expected: false }, { + name: "object with toString property", input: { toString: '2023-06-14T05:23:59.244Z' }, - expected: false, + expected: false }, - ] + ]; - for (let i = 0; i < testCases.length; i++) { - const testCase = testCases[i]; - it(`should return ${testCase.expected} for testcase ${i + 1}`, () => { + for (const testCase of testCases) { + it(`should return ${testCase.expected} for ${testCase.name}`, () => { expect(isBlank(testCase.input)).toEqual(testCase.expected); }); } -}) \ No newline at end of file +}); \ No newline at end of file