Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@doist/todoist-api-typescript",
"version": "1.7.0",
"version": "2.0.0",
"description": "A typescript wrapper for the Todoist REST API.",
"author": "Doist developers",
"repository": "[email protected]:doist/todoist-api-typescript.git",
Expand Down
13 changes: 7 additions & 6 deletions src/TodoistApi.comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function getTarget() {
describe('TodoistApi comment endpoints', () => {
describe('getComments', () => {
test('calls get request with expected params', async () => {
const getCommentsArgs = { projectId: 12 }
const getCommentsArgs = { projectId: '12' }
const requestMock = setupRestClientMock([DEFAULT_COMMENT])
const api = getTarget()

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

const comments = await api.getComments({ taskId: 12 })
const comments = await api.getComments({ taskId: '12' })

expect(comments).toEqual(expectedComments)
})
Expand Down Expand Up @@ -80,7 +80,7 @@ describe('TodoistApi comment endpoints', () => {
describe('addComment', () => {
const addCommentArgs = {
content: 'A comment',
taskId: 123,
taskId: '123',
}

test('makes post request with expected params', async () => {
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('TodoistApi comment endpoints', () => {

test('makes post request with expected params', async () => {
const taskId = 1
const requestMock = setupRestClientMock(undefined, 204)
const requestMock = setupRestClientMock(DEFAULT_COMMENT, 204)
const api = getTarget()

await api.updateComment(taskId, updateCommentArgs, DEFAULT_REQUEST_ID)
Expand All @@ -135,12 +135,13 @@ describe('TodoistApi comment endpoints', () => {
})

test('returns success result from rest client', async () => {
setupRestClientMock(undefined, 204)
const returnedComment = { ...DEFAULT_COMMENT, ...updateCommentArgs }
setupRestClientMock(returnedComment, 204)
const api = getTarget()

const result = await api.updateComment(1, updateCommentArgs)

expect(result).toEqual(true)
expect(result).toEqual(returnedComment)
})

test('throws validation error for invalid id input', async () => {
Expand Down
7 changes: 4 additions & 3 deletions src/TodoistApi.labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('TodoistApi label endpoints', () => {

test('calls post on restClient with expected parameters', async () => {
const labelId = 123
const requestMock = setupRestClientMock(undefined, 204)
const requestMock = setupRestClientMock(DEFAULT_LABEL, 204)
const api = getTarget()

await api.updateLabel(labelId, DEFAULT_UPDATE_LABEL_ARGS, DEFAULT_REQUEST_ID)
Expand All @@ -130,12 +130,13 @@ describe('TodoistApi label endpoints', () => {
})

test('returns success result from rest client', async () => {
setupRestClientMock(undefined, 204)
const returnedTask = { ...DEFAULT_LABEL, ...DEFAULT_UPDATE_LABEL_ARGS }
setupRestClientMock(returnedTask, 204)
const api = getTarget()

const result = await api.updateLabel(123, DEFAULT_UPDATE_LABEL_ARGS)

expect(result).toEqual(true)
expect(result).toEqual(returnedTask)
})

test('throws validation error for invalid id input', async () => {
Expand Down
13 changes: 8 additions & 5 deletions src/TodoistApi.projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ describe('TodoistApi project endpoints', () => {
})

describe('updateProject', () => {
const DEFAULT_UPDATE_PROJECT_ARGS = { name: 'a name' }
test('calls post on restClient with expected parameters', async () => {
const projectId = 123
const updateArgs = { name: 'a new name' }
const requestMock = setupRestClientMock(undefined, 204)
const requestMock = setupRestClientMock(DEFAULT_PROJECT, 204)
const api = getTarget()

await api.updateProject(projectId, updateArgs, DEFAULT_REQUEST_ID)
Expand All @@ -132,17 +133,19 @@ describe('TodoistApi project endpoints', () => {
})

test('returns success result from rest client', async () => {
setupRestClientMock(undefined, 204)
const returnedProject = { ...DEFAULT_PROJECT, DEFAULT_UPDATE_PROJECT_ARGS }
setupRestClientMock(returnedProject, 204)
const api = getTarget()

const result = await api.updateProject(123, { name: 'a name' })
const result = await api.updateProject(123, DEFAULT_UPDATE_PROJECT_ARGS)

expect(result).toEqual(true)
expect(result).toEqual(returnedProject)
})

test('throws validation error for invalid id input', async () => {
await assertInputValidationError(
async () => await getTarget().updateProject(INVALID_ENTITY_ID, { name: 'a name' }),
async () =>
await getTarget().updateProject(INVALID_ENTITY_ID, DEFAULT_UPDATE_PROJECT_ARGS),
)
})
})
Expand Down
20 changes: 11 additions & 9 deletions src/TodoistApi.sections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('TodoistApi section endpoints', () => {
describe('addSection', () => {
const DEFAULT_ADD_SECTION_ARGS = {
name: 'This is a section',
projectId: 123,
projectId: '123',
}

test('calls post on restClient with expected parameters', async () => {
Expand Down Expand Up @@ -110,38 +110,40 @@ describe('TodoistApi section endpoints', () => {
})

describe('updateSection', () => {
const DEFAULT_UPDATE_SECTION_ARGS = { name: 'a new name' }

test('calls post on restClient with expected parameters', async () => {
const sectionId = 123
const updateArgs = { name: 'a new name' }
const requestMock = setupRestClientMock(undefined, 204)
const requestMock = setupRestClientMock(DEFAULT_SECTION, 204)
const api = getTarget()

await api.updateSection(sectionId, updateArgs, DEFAULT_REQUEST_ID)
await api.updateSection(sectionId, DEFAULT_UPDATE_SECTION_ARGS, DEFAULT_REQUEST_ID)

expect(requestMock).toBeCalledTimes(1)
expect(requestMock).toBeCalledWith(
'POST',
getRestBaseUri(),
`${ENDPOINT_REST_SECTIONS}/${sectionId}`,
DEFAULT_AUTH_TOKEN,
updateArgs,
DEFAULT_UPDATE_SECTION_ARGS,
DEFAULT_REQUEST_ID,
)
})

test('returns success result from rest client', async () => {
setupRestClientMock(undefined, 204)
const returnedSection = { ...DEFAULT_SECTION, ...DEFAULT_UPDATE_SECTION_ARGS }
setupRestClientMock(returnedSection, 204)
const api = getTarget()

const response = await api.updateSection(123, { name: 'a new name' })
const response = await api.updateSection(123, DEFAULT_UPDATE_SECTION_ARGS)

expect(response).toEqual(true)
expect(response).toEqual(returnedSection)
})

test('throws validation error for invalid id input', async () => {
await assertInputValidationError(
async () =>
await getTarget().updateSection(INVALID_ENTITY_ID, { name: 'a new name' }),
await getTarget().updateSection(INVALID_ENTITY_ID, DEFAULT_UPDATE_SECTION_ARGS),
)
})
})
Expand Down
18 changes: 10 additions & 8 deletions src/TodoistApi.tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,34 @@ describe('TodoistApi task endpoints', () => {
})

describe('updateTask', () => {
const DEFAULT_UPDATE_TASK_ARGS = { content: 'some new content' }

test('calls post on restClient with expected parameters', async () => {
const taskId = 123
const updateArgs = { content: 'some new content' }
const requestMock = setupRestClientMock(undefined, 204)
const requestMock = setupRestClientMock(DEFAULT_TASK, 204)
const api = getTarget()

await api.updateTask(taskId, updateArgs, DEFAULT_REQUEST_ID)
await api.updateTask(taskId, DEFAULT_UPDATE_TASK_ARGS, DEFAULT_REQUEST_ID)

expect(requestMock).toBeCalledTimes(1)
expect(requestMock).toBeCalledWith(
'POST',
getRestBaseUri(),
`${ENDPOINT_REST_TASKS}/${taskId}`,
DEFAULT_AUTH_TOKEN,
updateArgs,
DEFAULT_UPDATE_TASK_ARGS,
DEFAULT_REQUEST_ID,
)
})

test('returns success result from rest client', async () => {
setupRestClientMock(undefined, 204)
const returnedTask = { ...DEFAULT_TASK, ...DEFAULT_UPDATE_TASK_ARGS }
setupRestClientMock(returnedTask, 204)
const api = getTarget()

const response = await api.updateTask(123, { content: 'some content' })
const response = await api.updateTask(123, DEFAULT_UPDATE_TASK_ARGS)

expect(response).toEqual(true)
expect(response).toEqual(returnedTask)
})

test('throws validation error for invalid id input', async () => {
Expand Down Expand Up @@ -282,7 +284,7 @@ describe('TodoistApi task endpoints', () => {

describe('getTasks', () => {
const DEFAULT_GET_TASKS_ARGS = {
projectId: 123,
projectId: '123',
}

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