Skip to content

Commit

Permalink
fix: add a test to additional query param required bug (#741)
Browse files Browse the repository at this point in the history
* add a test to additional query param required bug

* use new URL with default base url

Co-authored-by: John Kaster <kaster@google.com>
  • Loading branch information
annguy3n and jkaster authored Jul 8, 2021
1 parent 3ed6af7 commit 0cbe656
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/sdk-rtl/src/paging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,32 @@ describe('paging', () => {
expect(actual.options?.timeout).toEqual(99)
})

it('do not throw error without other params', async () => {
const actual = await pager(sdk, () =>
mockRawResponseSuccess(
transport,
mockedRows,
mockRawResponse('/api/4.0/alerts/search')
)
)
expect(actual).toBeDefined()
expect(actual.limit).toEqual(-1)
expect(actual.offset).toEqual(-1)
})

it('works without other query params', async () => {
const actual = await pager(sdk, () =>
mockRawResponseSuccess(
transport,
mockedRows,
mockRawResponse('/api/4.0/alerts/search?limit=3&offset=0')
)
)
expect(actual).toBeDefined()
expect(actual.limit).toEqual(3)
expect(actual.offset).toEqual(0)
})

it('works on relative url', async () => {
const actual = await pager(sdk, () =>
mockRawResponseSuccess(
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-rtl/src/paging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class Paging<TSuccess extends ILength, TError>
}

parse(raw: IRawResponse): IPager<TSuccess, TError> {
const params = new URLSearchParams(raw.url)
const params = new URL(raw.url, 'http://default').searchParams
this.limit = Paging.paramDefault(params.get('limit'), -1)
this.offset = Paging.paramDefault(
params.get('offset'),
Expand Down

0 comments on commit 0cbe656

Please sign in to comment.