diff --git a/package-lock.json b/package-lock.json index d0ef608..31b62b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@doist/todoist-api-typescript", - "version": "1.7.0", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@doist/todoist-api-typescript", - "version": "1.7.0", + "version": "2.0.0", "license": "MIT", "dependencies": { "axios": "^0.27.0", diff --git a/package.json b/package.json index a490018..9f7b347 100644 --- a/package.json +++ b/package.json @@ -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": "git@github.com:doist/todoist-api-typescript.git", diff --git a/src/TodoistApi.comments.test.ts b/src/TodoistApi.comments.test.ts index 457af60..b4342c2 100644 --- a/src/TodoistApi.comments.test.ts +++ b/src/TodoistApi.comments.test.ts @@ -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() @@ -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) }) @@ -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 () => { @@ -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) @@ -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 () => { diff --git a/src/TodoistApi.labels.test.ts b/src/TodoistApi.labels.test.ts index 186abaa..195daec 100644 --- a/src/TodoistApi.labels.test.ts +++ b/src/TodoistApi.labels.test.ts @@ -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) @@ -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 () => { diff --git a/src/TodoistApi.projects.test.ts b/src/TodoistApi.projects.test.ts index 82fd5b2..95dfc71 100644 --- a/src/TodoistApi.projects.test.ts +++ b/src/TodoistApi.projects.test.ts @@ -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) @@ -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), ) }) }) diff --git a/src/TodoistApi.sections.test.ts b/src/TodoistApi.sections.test.ts index 771c607..b68cb01 100644 --- a/src/TodoistApi.sections.test.ts +++ b/src/TodoistApi.sections.test.ts @@ -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 () => { @@ -110,13 +110,14 @@ 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( @@ -124,24 +125,25 @@ describe('TodoistApi section endpoints', () => { 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), ) }) }) diff --git a/src/TodoistApi.tasks.test.ts b/src/TodoistApi.tasks.test.ts index cd0e23c..cd9c2d9 100644 --- a/src/TodoistApi.tasks.test.ts +++ b/src/TodoistApi.tasks.test.ts @@ -78,13 +78,14 @@ 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( @@ -92,18 +93,19 @@ describe('TodoistApi task endpoints', () => { 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 () => { @@ -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 () => { diff --git a/src/TodoistApi.ts b/src/TodoistApi.ts index 8b2d1a7..86c4fef 100644 --- a/src/TodoistApi.ts +++ b/src/TodoistApi.ts @@ -24,6 +24,8 @@ import { UpdateSectionArgs, UpdateTaskArgs, QuickAddTaskArgs, + RenameSharedLabelArgs, + RemoveSharedLabelArgs, } from './types/requests' import { request, isSuccess } from './restClient' import { getTaskFromQuickAddResponse } from './utils/taskConverters' @@ -39,6 +41,9 @@ import { ENDPOINT_REST_PROJECT_COLLABORATORS, ENDPOINT_REST_SECTIONS, ENDPOINT_REST_COMMENTS, + ENDPOINT_REST_LABELS_SHARED, + ENDPOINT_REST_LABELS_SHARED_RENAME, + ENDPOINT_REST_LABELS_SHARED_REMOVE, } from './consts/endpoints' import { validateComment, @@ -127,7 +132,7 @@ export class TodoistApi { return validateTask(task) } - async updateTask(id: number, args: UpdateTaskArgs, requestId?: string): Promise { + async updateTask(id: number, args: UpdateTaskArgs, requestId?: string): Promise { Int.check(id) const response = await request( 'POST', @@ -137,7 +142,7 @@ export class TodoistApi { args, requestId, ) - return isSuccess(response) + return validateTask(response.data) } async closeTask(id: number, requestId?: string): Promise { @@ -215,7 +220,7 @@ export class TodoistApi { return validateProject(response.data) } - async updateProject(id: number, args: UpdateProjectArgs, requestId?: string): Promise { + async updateProject(id: number, args: UpdateProjectArgs, requestId?: string): Promise { Int.check(id) const response = await request( 'POST', @@ -225,7 +230,7 @@ export class TodoistApi { args, requestId, ) - return isSuccess(response) + return validateProject(response.data) } async deleteProject(id: number, requestId?: string): Promise { @@ -293,7 +298,7 @@ export class TodoistApi { return validateSection(response.data) } - async updateSection(id: number, args: UpdateSectionArgs, requestId?: string): Promise { + async updateSection(id: number, args: UpdateSectionArgs, requestId?: string): Promise
{ Int.check(id) const response = await request( 'POST', @@ -303,7 +308,7 @@ export class TodoistApi { args, requestId, ) - return isSuccess(response) + return validateSection(response.data) } async deleteSection(id: number, requestId?: string): Promise { @@ -319,6 +324,9 @@ export class TodoistApi { return isSuccess(response) } + /** + * Fetches a personal label + */ async getLabel(id: number): Promise