Skip to content

Move-tasks discards additional tasks because of a duplicate uuid #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
53 changes: 53 additions & 0 deletions src/TodoistApi.tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,59 @@
})
})

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]

Check failure on line 357 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe assignment of an `any` value

expect(syncRequest.commands).toHaveLength(TASK_IDS.length)

Check failure on line 359 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe member access .commands on an `any` value
expect(syncRequest.resource_types).toEqual(['items'])

Check failure on line 360 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe member access .resource_types on an `any` value

syncRequest.commands.forEach((cmd: any, index: number) => {

Check failure on line 362 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected any. Specify a different type

Check failure on line 362 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe member access .commands on an `any` value

Check failure on line 362 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe call of an `any` typed value
expect(cmd.type).toBe('item_move')

Check failure on line 363 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe member access .type on an `any` value
expect(cmd.args.id).toBe(TASK_IDS[index])

Check failure on line 364 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe member access .args on an `any` value
expect(cmd.args.project_id).toBe(DEFAULT_MOVE_TASKS_ARGS.projectId)

Check failure on line 365 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe member access .args on an `any` value
})

const uuids = syncRequest.commands.map((cmd: any) => cmd.uuid)

Check failure on line 368 in src/TodoistApi.tasks.test.ts

View workflow job for this annotation

GitHub Actions / ci

Unsafe assignment of an `any` value
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',
Expand Down
3 changes: 1 addition & 2 deletions src/TodoistApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down