diff --git a/src/TodoistApi.tasks.test.ts b/src/TodoistApi.tasks.test.ts index 4295a2d..0030c62 100644 --- a/src/TodoistApi.tasks.test.ts +++ b/src/TodoistApi.tasks.test.ts @@ -333,6 +333,59 @@ describe('TodoistApi task endpoints', () => { }) }) + describe('moveTasks', () => { + const DEFAULT_MOVE_TASKS_ARGS = { + projectId: '6c6vJQjh5HFrGV5f', + } + const TASK_IDS = ['6c5rGRV6Hx6wM7g4', '6c5rGV8q9mqc4Xh4', '6c5rGVhqv6qcGfX4'] + + test('calls sync endpoint with expected parameters', async () => { + const mockSyncResponse = { + sync_status: {}, + items: [ + { ...DEFAULT_TASK, id: TASK_IDS[0] }, + { ...DEFAULT_TASK, id: TASK_IDS[1] }, + { ...DEFAULT_TASK, id: TASK_IDS[2] }, + ], + } + const requestMock = setupRestClientMock(mockSyncResponse) + const api = getTarget() + + await api.moveTasks(TASK_IDS, DEFAULT_MOVE_TASKS_ARGS, DEFAULT_REQUEST_ID) + + expect(requestMock).toBeCalledTimes(1) + const [, , , , syncRequest] = requestMock.mock.calls[0] + + expect(syncRequest.commands).toHaveLength(TASK_IDS.length) + expect(syncRequest.resource_types).toEqual(['items']) + + syncRequest.commands.forEach((cmd: any, index: number) => { + expect(cmd.type).toBe('item_move') + expect(cmd.args.id).toBe(TASK_IDS[index]) + expect(cmd.args.project_id).toBe(DEFAULT_MOVE_TASKS_ARGS.projectId) + }) + + const uuids = syncRequest.commands.map((cmd: any) => cmd.uuid) + const uniqueUuids = new Set(uuids) + expect(uniqueUuids.size).toBe(TASK_IDS.length) + }) + + test('returns result from sync client', async () => { + const movedTasks = TASK_IDS.map((id) => ({ ...DEFAULT_TASK, id })) + const mockSyncResponse = { + sync_status: {}, + items: movedTasks, + } + setupRestClientMock(mockSyncResponse) + const api = getTarget() + + const result = await api.moveTasks(TASK_IDS, DEFAULT_MOVE_TASKS_ARGS) + + expect(result).toHaveLength(TASK_IDS.length) + expect(result.map((task) => task.id)).toEqual(TASK_IDS) + }) + }) + describe('getCompletedTasksByCompletionDate', () => { const DEFAULT_GET_COMPLETED_TASKS_ARGS = { since: '2025-01-01T00:00:00Z', diff --git a/src/TodoistApi.ts b/src/TodoistApi.ts index 5362411..4b5f5db 100644 --- a/src/TodoistApi.ts +++ b/src/TodoistApi.ts @@ -309,10 +309,9 @@ export class TodoistApi { if (ids.length > MAX_COMMAND_COUNT) { throw new TodoistRequestError(`Maximum number of items is ${MAX_COMMAND_COUNT}`, 400) } - const uuid = uuidv4() const commands: Command[] = ids.map((id) => ({ type: 'item_move', - uuid, + uuid: uuidv4(), args: { id, ...(args.projectId && { project_id: args.projectId }),