9
9
INVALID_ENTITY_ID ,
10
10
} from './testUtils/testDefaults'
11
11
import {
12
- API_REST_BASE_URI ,
13
- API_SYNC_BASE_URI ,
12
+ getRestBaseUri ,
13
+ getSyncBaseUri ,
14
14
ENDPOINT_REST_TASK_CLOSE ,
15
15
ENDPOINT_REST_TASK_REOPEN ,
16
16
ENDPOINT_REST_TASKS ,
@@ -23,8 +23,8 @@ function setupSyncTaskConverter(returnedTask: Task) {
23
23
return jest . spyOn ( taskConverters , 'getTaskFromQuickAddResponse' ) . mockReturnValue ( returnedTask )
24
24
}
25
25
26
- function getTarget ( ) {
27
- return new TodoistApi ( DEFAULT_AUTH_TOKEN )
26
+ function getTarget ( baseUrl = 'https://api.todoist.com' ) {
27
+ return new TodoistApi ( DEFAULT_AUTH_TOKEN , baseUrl )
28
28
}
29
29
30
30
describe ( 'TodoistApi task endpoints' , ( ) => {
@@ -42,7 +42,24 @@ describe('TodoistApi task endpoints', () => {
42
42
expect ( requestMock ) . toBeCalledTimes ( 1 )
43
43
expect ( requestMock ) . toBeCalledWith (
44
44
'POST' ,
45
- API_REST_BASE_URI ,
45
+ getRestBaseUri ( ) ,
46
+ ENDPOINT_REST_TASKS ,
47
+ DEFAULT_AUTH_TOKEN ,
48
+ DEFAULT_ADD_TASK_ARGS ,
49
+ DEFAULT_REQUEST_ID ,
50
+ )
51
+ } )
52
+
53
+ test ( 'calls post on restClient with expected parameters against staging' , async ( ) => {
54
+ const requestMock = setupRestClientMock ( DEFAULT_TASK )
55
+ const api = getTarget ( 'https://staging.todoist.com' )
56
+
57
+ await api . addTask ( DEFAULT_ADD_TASK_ARGS , DEFAULT_REQUEST_ID )
58
+
59
+ expect ( requestMock ) . toBeCalledTimes ( 1 )
60
+ expect ( requestMock ) . toBeCalledWith (
61
+ 'POST' ,
62
+ getRestBaseUri ( 'https://staging.todoist.com' ) ,
46
63
ENDPOINT_REST_TASKS ,
47
64
DEFAULT_AUTH_TOKEN ,
48
65
DEFAULT_ADD_TASK_ARGS ,
@@ -72,7 +89,7 @@ describe('TodoistApi task endpoints', () => {
72
89
expect ( requestMock ) . toBeCalledTimes ( 1 )
73
90
expect ( requestMock ) . toBeCalledWith (
74
91
'POST' ,
75
- API_REST_BASE_URI ,
92
+ getRestBaseUri ( ) ,
76
93
`${ ENDPOINT_REST_TASKS } /${ taskId } ` ,
77
94
DEFAULT_AUTH_TOKEN ,
78
95
updateArgs ,
@@ -108,7 +125,7 @@ describe('TodoistApi task endpoints', () => {
108
125
expect ( requestMock ) . toBeCalledTimes ( 1 )
109
126
expect ( requestMock ) . toBeCalledWith (
110
127
'POST' ,
111
- API_REST_BASE_URI ,
128
+ getRestBaseUri ( ) ,
112
129
`${ ENDPOINT_REST_TASKS } /${ taskId } /${ ENDPOINT_REST_TASK_CLOSE } ` ,
113
130
DEFAULT_AUTH_TOKEN ,
114
131
undefined ,
@@ -143,7 +160,7 @@ describe('TodoistApi task endpoints', () => {
143
160
expect ( requestMock ) . toBeCalledTimes ( 1 )
144
161
expect ( requestMock ) . toBeCalledWith (
145
162
'POST' ,
146
- API_REST_BASE_URI ,
163
+ getRestBaseUri ( ) ,
147
164
`${ ENDPOINT_REST_TASKS } /${ taskId } /${ ENDPOINT_REST_TASK_REOPEN } ` ,
148
165
DEFAULT_AUTH_TOKEN ,
149
166
undefined ,
@@ -178,7 +195,7 @@ describe('TodoistApi task endpoints', () => {
178
195
expect ( requestMock ) . toBeCalledTimes ( 1 )
179
196
expect ( requestMock ) . toBeCalledWith (
180
197
'DELETE' ,
181
- API_REST_BASE_URI ,
198
+ getRestBaseUri ( ) ,
182
199
`${ ENDPOINT_REST_TASKS } /${ taskId } ` ,
183
200
DEFAULT_AUTH_TOKEN ,
184
201
undefined ,
@@ -219,7 +236,7 @@ describe('TodoistApi task endpoints', () => {
219
236
expect ( requestMock ) . toBeCalledTimes ( 1 )
220
237
expect ( requestMock ) . toBeCalledWith (
221
238
'POST' ,
222
- API_SYNC_BASE_URI ,
239
+ getSyncBaseUri ( ) ,
223
240
ENDPOINT_SYNC_QUICK_ADD ,
224
241
DEFAULT_AUTH_TOKEN ,
225
242
DEFAULT_QUICK_ADD_ARGS ,
@@ -250,7 +267,7 @@ describe('TodoistApi task endpoints', () => {
250
267
expect ( requestMock ) . toBeCalledTimes ( 1 )
251
268
expect ( requestMock ) . toBeCalledWith (
252
269
'GET' ,
253
- API_REST_BASE_URI ,
270
+ getRestBaseUri ( ) ,
254
271
`${ ENDPOINT_REST_TASKS } /${ taskId } ` ,
255
272
DEFAULT_AUTH_TOKEN ,
256
273
)
@@ -277,7 +294,7 @@ describe('TodoistApi task endpoints', () => {
277
294
expect ( requestMock ) . toBeCalledTimes ( 1 )
278
295
expect ( requestMock ) . toBeCalledWith (
279
296
'GET' ,
280
- API_REST_BASE_URI ,
297
+ getRestBaseUri ( ) ,
281
298
ENDPOINT_REST_TASKS ,
282
299
DEFAULT_AUTH_TOKEN ,
283
300
DEFAULT_GET_TASKS_ARGS ,
0 commit comments