Skip to content

Commit 7b7b752

Browse files
chore: Corrects the quick add types and fixes the tests
1 parent c0a986c commit 7b7b752

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

src/TodoistApi.comments.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function getTarget() {
1616
describe('TodoistApi comment endpoints', () => {
1717
describe('getComments', () => {
1818
test('calls get request with expected params', async () => {
19-
const getCommentsArgs = { projectId: 12 }
19+
const getCommentsArgs = { projectId: '12' }
2020
const requestMock = setupRestClientMock([DEFAULT_COMMENT])
2121
const api = getTarget()
2222

@@ -37,7 +37,7 @@ describe('TodoistApi comment endpoints', () => {
3737
setupRestClientMock(expectedComments)
3838
const api = getTarget()
3939

40-
const comments = await api.getComments({ taskId: 12 })
40+
const comments = await api.getComments({ taskId: '12' })
4141

4242
expect(comments).toEqual(expectedComments)
4343
})
@@ -80,7 +80,7 @@ describe('TodoistApi comment endpoints', () => {
8080
describe('addComment', () => {
8181
const addCommentArgs = {
8282
content: 'A comment',
83-
taskId: 123,
83+
taskId: '123',
8484
}
8585

8686
test('makes post request with expected params', async () => {

src/TodoistApi.sections.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('TodoistApi section endpoints', () => {
7979
describe('addSection', () => {
8080
const DEFAULT_ADD_SECTION_ARGS = {
8181
name: 'This is a section',
82-
projectId: 123,
82+
projectId: '123',
8383
}
8484

8585
test('calls post on restClient with expected parameters', async () => {

src/TodoistApi.tasks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ describe('TodoistApi task endpoints', () => {
265265

266266
describe('getTasks', () => {
267267
const DEFAULT_GET_TASKS_ARGS = {
268-
projectId: 123,
268+
projectId: '123',
269269
}
270270

271271
test('calls get on expected endpoint with args', async () => {

src/testUtils/testDefaults.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const DEFAULT_SECTION_ID = '456'
2323
const DEFAULT_SECTION_NAME = 'This is a section'
2424
const DEFAULT_PARENT_ID = '5678'
2525
const DEFAULT_ASSIGNEE = '1234'
26+
const DEFAULT_CREATOR = '1234'
2627
const DEFAULT_DATE = '2020-09-08T12:00:00Z'
2728
const DEFAULT_ENTITY_COLOR = 'berry_red'
2829
const DEFAULT_LABELS = ['personal', 'work', 'hobby']
@@ -49,18 +50,19 @@ export const INVALID_DUE_DATE = {
4950
}
5051

5152
export const DEFAULT_QUICK_ADD_RESPONSE: QuickAddTaskResponse = {
52-
id: DEFAULT_TASK_ID,
53-
projectId: DEFAULT_PROJECT_ID,
53+
id: parseInt(DEFAULT_TASK_ID),
54+
projectId: parseInt(DEFAULT_PROJECT_ID),
5455
content: DEFAULT_TASK_CONTENT,
5556
description: DEFAULT_TASK_DESCRIPTION,
5657
priority: DEFAULT_TASK_PRIORITY,
57-
sectionId: DEFAULT_SECTION_ID,
58-
parentId: DEFAULT_PARENT_ID,
58+
sectionId: parseInt(DEFAULT_SECTION_ID),
59+
parentId: parseInt(DEFAULT_PARENT_ID),
5960
childOrder: DEFAULT_ORDER,
60-
labels: DEFAULT_LABELS,
61-
responsibleUid: DEFAULT_ASSIGNEE,
61+
labels: [1, 2, 3],
62+
responsibleUid: parseInt(DEFAULT_ASSIGNEE),
6263
checked: 0,
6364
dateAdded: DEFAULT_DATE,
65+
creatorId: parseInt(DEFAULT_CREATOR),
6466
due: {
6567
date: DEFAULT_DATE,
6668
timezone: null,
@@ -86,6 +88,7 @@ export const DEFAULT_TASK: Task = {
8688
url: 'https://todoist.com/showTask?id=1234',
8789
due: DEFAULT_DUE_DATE,
8890
assigneeId: DEFAULT_ASSIGNEE,
91+
creatorId: DEFAULT_CREATOR,
8992
}
9093

9194
export const INVALID_TASK = {

src/types/entities.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const Task = Record({
5151
commentCount: Int,
5252
createdAt: String,
5353
url: String,
54+
creatorId: String,
5455
}).And(
5556
Partial({
5657
due: DueDate,
@@ -150,18 +151,19 @@ export type Color = TodoistEntity & {
150151
}
151152

152153
export type QuickAddTaskResponse = {
153-
id: string
154-
projectId: string
154+
id: number
155+
projectId: number
155156
content: string
156157
description: string
157158
priority: number
158-
sectionId: string | null
159-
parentId: string | null
159+
sectionId: number | null
160+
parentId: number | null
160161
childOrder: number // order
161-
labels: string[] // labelIds
162-
responsibleUid: string | null
162+
labels: number[] // labelIds
163+
responsibleUid: number | null
163164
checked: number // completed
164165
dateAdded: string // created
166+
creatorId: number | null
165167
due: {
166168
date: string
167169
timezone: string | null

src/utils/colors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getColor, berryRed, charcoal, taupe } from './colors'
1+
import { berryRed, charcoal, taupe, getColorById } from './colors'
22

33
describe('getColor', () => {
44
const colorTheories = [
@@ -9,7 +9,7 @@ describe('getColor', () => {
99
] as const
1010

1111
test.each(colorTheories)('id %p returns color %p', (id, expected) => {
12-
const color = getColor(id)
12+
const color = getColorById(id)
1313
expect(color).toEqual(expected)
1414
})
1515
})

src/utils/taskConverters.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DEFAULT_QUICK_ADD_RESPONSE, DEFAULT_TASK } from '../testUtils/testDefau
44
describe('getTaskFromQuickAddResponse', () => {
55
test('maps sync data to expected task properties', () => {
66
const task = getTaskFromQuickAddResponse(DEFAULT_QUICK_ADD_RESPONSE)
7-
expect(task).toEqual(DEFAULT_TASK)
7+
expect(task).toEqual({ ...DEFAULT_TASK, labels: ['1', '2', '3'] })
88
})
99

1010
test('converts null sectionId to null', () => {
@@ -62,8 +62,8 @@ describe('getTaskFromQuickAddResponse', () => {
6262
})
6363

6464
const taskUrlTheories = [
65-
['1234', 'https://todoist.com/showTask?id=1234'],
66-
['1234', 'https://todoist.com/showTask?id=1234'],
65+
[1234, 'https://todoist.com/showTask?id=1234'],
66+
[1234, 'https://todoist.com/showTask?id=1234'],
6767
] as const
6868

6969
test.each(taskUrlTheories)('with id %p and syncId %p returns url %p', (id, url) => {

src/utils/taskConverters.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ export function getTaskFromQuickAddResponse(responseData: QuickAddTaskResponse):
1818
: undefined
1919

2020
const task = {
21-
id: responseData.id,
21+
id: String(responseData.id),
2222
order: responseData.childOrder,
2323
content: responseData.content,
2424
description: responseData.description,
25-
projectId: responseData.projectId,
26-
sectionId: responseData.sectionId ?? undefined,
25+
projectId: String(responseData.projectId),
26+
sectionId: responseData.sectionId ? String(responseData.sectionId) : undefined,
2727
isCompleted: responseData.checked === 1,
28-
labels: responseData.labels,
28+
labels: responseData.labels.map((x) => String(x)),
2929
priority: responseData.priority,
3030
commentCount: 0, // Will always be 0 for a quick add
3131
createdAt: responseData.dateAdded,
3232
url: getTaskUrlFromQuickAddResponse(responseData),
33+
creatorId: responseData.creatorId ? String(responseData.creatorId) : '',
3334
...(due !== undefined && { due }),
34-
...(responseData.parentId !== null && { parentId: responseData.parentId }),
35-
...(responseData.responsibleUid !== null && { assigneeId: responseData.responsibleUid }),
35+
...(responseData.parentId !== null && { parentId: String(responseData.parentId) }),
36+
...(responseData.responsibleUid !== null && {
37+
assigneeId: String(responseData.responsibleUid),
38+
}),
3639
}
3740

3841
return task

0 commit comments

Comments
 (0)