Skip to content

Commit 44cac53

Browse files
refactor: Accept nulls for optional entity fields (#136)
1 parent 68060f2 commit 44cac53

11 files changed

+179
-256
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ node_modules/
44
.npm
55
.eslintcache
66
scratch.ts
7+
8+
.vscode/

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": "2.0.0",
3+
"version": "2.0.1",
44
"description": "A typescript wrapper for the Todoist REST API.",
55
"author": "Doist developers",
66
"repository": "[email protected]:doist/todoist-api-typescript.git",

src/TodoistApi.comments.test.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { TodoistApi } from '.'
22
import {
3+
COMMENT_WITH_ATTACHMENT_WITH_OPTIONALS_AS_NULL,
4+
COMMENT_WITH_OPTIONALS_AS_NULL_PROJECT,
5+
COMMENT_WITH_OPTIONALS_AS_NULL_TASK,
36
DEFAULT_AUTH_TOKEN,
47
DEFAULT_COMMENT,
58
DEFAULT_REQUEST_ID,
6-
INVALID_ENTITY_ID,
79
} from './testUtils/testDefaults'
810
import { getRestBaseUri, ENDPOINT_REST_COMMENTS } from './consts/endpoints'
911
import { setupRestClientMock } from './testUtils/mocks'
10-
import { assertInputValidationError } from './testUtils/asserts'
1112

1213
function getTarget() {
1314
return new TodoistApi(DEFAULT_AUTH_TOKEN)
@@ -33,7 +34,12 @@ describe('TodoistApi comment endpoints', () => {
3334
})
3435

3536
test('returns result from rest client', async () => {
36-
const expectedComments = [DEFAULT_COMMENT]
37+
const expectedComments = [
38+
DEFAULT_COMMENT,
39+
COMMENT_WITH_OPTIONALS_AS_NULL_TASK,
40+
COMMENT_WITH_OPTIONALS_AS_NULL_PROJECT,
41+
COMMENT_WITH_ATTACHMENT_WITH_OPTIONALS_AS_NULL,
42+
]
3743
setupRestClientMock(expectedComments)
3844
const api = getTarget()
3945

@@ -45,7 +51,7 @@ describe('TodoistApi comment endpoints', () => {
4551

4652
describe('getComment', () => {
4753
test('calls get on expected url', async () => {
48-
const commentId = 1
54+
const commentId = '1'
4955
const requestMock = setupRestClientMock(DEFAULT_COMMENT)
5056
const api = getTarget()
5157

@@ -65,16 +71,10 @@ describe('TodoistApi comment endpoints', () => {
6571
setupRestClientMock(expectedComment)
6672
const api = getTarget()
6773

68-
const comment = await api.getComment(1)
74+
const comment = await api.getComment('1')
6975

7076
expect(comment).toEqual(expectedComment)
7177
})
72-
73-
test('throws validation error for invalid id input', async () => {
74-
await assertInputValidationError(
75-
async () => await getTarget().getComment(INVALID_ENTITY_ID),
76-
)
77-
})
7878
})
7979

8080
describe('addComment', () => {
@@ -117,7 +117,7 @@ describe('TodoistApi comment endpoints', () => {
117117
}
118118

119119
test('makes post request with expected params', async () => {
120-
const taskId = 1
120+
const taskId = '1'
121121
const requestMock = setupRestClientMock(DEFAULT_COMMENT, 204)
122122
const api = getTarget()
123123

@@ -139,21 +139,15 @@ describe('TodoistApi comment endpoints', () => {
139139
setupRestClientMock(returnedComment, 204)
140140
const api = getTarget()
141141

142-
const result = await api.updateComment(1, updateCommentArgs)
142+
const result = await api.updateComment('1', updateCommentArgs)
143143

144144
expect(result).toEqual(returnedComment)
145145
})
146-
147-
test('throws validation error for invalid id input', async () => {
148-
await assertInputValidationError(
149-
async () => await getTarget().updateComment(INVALID_ENTITY_ID, updateCommentArgs),
150-
)
151-
})
152146
})
153147

154148
describe('deleteComment', () => {
155149
test('makes delete request on expected url', async () => {
156-
const taskId = 1
150+
const taskId = '1'
157151
const requestMock = setupRestClientMock(undefined, 204)
158152
const api = getTarget()
159153

@@ -174,15 +168,9 @@ describe('TodoistApi comment endpoints', () => {
174168
setupRestClientMock(undefined, 204)
175169
const api = getTarget()
176170

177-
const result = await api.deleteComment(1)
171+
const result = await api.deleteComment('1')
178172

179173
expect(result).toEqual(true)
180174
})
181-
182-
test('throws validation error for invalid id input', async () => {
183-
await assertInputValidationError(
184-
async () => await getTarget().deleteComment(INVALID_ENTITY_ID),
185-
)
186-
})
187175
})
188176
})

src/TodoistApi.labels.test.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { TodoistApi } from '.'
2-
import {
3-
DEFAULT_AUTH_TOKEN,
4-
DEFAULT_LABEL,
5-
DEFAULT_REQUEST_ID,
6-
INVALID_ENTITY_ID,
7-
} from './testUtils/testDefaults'
2+
import { DEFAULT_AUTH_TOKEN, DEFAULT_LABEL, DEFAULT_REQUEST_ID } from './testUtils/testDefaults'
83
import { getRestBaseUri, ENDPOINT_REST_LABELS } from './consts/endpoints'
94
import { setupRestClientMock } from './testUtils/mocks'
10-
import { assertInputValidationError } from './testUtils/asserts'
115

126
function getTarget() {
137
return new TodoistApi(DEFAULT_AUTH_TOKEN)
@@ -16,7 +10,7 @@ function getTarget() {
1610
describe('TodoistApi label endpoints', () => {
1711
describe('getLabel', () => {
1812
test('calls get request with expected url', async () => {
19-
const labelId = 12
13+
const labelId = '12'
2014
const requestMock = setupRestClientMock(DEFAULT_LABEL)
2115
const api = getTarget()
2216

@@ -35,16 +29,10 @@ describe('TodoistApi label endpoints', () => {
3529
setupRestClientMock(DEFAULT_LABEL)
3630
const api = getTarget()
3731

38-
const label = await api.getLabel(123)
32+
const label = await api.getLabel('123')
3933

4034
expect(label).toEqual(DEFAULT_LABEL)
4135
})
42-
43-
test('throws validation error for invalid id input', async () => {
44-
await assertInputValidationError(
45-
async () => await getTarget().getLabel(INVALID_ENTITY_ID),
46-
)
47-
})
4836
})
4937

5038
describe('getLabels', () => {
@@ -112,7 +100,7 @@ describe('TodoistApi label endpoints', () => {
112100
}
113101

114102
test('calls post on restClient with expected parameters', async () => {
115-
const labelId = 123
103+
const labelId = '123'
116104
const requestMock = setupRestClientMock(DEFAULT_LABEL, 204)
117105
const api = getTarget()
118106

@@ -134,22 +122,15 @@ describe('TodoistApi label endpoints', () => {
134122
setupRestClientMock(returnedTask, 204)
135123
const api = getTarget()
136124

137-
const result = await api.updateLabel(123, DEFAULT_UPDATE_LABEL_ARGS)
125+
const result = await api.updateLabel('123', DEFAULT_UPDATE_LABEL_ARGS)
138126

139127
expect(result).toEqual(returnedTask)
140128
})
141-
142-
test('throws validation error for invalid id input', async () => {
143-
await assertInputValidationError(
144-
async () =>
145-
await getTarget().updateLabel(INVALID_ENTITY_ID, DEFAULT_UPDATE_LABEL_ARGS),
146-
)
147-
})
148129
})
149130

150131
describe('deleteLabel', () => {
151132
test('calls delete on expected label', async () => {
152-
const labelId = 123
133+
const labelId = '123'
153134
const requestMock = setupRestClientMock(undefined, 204)
154135
const api = getTarget()
155136

@@ -170,15 +151,9 @@ describe('TodoistApi label endpoints', () => {
170151
setupRestClientMock(undefined, 204)
171152
const api = getTarget()
172153

173-
const result = await api.deleteLabel(123)
154+
const result = await api.deleteLabel('123')
174155

175156
expect(result).toEqual(true)
176157
})
177-
178-
test('throws validation error for invalid id input', async () => {
179-
await assertInputValidationError(
180-
async () => await getTarget().deleteLabel(INVALID_ENTITY_ID),
181-
)
182-
})
183158
})
184159
})

src/TodoistApi.projects.test.ts

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import {
44
DEFAULT_PROJECT,
55
DEFAULT_REQUEST_ID,
66
DEFAULT_USER,
7-
INVALID_ENTITY_ID,
7+
PROJECT_WITH_OPTIONALS_AS_NULL,
88
} from './testUtils/testDefaults'
99
import {
1010
getRestBaseUri,
1111
ENDPOINT_REST_PROJECTS,
1212
ENDPOINT_REST_PROJECT_COLLABORATORS,
1313
} from './consts/endpoints'
1414
import { setupRestClientMock } from './testUtils/mocks'
15-
import { assertInputValidationError } from './testUtils/asserts'
1615

1716
function getTarget() {
1817
return new TodoistApi(DEFAULT_AUTH_TOKEN)
@@ -21,7 +20,7 @@ function getTarget() {
2120
describe('TodoistApi project endpoints', () => {
2221
describe('getProject', () => {
2322
test('calls get request with expected url', async () => {
24-
const projectId = 12
23+
const projectId = '12'
2524
const requestMock = setupRestClientMock(DEFAULT_PROJECT)
2625
const api = getTarget()
2726

@@ -40,16 +39,10 @@ describe('TodoistApi project endpoints', () => {
4039
setupRestClientMock(DEFAULT_PROJECT)
4140
const api = getTarget()
4241

43-
const project = await api.getProject(123)
42+
const project = await api.getProject('123')
4443

4544
expect(project).toEqual(DEFAULT_PROJECT)
4645
})
47-
48-
test('throws validation error for invalid id input', async () => {
49-
await assertInputValidationError(
50-
async () => await getTarget().getProject(INVALID_ENTITY_ID),
51-
)
52-
})
5346
})
5447

5548
describe('getProjects', () => {
@@ -69,7 +62,7 @@ describe('TodoistApi project endpoints', () => {
6962
})
7063

7164
test('returns result from rest client', async () => {
72-
const projects = [DEFAULT_PROJECT]
65+
const projects = [DEFAULT_PROJECT, PROJECT_WITH_OPTIONALS_AS_NULL]
7366
setupRestClientMock(projects)
7467
const api = getTarget()
7568

@@ -114,7 +107,7 @@ describe('TodoistApi project endpoints', () => {
114107
describe('updateProject', () => {
115108
const DEFAULT_UPDATE_PROJECT_ARGS = { name: 'a name' }
116109
test('calls post on restClient with expected parameters', async () => {
117-
const projectId = 123
110+
const projectId = '123'
118111
const updateArgs = { name: 'a new name' }
119112
const requestMock = setupRestClientMock(DEFAULT_PROJECT, 204)
120113
const api = getTarget()
@@ -137,22 +130,15 @@ describe('TodoistApi project endpoints', () => {
137130
setupRestClientMock(returnedProject, 204)
138131
const api = getTarget()
139132

140-
const result = await api.updateProject(123, DEFAULT_UPDATE_PROJECT_ARGS)
133+
const result = await api.updateProject('123', DEFAULT_UPDATE_PROJECT_ARGS)
141134

142135
expect(result).toEqual(returnedProject)
143136
})
144-
145-
test('throws validation error for invalid id input', async () => {
146-
await assertInputValidationError(
147-
async () =>
148-
await getTarget().updateProject(INVALID_ENTITY_ID, DEFAULT_UPDATE_PROJECT_ARGS),
149-
)
150-
})
151137
})
152138

153139
describe('deleteProject', () => {
154140
test('calls delete on expected project', async () => {
155-
const projectId = 123
141+
const projectId = '123'
156142
const requestMock = setupRestClientMock(undefined, 204)
157143
const api = getTarget()
158144

@@ -172,20 +158,14 @@ describe('TodoistApi project endpoints', () => {
172158
setupRestClientMock(undefined, 204)
173159
const api = getTarget()
174160

175-
const result = await api.deleteProject(123)
161+
const result = await api.deleteProject('123')
176162

177163
expect(result).toEqual(true)
178164
})
179-
180-
test('throws validation error for invalid id input', async () => {
181-
await assertInputValidationError(
182-
async () => await getTarget().deleteProject(INVALID_ENTITY_ID),
183-
)
184-
})
185165
})
186166

187167
describe('getProjectCollaborators', () => {
188-
const projectId = 123
168+
const projectId = '123'
189169
const users = [DEFAULT_USER]
190170

191171
test('calls get on expected endpoint', async () => {
@@ -211,11 +191,5 @@ describe('TodoistApi project endpoints', () => {
211191

212192
expect(returnedUsers).toEqual(users)
213193
})
214-
215-
test('throws validation error for invalid id input', async () => {
216-
await assertInputValidationError(
217-
async () => await getTarget().getProjectCollaborators(INVALID_ENTITY_ID),
218-
)
219-
})
220194
})
221195
})

0 commit comments

Comments
 (0)