Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a test to additional query param required bug #741

Merged
merged 3 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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