Skip to content

Commit 31a35c5

Browse files
Merge pull request #130 from Doist/scottl/add-staging
chore: Adds support for accessing Todoist via a baseUrl
2 parents 73772d6 + f2e1a66 commit 31a35c5

11 files changed

+146
-84
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@doist/todoist-api-typescript",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"description": "A typescript wrapper for the Todoist REST API.",
55
"author": "Doist developers",
66
"repository": "git@github.com:doist/todoist-api-typescript.git",

src/TodoistApi.comments.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
DEFAULT_REQUEST_ID,
66
INVALID_ENTITY_ID,
77
} from './testUtils/testDefaults'
8-
import { API_REST_BASE_URI, ENDPOINT_REST_COMMENTS } from './consts/endpoints'
8+
import { getRestBaseUri, ENDPOINT_REST_COMMENTS } from './consts/endpoints'
99
import { setupRestClientMock } from './testUtils/mocks'
1010
import { assertInputValidationError } from './testUtils/asserts'
1111

@@ -25,7 +25,7 @@ describe('TodoistApi comment endpoints', () => {
2525
expect(requestMock).toBeCalledTimes(1)
2626
expect(requestMock).toBeCalledWith(
2727
'GET',
28-
API_REST_BASE_URI,
28+
getRestBaseUri(),
2929
ENDPOINT_REST_COMMENTS,
3030
DEFAULT_AUTH_TOKEN,
3131
getCommentsArgs,
@@ -54,7 +54,7 @@ describe('TodoistApi comment endpoints', () => {
5454
expect(requestMock).toBeCalledTimes(1)
5555
expect(requestMock).toBeCalledWith(
5656
'GET',
57-
API_REST_BASE_URI,
57+
getRestBaseUri(),
5858
`${ENDPOINT_REST_COMMENTS}/${commentId}`,
5959
DEFAULT_AUTH_TOKEN,
6060
)
@@ -92,7 +92,7 @@ describe('TodoistApi comment endpoints', () => {
9292
expect(requestMock).toBeCalledTimes(1)
9393
expect(requestMock).toBeCalledWith(
9494
'POST',
95-
API_REST_BASE_URI,
95+
getRestBaseUri(),
9696
ENDPOINT_REST_COMMENTS,
9797
DEFAULT_AUTH_TOKEN,
9898
addCommentArgs,
@@ -126,7 +126,7 @@ describe('TodoistApi comment endpoints', () => {
126126
expect(requestMock).toBeCalledTimes(1)
127127
expect(requestMock).toBeCalledWith(
128128
'POST',
129-
API_REST_BASE_URI,
129+
getRestBaseUri(),
130130
`${ENDPOINT_REST_COMMENTS}/${taskId}`,
131131
DEFAULT_AUTH_TOKEN,
132132
updateCommentArgs,
@@ -161,7 +161,7 @@ describe('TodoistApi comment endpoints', () => {
161161
expect(requestMock).toBeCalledTimes(1)
162162
expect(requestMock).toBeCalledWith(
163163
'DELETE',
164-
API_REST_BASE_URI,
164+
getRestBaseUri(),
165165
`${ENDPOINT_REST_COMMENTS}/${taskId}`,
166166
DEFAULT_AUTH_TOKEN,
167167
undefined,

src/TodoistApi.labels.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
DEFAULT_REQUEST_ID,
66
INVALID_ENTITY_ID,
77
} from './testUtils/testDefaults'
8-
import { API_REST_BASE_URI, ENDPOINT_REST_LABELS } from './consts/endpoints'
8+
import { getRestBaseUri, ENDPOINT_REST_LABELS } from './consts/endpoints'
99
import { setupRestClientMock } from './testUtils/mocks'
1010
import { assertInputValidationError } from './testUtils/asserts'
1111

@@ -25,7 +25,7 @@ describe('TodoistApi label endpoints', () => {
2525
expect(requestMock).toBeCalledTimes(1)
2626
expect(requestMock).toBeCalledWith(
2727
'GET',
28-
API_REST_BASE_URI,
28+
getRestBaseUri(),
2929
`${ENDPOINT_REST_LABELS}/${labelId}`,
3030
DEFAULT_AUTH_TOKEN,
3131
)
@@ -57,7 +57,7 @@ describe('TodoistApi label endpoints', () => {
5757
expect(requestMock).toBeCalledTimes(1)
5858
expect(requestMock).toBeCalledWith(
5959
'GET',
60-
API_REST_BASE_URI,
60+
getRestBaseUri(),
6161
ENDPOINT_REST_LABELS,
6262
DEFAULT_AUTH_TOKEN,
6363
)
@@ -88,7 +88,7 @@ describe('TodoistApi label endpoints', () => {
8888
expect(requestMock).toBeCalledTimes(1)
8989
expect(requestMock).toBeCalledWith(
9090
'POST',
91-
API_REST_BASE_URI,
91+
getRestBaseUri(),
9292
ENDPOINT_REST_LABELS,
9393
DEFAULT_AUTH_TOKEN,
9494
DEFAULT_ADD_LABEL_ARGS,
@@ -121,7 +121,7 @@ describe('TodoistApi label endpoints', () => {
121121
expect(requestMock).toBeCalledTimes(1)
122122
expect(requestMock).toBeCalledWith(
123123
'POST',
124-
API_REST_BASE_URI,
124+
getRestBaseUri(),
125125
`${ENDPOINT_REST_LABELS}/${labelId}`,
126126
DEFAULT_AUTH_TOKEN,
127127
DEFAULT_UPDATE_LABEL_ARGS,
@@ -157,7 +157,7 @@ describe('TodoistApi label endpoints', () => {
157157
expect(requestMock).toBeCalledTimes(1)
158158
expect(requestMock).toBeCalledWith(
159159
'DELETE',
160-
API_REST_BASE_URI,
160+
getRestBaseUri(),
161161
`${ENDPOINT_REST_LABELS}/${labelId}`,
162162
DEFAULT_AUTH_TOKEN,
163163
undefined,

src/TodoistApi.projects.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
INVALID_ENTITY_ID,
88
} from './testUtils/testDefaults'
99
import {
10-
API_REST_BASE_URI,
10+
getRestBaseUri,
1111
ENDPOINT_REST_PROJECTS,
1212
ENDPOINT_REST_PROJECT_COLLABORATORS,
1313
} from './consts/endpoints'
@@ -30,7 +30,7 @@ describe('TodoistApi project endpoints', () => {
3030
expect(requestMock).toBeCalledTimes(1)
3131
expect(requestMock).toBeCalledWith(
3232
'GET',
33-
API_REST_BASE_URI,
33+
getRestBaseUri(),
3434
`${ENDPOINT_REST_PROJECTS}/${projectId}`,
3535
DEFAULT_AUTH_TOKEN,
3636
)
@@ -62,7 +62,7 @@ describe('TodoistApi project endpoints', () => {
6262
expect(requestMock).toBeCalledTimes(1)
6363
expect(requestMock).toBeCalledWith(
6464
'GET',
65-
API_REST_BASE_URI,
65+
getRestBaseUri(),
6666
ENDPOINT_REST_PROJECTS,
6767
DEFAULT_AUTH_TOKEN,
6868
)
@@ -93,7 +93,7 @@ describe('TodoistApi project endpoints', () => {
9393
expect(requestMock).toBeCalledTimes(1)
9494
expect(requestMock).toBeCalledWith(
9595
'POST',
96-
API_REST_BASE_URI,
96+
getRestBaseUri(),
9797
ENDPOINT_REST_PROJECTS,
9898
DEFAULT_AUTH_TOKEN,
9999
DEFAULT_ADD_PROJECT_ARGS,
@@ -123,7 +123,7 @@ describe('TodoistApi project endpoints', () => {
123123
expect(requestMock).toBeCalledTimes(1)
124124
expect(requestMock).toBeCalledWith(
125125
'POST',
126-
API_REST_BASE_URI,
126+
getRestBaseUri(),
127127
`${ENDPOINT_REST_PROJECTS}/${projectId}`,
128128
DEFAULT_AUTH_TOKEN,
129129
updateArgs,
@@ -158,7 +158,7 @@ describe('TodoistApi project endpoints', () => {
158158
expect(requestMock).toBeCalledTimes(1)
159159
expect(requestMock).toBeCalledWith(
160160
'DELETE',
161-
API_REST_BASE_URI,
161+
getRestBaseUri(),
162162
`${ENDPOINT_REST_PROJECTS}/${projectId}`,
163163
DEFAULT_AUTH_TOKEN,
164164
DEFAULT_REQUEST_ID,
@@ -194,7 +194,7 @@ describe('TodoistApi project endpoints', () => {
194194
expect(requestMock).toBeCalledTimes(1)
195195
expect(requestMock).toBeCalledWith(
196196
'GET',
197-
API_REST_BASE_URI,
197+
getRestBaseUri(),
198198
`${ENDPOINT_REST_PROJECTS}/${projectId}/${ENDPOINT_REST_PROJECT_COLLABORATORS}`,
199199
DEFAULT_AUTH_TOKEN,
200200
)

src/TodoistApi.sections.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
DEFAULT_SECTION,
66
INVALID_ENTITY_ID,
77
} from './testUtils/testDefaults'
8-
import { API_REST_BASE_URI, ENDPOINT_REST_SECTIONS } from './consts/endpoints'
8+
import { getRestBaseUri, ENDPOINT_REST_SECTIONS } from './consts/endpoints'
99
import { setupRestClientMock } from './testUtils/mocks'
1010
import { assertInputValidationError } from './testUtils/asserts'
1111

@@ -25,7 +25,7 @@ describe('TodoistApi section endpoints', () => {
2525
expect(requestMock).toBeCalledTimes(1)
2626
expect(requestMock).toBeCalledWith(
2727
'GET',
28-
API_REST_BASE_URI,
28+
getRestBaseUri(),
2929
`${ENDPOINT_REST_SECTIONS}/${sectionId}`,
3030
DEFAULT_AUTH_TOKEN,
3131
)
@@ -58,7 +58,7 @@ describe('TodoistApi section endpoints', () => {
5858
expect(requestMock).toBeCalledTimes(1)
5959
expect(requestMock).toBeCalledWith(
6060
'GET',
61-
API_REST_BASE_URI,
61+
getRestBaseUri(),
6262
ENDPOINT_REST_SECTIONS,
6363
DEFAULT_AUTH_TOKEN,
6464
{ projectId },
@@ -91,7 +91,7 @@ describe('TodoistApi section endpoints', () => {
9191
expect(requestMock).toBeCalledTimes(1)
9292
expect(requestMock).toBeCalledWith(
9393
'POST',
94-
API_REST_BASE_URI,
94+
getRestBaseUri(),
9595
ENDPOINT_REST_SECTIONS,
9696
DEFAULT_AUTH_TOKEN,
9797
DEFAULT_ADD_SECTION_ARGS,
@@ -121,7 +121,7 @@ describe('TodoistApi section endpoints', () => {
121121
expect(requestMock).toBeCalledTimes(1)
122122
expect(requestMock).toBeCalledWith(
123123
'POST',
124-
API_REST_BASE_URI,
124+
getRestBaseUri(),
125125
`${ENDPOINT_REST_SECTIONS}/${sectionId}`,
126126
DEFAULT_AUTH_TOKEN,
127127
updateArgs,
@@ -157,7 +157,7 @@ describe('TodoistApi section endpoints', () => {
157157
expect(requestMock).toBeCalledTimes(1)
158158
expect(requestMock).toBeCalledWith(
159159
'DELETE',
160-
API_REST_BASE_URI,
160+
getRestBaseUri(),
161161
`${ENDPOINT_REST_SECTIONS}/${sectionId}`,
162162
DEFAULT_AUTH_TOKEN,
163163
undefined,

src/TodoistApi.tasks.test.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
INVALID_ENTITY_ID,
1010
} from './testUtils/testDefaults'
1111
import {
12-
API_REST_BASE_URI,
13-
API_SYNC_BASE_URI,
12+
getRestBaseUri,
13+
getSyncBaseUri,
1414
ENDPOINT_REST_TASK_CLOSE,
1515
ENDPOINT_REST_TASK_REOPEN,
1616
ENDPOINT_REST_TASKS,
@@ -23,8 +23,8 @@ function setupSyncTaskConverter(returnedTask: Task) {
2323
return jest.spyOn(taskConverters, 'getTaskFromQuickAddResponse').mockReturnValue(returnedTask)
2424
}
2525

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)
2828
}
2929

3030
describe('TodoistApi task endpoints', () => {
@@ -42,7 +42,24 @@ describe('TodoistApi task endpoints', () => {
4242
expect(requestMock).toBeCalledTimes(1)
4343
expect(requestMock).toBeCalledWith(
4444
'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'),
4663
ENDPOINT_REST_TASKS,
4764
DEFAULT_AUTH_TOKEN,
4865
DEFAULT_ADD_TASK_ARGS,
@@ -72,7 +89,7 @@ describe('TodoistApi task endpoints', () => {
7289
expect(requestMock).toBeCalledTimes(1)
7390
expect(requestMock).toBeCalledWith(
7491
'POST',
75-
API_REST_BASE_URI,
92+
getRestBaseUri(),
7693
`${ENDPOINT_REST_TASKS}/${taskId}`,
7794
DEFAULT_AUTH_TOKEN,
7895
updateArgs,
@@ -108,7 +125,7 @@ describe('TodoistApi task endpoints', () => {
108125
expect(requestMock).toBeCalledTimes(1)
109126
expect(requestMock).toBeCalledWith(
110127
'POST',
111-
API_REST_BASE_URI,
128+
getRestBaseUri(),
112129
`${ENDPOINT_REST_TASKS}/${taskId}/${ENDPOINT_REST_TASK_CLOSE}`,
113130
DEFAULT_AUTH_TOKEN,
114131
undefined,
@@ -143,7 +160,7 @@ describe('TodoistApi task endpoints', () => {
143160
expect(requestMock).toBeCalledTimes(1)
144161
expect(requestMock).toBeCalledWith(
145162
'POST',
146-
API_REST_BASE_URI,
163+
getRestBaseUri(),
147164
`${ENDPOINT_REST_TASKS}/${taskId}/${ENDPOINT_REST_TASK_REOPEN}`,
148165
DEFAULT_AUTH_TOKEN,
149166
undefined,
@@ -178,7 +195,7 @@ describe('TodoistApi task endpoints', () => {
178195
expect(requestMock).toBeCalledTimes(1)
179196
expect(requestMock).toBeCalledWith(
180197
'DELETE',
181-
API_REST_BASE_URI,
198+
getRestBaseUri(),
182199
`${ENDPOINT_REST_TASKS}/${taskId}`,
183200
DEFAULT_AUTH_TOKEN,
184201
undefined,
@@ -219,7 +236,7 @@ describe('TodoistApi task endpoints', () => {
219236
expect(requestMock).toBeCalledTimes(1)
220237
expect(requestMock).toBeCalledWith(
221238
'POST',
222-
API_SYNC_BASE_URI,
239+
getSyncBaseUri(),
223240
ENDPOINT_SYNC_QUICK_ADD,
224241
DEFAULT_AUTH_TOKEN,
225242
DEFAULT_QUICK_ADD_ARGS,
@@ -250,7 +267,7 @@ describe('TodoistApi task endpoints', () => {
250267
expect(requestMock).toBeCalledTimes(1)
251268
expect(requestMock).toBeCalledWith(
252269
'GET',
253-
API_REST_BASE_URI,
270+
getRestBaseUri(),
254271
`${ENDPOINT_REST_TASKS}/${taskId}`,
255272
DEFAULT_AUTH_TOKEN,
256273
)
@@ -277,7 +294,7 @@ describe('TodoistApi task endpoints', () => {
277294
expect(requestMock).toBeCalledTimes(1)
278295
expect(requestMock).toBeCalledWith(
279296
'GET',
280-
API_REST_BASE_URI,
297+
getRestBaseUri(),
281298
ENDPOINT_REST_TASKS,
282299
DEFAULT_AUTH_TOKEN,
283300
DEFAULT_GET_TASKS_ARGS,

0 commit comments

Comments
 (0)