Skip to content

Commit 77dd9d4

Browse files
committed
chore: keep query
Signed-off-by: ferhat elmas <elmas.ferhat@gmail.com>
1 parent 4472060 commit 77dd9d4

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/scripts/jobs-client.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from './jobs-client'
99

1010
describe('resolveJobsAdminUrl', () => {
11-
it('preserves base URL path prefixes and query params', () => {
11+
it('preserves base URL path prefixes and adds query params', () => {
1212
const url = resolveJobsAdminUrl('http://localhost:54321/admin/', '/queue/overflow', {
1313
source: 'backup',
1414
groupBy: 'tenant',
@@ -18,6 +18,20 @@ describe('resolveJobsAdminUrl', () => {
1818
'http://localhost:54321/admin/queue/overflow?source=backup&groupBy=tenant'
1919
)
2020
})
21+
22+
it('preserves existing base URL query params when appending the request path', () => {
23+
const url = resolveJobsAdminUrl('https://example.com/admin?region=eu', '/queue/overflow', {
24+
source: 'backup',
25+
})
26+
27+
expect(url.toString()).toBe('https://example.com/admin/queue/overflow?region=eu&source=backup')
28+
})
29+
30+
it('appends the request path before an existing base URL fragment', () => {
31+
const url = resolveJobsAdminUrl('https://example.com/admin#region=eu', '/queue/overflow')
32+
33+
expect(url.toString()).toBe('https://example.com/admin/queue/overflow#region=eu')
34+
})
2135
})
2236

2337
describe('parseJobsOptions', () => {

src/scripts/jobs-client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export function resolveJobsAdminUrl(
4444
requestPath: string,
4545
query?: Record<string, string | undefined>
4646
) {
47-
const url = new URL(`${baseUrl.replace(/\/+$/, '')}/${requestPath.replace(/^\/+/, '')}`)
47+
const url = new URL(baseUrl)
48+
url.pathname = `${url.pathname.replace(/\/+$/, '')}/${requestPath.replace(/^\/+/, '')}`
4849

4950
for (const [key, value] of Object.entries(query ?? {})) {
5051
if (value !== undefined) {

0 commit comments

Comments
 (0)