Skip to content

Commit 37d0ae4

Browse files
authored
Fix duplicate base path for filters (#3233)
* Add base path to mock resolve * Remove resolve from updateQueryParameters utils
1 parent 3dba6b1 commit 37d0ae4

File tree

10 files changed

+204
-115
lines changed

10 files changed

+204
-115
lines changed

src/lib/services/batch-service.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import { writable } from 'svelte/store';
22

33
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
44

5+
import { base } from '$app/paths';
6+
57
import { batchCancelWorkflows, batchTerminateWorkflows } from './batch-service';
68
import { temporalVersion } from '../stores/versions';
9+
import { getApiOrigin } from '../utilities/get-api-origin';
710
import { requestFromAPI } from '../utilities/request-from-api';
811

912
const mockWorkflows = [
@@ -12,6 +15,8 @@ const mockWorkflows = [
1215
{ id: '3', runId: 'c' },
1316
];
1417

18+
const origin = getApiOrigin();
19+
1520
vi.mock('../utilities/request-from-api', () => ({
1621
requestFromAPI: vi.fn().mockImplementation((route) => {
1722
if (route.includes('/describe')) {
@@ -52,7 +57,7 @@ describe('Batch Service', () => {
5257

5358
expect(requestFromAPI).toHaveBeenCalledTimes(2);
5459
expect(requestFromAPI).toHaveBeenCalledWith(
55-
'http://localhost:8233/api/v1/namespaces/default/batch-operations/xxx',
60+
`${origin}${base}/api/v1/namespaces/default/batch-operations/xxx`,
5661
{
5762
notifyOnError: false,
5863
options: {
@@ -73,7 +78,7 @@ describe('Batch Service', () => {
7378

7479
expect(requestFromAPI).toHaveBeenCalledTimes(2);
7580
expect(requestFromAPI).toHaveBeenCalledWith(
76-
'http://localhost:8233/api/v1/namespaces/default/batch-operations/xxx',
81+
`${origin}${base}/api/v1/namespaces/default/batch-operations/xxx`,
7782
{
7883
notifyOnError: false,
7984
options: {
@@ -102,7 +107,7 @@ describe('Batch Service', () => {
102107

103108
expect(requestFromAPI).toHaveBeenCalledTimes(2);
104109
expect(requestFromAPI).toHaveBeenCalledWith(
105-
'http://localhost:8233/api/v1/namespaces/default/batch-operations/xxx',
110+
`${origin}${base}/api/v1/namespaces/default/batch-operations/xxx`,
106111
{
107112
notifyOnError: false,
108113
options: {
@@ -123,7 +128,7 @@ describe('Batch Service', () => {
123128

124129
expect(requestFromAPI).toHaveBeenCalledTimes(2);
125130
expect(requestFromAPI).toHaveBeenCalledWith(
126-
'http://localhost:8233/api/v1/namespaces/default/batch-operations/xxx',
131+
`${origin}${base}/api/v1/namespaces/default/batch-operations/xxx`,
127132
{
128133
notifyOnError: false,
129134
options: {

src/lib/services/namespaces-service.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { afterEach, describe, expect, it, vi } from 'vitest';
22

3+
import { base } from '$app/paths';
4+
35
import { fetchNamespaces } from './namespaces-service';
46
import { namespaces } from '../stores/namespaces';
57
import { toaster } from '../stores/toaster';
8+
import { getApiOrigin } from '../utilities/get-api-origin';
69

710
vi.mock('../stores/toaster', () => ({ toaster: { push: vi.fn() } }));
811
vi.mock('../stores/namespaces', () => ({ namespaces: { set: vi.fn() } }));
912

13+
const origin = getApiOrigin();
14+
1015
const createSuccessfulRequest = () =>
1116
vi.fn(() =>
1217
Promise.resolve({
@@ -42,7 +47,7 @@ describe('fetchNamespaces', () => {
4247

4348
await fetchNamespaces({ runtimeEnvironment: { isCloud: false } }, request);
4449
expect(request).toHaveBeenCalledWith(
45-
'http://localhost:8233/api/v1/namespaces?',
50+
`${origin}${base}/api/v1/namespaces?`,
4651
{
4752
credentials: 'include',
4853
headers: {

src/lib/services/workflow-service.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { afterEach, describe, expect, test, vi } from 'vitest';
22

3+
import { base } from '$app/paths';
4+
35
import { fetchAllWorkflows, fetchWorkflowForRunId } from './workflow-service';
6+
import { getApiOrigin } from '../utilities/get-api-origin';
47
import { requestFromAPI } from '../utilities/request-from-api';
58

69
vi.mock('../utilities/request-from-api', () => ({
@@ -15,6 +18,8 @@ vi.mock('../utilities/request-from-api', () => ({
1518
),
1619
}));
1720

21+
const origin = getApiOrigin();
22+
1823
describe('workflow service', () => {
1924
afterEach(() => {
2025
vi.clearAllMocks();
@@ -28,7 +33,7 @@ describe('workflow service', () => {
2833

2934
expect(requestFromAPI).toHaveBeenCalledOnce();
3035
expect(requestFromAPI).toHaveBeenCalledWith(
31-
'http://localhost:8233/api/v1/namespaces/test/workflows',
36+
`${origin}${base}/api/v1/namespaces/test/workflows`,
3237
{
3338
handleError: expect.any(Function),
3439
onError: expect.any(Function),
@@ -48,7 +53,7 @@ describe('workflow service', () => {
4853

4954
expect(requestFromAPI).toHaveBeenCalledOnce();
5055
expect(requestFromAPI).toHaveBeenCalledWith(
51-
'http://localhost:8233/api/v1/namespaces/test/workflows',
56+
`${origin}${base}/api/v1/namespaces/test/workflows`,
5257
{
5358
params: {
5459
query: `WorkflowId="${workflowId}"`,

src/lib/svelte-mocks/app/paths.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
export const base = '/temporal';
2+
13
// A mock function for resolve from $app/paths: https://svelte.dev/docs/kit/$app-paths#resolve
24
export const resolve = (route: string, params?: Record<string, string>) => {
5+
let resolved = route;
36
if (params) {
4-
return Object.entries(params).reduce(
7+
resolved = Object.entries(params).reduce(
58
(path, [key, value]) => path.replace(`[${key}]`, value),
6-
route,
9+
resolved,
710
);
811
}
9-
return route;
12+
return `${base}${resolved}`;
1013
};

src/lib/utilities/event-link-href.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, expect, it } from 'vitest';
22

3+
import { base } from '$app/paths';
4+
35
import { getEventLinkHref } from './event-link-href';
46

57
describe('getEventLinkHref', () => {
@@ -17,7 +19,7 @@ describe('getEventLinkHref', () => {
1719

1820
const result = getEventLinkHref(link);
1921
expect(result).toBe(
20-
'/namespaces/test-ns/workflows/test-wf/test-run/history/events/42',
22+
`${base}/namespaces/test-ns/workflows/test-wf/test-run/history/events/42`,
2123
);
2224
});
2325

@@ -35,7 +37,7 @@ describe('getEventLinkHref', () => {
3537

3638
const result = getEventLinkHref(link);
3739
expect(result).toBe(
38-
'/namespaces/test-ns/workflows/test-wf/test-run/history/events/1',
40+
`${base}/namespaces/test-ns/workflows/test-wf/test-run/history/events/1`,
3941
);
4042
});
4143

@@ -53,7 +55,7 @@ describe('getEventLinkHref', () => {
5355

5456
const result = getEventLinkHref(link);
5557
expect(result).toBe(
56-
'/namespaces/test-ns/workflows/test-wf/test-run/history/events/req-123',
58+
`${base}/namespaces/test-ns/workflows/test-wf/test-run/history/events/req-123`,
5759
);
5860
});
5961

@@ -68,7 +70,7 @@ describe('getEventLinkHref', () => {
6870

6971
const result = getEventLinkHref(link);
7072
expect(result).toBe(
71-
'/namespaces/test-ns/workflows/test-wf/test-run/timeline',
73+
`${base}/namespaces/test-ns/workflows/test-wf/test-run/timeline`,
7274
);
7375
});
7476

@@ -90,7 +92,7 @@ describe('getEventLinkHref', () => {
9092

9193
const result = getEventLinkHref(link);
9294
expect(result).toBe(
93-
'/namespaces/test-ns/workflows/test-wf/test-run/history/events/99',
95+
`${base}/namespaces/test-ns/workflows/test-wf/test-run/history/events/99`,
9496
);
9597
});
9698
});

src/lib/utilities/route-for-api.test.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { describe, expect, it } from 'vitest';
22

3+
import { base } from '$app/paths';
4+
35
import { routeForApi } from './route-for-api';
6+
import { getApiOrigin } from '../utilities/get-api-origin';
47

58
const parameters = {
69
namespace: 'namespace',
@@ -9,48 +12,50 @@ const parameters = {
912
queue: 'queue',
1013
};
1114

15+
const origin = getApiOrigin();
16+
1217
describe('routeForApi', () => {
1318
it('should return a route for workflow', () => {
1419
const route = routeForApi('workflow', parameters);
1520
expect(route).toBe(
16-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow',
21+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow`,
1722
);
1823
});
1924

2025
it('should return a route for events', () => {
2126
const route = routeForApi('events.ascending', parameters);
2227
expect(route).toBe(
23-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow/history',
28+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow/history`,
2429
);
2530
});
2631

2732
it('should return a route for events', () => {
2833
const route = routeForApi('events.descending', parameters);
2934
expect(route).toBe(
30-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow/history-reverse',
35+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow/history-reverse`,
3136
);
3237
});
3338

3439
it('should return a route for task-queue', () => {
3540
const route = routeForApi('task-queue', parameters);
3641
expect(route).toBe(
37-
'http://localhost:8233/api/v1/namespaces/namespace/task-queues/queue',
42+
`${origin}${base}/api/v1/namespaces/namespace/task-queues/queue`,
3843
);
3944
});
4045

4146
it('should return a route for cluster', () => {
4247
const route = routeForApi('cluster');
43-
expect(route).toBe('http://localhost:8233/api/v1/cluster-info');
48+
expect(route).toBe(`${origin}${base}/api/v1/cluster-info`);
4449
});
4550

4651
it('should return a route for settings', () => {
4752
const route = routeForApi('settings');
48-
expect(route).toBe('http://localhost:8233/api/v1/settings');
53+
expect(route).toBe(`${origin}${base}/api/v1/settings`);
4954
});
5055

5156
it('should return a route for user', () => {
5257
const route = routeForApi('user');
53-
expect(route).toBe('http://localhost:8233/api/v1/me');
58+
expect(route).toBe(`${origin}${base}/api/v1/me`);
5459
});
5560

5661
it('should return a route for workflow', () => {
@@ -61,7 +66,7 @@ describe('routeForApi', () => {
6166

6267
const route = routeForApi('workflow', parameters);
6368
expect(route).toBe(
64-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow',
69+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow`,
6570
);
6671
});
6772

@@ -74,7 +79,7 @@ describe('routeForApi', () => {
7479

7580
const route = routeForApi('workflow', parameters);
7681
expect(route).toBe(
77-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow',
82+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow`,
7883
);
7984
});
8085

@@ -87,28 +92,28 @@ describe('routeForApi', () => {
8792

8893
const route = routeForApi('workflow', parameters);
8994
expect(route).toBe(
90-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow',
95+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow`,
9196
);
9297
});
9398

9499
it('should return a route for workflow.terminate', () => {
95100
const route = routeForApi('workflow.terminate', parameters);
96101
expect(route).toBe(
97-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow/terminate',
102+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow/terminate`,
98103
);
99104
});
100105

101106
it('should return a route for workflow.cancel', () => {
102107
const route = routeForApi('workflow.cancel', parameters);
103108
expect(route).toBe(
104-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow/cancel',
109+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow/cancel`,
105110
);
106111
});
107112

108113
it('should return a route for workflow.reset', () => {
109114
const route = routeForApi('workflow.reset', parameters);
110115
expect(route).toBe(
111-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow/reset',
116+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow/reset`,
112117
);
113118
});
114119

@@ -122,7 +127,7 @@ describe('routeForApi', () => {
122127

123128
const route = routeForApi('workflow.signal', parameters);
124129
expect(route).toBe(
125-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow/signal/signalName',
130+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow/signal/signalName`,
126131
);
127132
});
128133

@@ -133,7 +138,7 @@ describe('routeForApi', () => {
133138

134139
const route = routeForApi('schedules', parameters);
135140
expect(route).toBe(
136-
'http://localhost:8233/api/v1/namespaces/namespace/schedules',
141+
`${origin}${base}/api/v1/namespaces/namespace/schedules`,
137142
);
138143
});
139144

@@ -145,7 +150,7 @@ describe('routeForApi', () => {
145150

146151
const route = routeForApi('schedule', parameters);
147152
expect(route).toBe(
148-
'http://localhost:8233/api/v1/namespaces/namespace/schedules/scheduleName',
153+
`${origin}${base}/api/v1/namespaces/namespace/schedules/scheduleName`,
149154
);
150155
});
151156

@@ -157,7 +162,7 @@ describe('routeForApi', () => {
157162

158163
const route = routeForApi('schedule.edit', parameters);
159164
expect(route).toBe(
160-
'http://localhost:8233/api/v1/namespaces/namespace/schedules/scheduleName/update',
165+
`${origin}${base}/api/v1/namespaces/namespace/schedules/scheduleName/update`,
161166
);
162167
});
163168

@@ -169,7 +174,7 @@ describe('routeForApi', () => {
169174

170175
const route = routeForApi('schedule.patch', parameters);
171176
expect(route).toBe(
172-
'http://localhost:8233/api/v1/namespaces/namespace/schedules/scheduleName/patch',
177+
`${origin}${base}/api/v1/namespaces/namespace/schedules/scheduleName/patch`,
173178
);
174179
});
175180
});
@@ -181,7 +186,7 @@ describe('API Request Encoding', () => {
181186
workflowId: 'workflow#with#hashes',
182187
});
183188
expect(route).toBe(
184-
'http://localhost:8233/api/v1/namespaces/namespace/workflows/workflow%23with%23hashes',
189+
`${origin}${base}/api/v1/namespaces/namespace/workflows/workflow%23with%23hashes`,
185190
);
186191
});
187192

@@ -194,7 +199,7 @@ describe('API Request Encoding', () => {
194199
'temporal.canary.cron-workflow.sanity-2022-05-02T16:03:11-06:00/workflow.advanced-visibility.scan',
195200
});
196201
expect(route).toBe(
197-
'http://localhost:8233/api/v1/namespaces/canary/workflows/temporal.canary.cron-workflow.sanity-2022-05-02T16%3A03%3A11-06%3A00%2Fworkflow.advanced-visibility.scan',
202+
`${origin}${base}/api/v1/namespaces/canary/workflows/temporal.canary.cron-workflow.sanity-2022-05-02T16%3A03%3A11-06%3A00%2Fworkflow.advanced-visibility.scan`,
198203
);
199204
});
200205
});

0 commit comments

Comments
 (0)