Skip to content

Commit

Permalink
chore: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
achettyiitr committed Jan 3, 2024
1 parent 36de43f commit c437f1f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/warehouse/config/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
52 changes: 35 additions & 17 deletions test/__tests__/warehouse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
})
});

0 comments on commit c437f1f

Please sign in to comment.