11import { describe , expect , it } from 'vitest' ;
22
3+ import { base } from '$app/paths' ;
4+
35import { routeForApi } from './route-for-api' ;
6+ import { getApiOrigin } from '../utilities/get-api-origin' ;
47
58const parameters = {
69 namespace : 'namespace' ,
@@ -9,48 +12,50 @@ const parameters = {
912 queue : 'queue' ,
1013} ;
1114
15+ const origin = getApiOrigin ( ) ;
16+
1217describe ( '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