Skip to content

Commit afc56c2

Browse files
author
Crhistian
committed
🐛 filters with zero are dropped #73
1 parent b1b9d7b commit afc56c2

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

codegen/templates/utils/paramsSerializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default function ParamSerializer(originalParams: {
1818
valuesArray.push(`${key}=${encodeURIComponent(val)}`)
1919
)
2020
}
21-
// exclude null, undefined, or empty string but permit boolean false to be serialized
22-
else if (typeof filterVal === 'boolean' || filterVal) {
21+
// exclude null, undefined, or empty string but permit boolean false, and 0 to be serialized
22+
else if (typeof filterVal === 'boolean' || filterVal === 0 || filterVal) {
2323
valuesArray.push(`${key}=${encodeURIComponent(filterVal)}`)
2424
}
2525
}

src/utils/paramsSerializer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default function ParamSerializer(originalParams: {
1818
valuesArray.push(`${key}=${encodeURIComponent(val)}`)
1919
)
2020
}
21-
// exclude null, undefined, or empty string but permit boolean false to be serialized
22-
else if (typeof filterVal === 'boolean' || filterVal) {
21+
// exclude null, undefined, or empty string but permit boolean false, and 0 to be serialized
22+
else if (typeof filterVal === 'boolean' || filterVal === 0 || filterVal) {
2323
valuesArray.push(`${key}=${encodeURIComponent(filterVal)}`)
2424
}
2525
}

tests/paramsSerializer.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,21 @@ test('should allow true boolean', () => {
7878
}
7979
expect(serialize(params)).toBe('FirstName=Bob&IsSubmitted=true')
8080
})
81+
82+
test('should allow number filters', () => {
83+
const params = {
84+
filters: {
85+
SpecCount: 3,
86+
},
87+
}
88+
expect(serialize(params)).toBe('SpecCount=3')
89+
})
90+
91+
test('should not drop 0 filters', () => {
92+
const params = {
93+
filters: {
94+
SpecCount: 0,
95+
},
96+
}
97+
expect(serialize(params)).toBe('SpecCount=0')
98+
})

0 commit comments

Comments
 (0)