From c633bc0d377117a20bb27597feac23397b6d7c9b Mon Sep 17 00:00:00 2001 From: Ella Nan <38847123+ellanan@users.noreply.github.com> Date: Thu, 30 Jan 2025 11:19:00 -0500 Subject: [PATCH] add tests --- test/utils/helpers.ts | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/utils/helpers.ts b/test/utils/helpers.ts index b2a61ac..e14e756 100644 --- a/test/utils/helpers.ts +++ b/test/utils/helpers.ts @@ -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', () => { @@ -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', () => {