Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellanan committed Jan 30, 2025
1 parent 850136f commit c633bc0
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ describe('Format filter string', () => {

expect(res).to.equal('in(sku,prod12,prod34,prod56)')
})

it('should handle multiple filters of the same type', () => {
const res = formatFilterString('eq', {
name: 'Code',
age: 'welcome10'
})
expect(res).to.equal('eq(name,Code):eq(age,welcome10)')
})

it('should handle nested object with multiple attributes', () => {
const res = formatFilterString('eq', {
price: { gt: '100', lt: '200' }
})
expect(res).to.equal('eq(price.gt,100:price.lt,200)')
})
})

describe('Format query string', () => {
Expand All @@ -198,6 +213,59 @@ describe('Format query string', () => {

expect(res).to.equal('filter=eq(name,Test)')
})

it('should handle multiple filter types', () => {
const res = formatQueryString('filter', {
eq: { name: 'sku-123' },
gt: { price: '100' }
})
expect(res).to.equal('filter=eq(name,sku-123):gt(price,100)')
})

it('should handle OR conditions in filters', () => {
const res = formatQueryString('filter', {
or: [{ eq: { category: 'hoodies' } }, { eq: { category: 't-shirts' } }]
})
expect(res).to.equal('filter=(eq(category,hoodies)|eq(category,t-shirts))')
})

it('should handle complex OR conditions with multiple filter types', () => {
const res = formatQueryString('filter', {
or: [
{
eq: { category: 'hoodies' },
gt: { price: '10' }
},
{
eq: { category: 't-shirts' },
lt: { price: '20' }
}
]
})
expect(res).to.equal(
'filter=(eq(category,hoodies):gt(price,10)|eq(category,t-shirts):lt(price,20))'
)
})

it('should handle OR conditions with datetime comparisons', () => {
const res = formatQueryString('filter', {
or: [
{
le: { start: '"2025-01-29T23:31:08.400Z"' },
gt: { end: '"2025-01-29T23:31:08.400Z"' }
},
{
gt: {
start: '"2025-01-29T23:31:08.400Z"',
end: '"2025-01-29T23:31:08.400Z"'
}
}
]
})
expect(res).to.equal(
'filter=(le(start,2025-01-29T23:31:08.400Z):gt(end,2025-01-29T23:31:08.400Z)|gt(start,2025-01-29T23:31:08.400Z):gt(end,2025-01-29T23:31:08.400Z))'
)
})
})

describe('Build query params', () => {
Expand Down

0 comments on commit c633bc0

Please sign in to comment.