Skip to content

Commit

Permalink
fix(#1601): fix parsing falsy values in filterOutNullParams util
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Aug 29, 2024
1 parent b2757a0 commit 8ad1bb7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const GovernanceActionDetailsCardLinks = ({
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
mb: 2,
my: 2,
}}
data-testid="supporting-links"
>
Expand Down
6 changes: 5 additions & 1 deletion govtool/frontend/src/utils/filterOutNullParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export const filterOutNullParams = (

const finalObject = Object.entries(originalObject).reduce(
(acc: Record<string, unknown>, [key, value]) => {
if (value && !filterOutKeys?.includes(key)) {
if (
value !== null &&
value !== undefined &&
!filterOutKeys?.includes(key)
) {
acc[key] = value;
}
return acc;
Expand Down
19 changes: 19 additions & 0 deletions govtool/frontend/src/utils/tests/filterOutNullParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,23 @@ describe("filterOutNullParams", () => {

expect(result).toBeNull();
});

it("shouldn't filter out 0", () => {
const originalObject = {
key1: "value1",
key2: 0,
key3: "value3",
key4: undefined,
};

const expectedObject = {
key1: "value1",
key2: 0,
key3: "value3",
};

const result = filterOutNullParams(originalObject);

expect(result).toEqual(expectedObject);
});
});

0 comments on commit 8ad1bb7

Please sign in to comment.