Skip to content
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
15 changes: 10 additions & 5 deletions .nsprc
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"1097679": {
"active": true,
"notes": "For this to be resolved, it requires dependency updates further up the tree (like the @doist packages)",
"expiry": "2025/12/31"
},
"1099520": {
"active": true,
"notes": "For this to be resolved, it requires dependency updates for @nestjs/core",
Expand All @@ -13,5 +8,15 @@
"active": true,
"notes": "For this to be resolved, it requires dependency updates for @nestjs/core",
"expiry": "2025/12/31"
},
"1104001": {
"active": true,
"notes": "For this to be resolved, it requires dependency updates for @doist/ui-extensions-server",
"expiry": "2025/12/31"
},
"1103903": {
"active": true,
"notes": "For this to be resolved, it requires dependency updates for @doist/ui-extensions-server",
"expiry": "2025/12/31"
}
}
335 changes: 163 additions & 172 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
},
"prettier": "@doist/prettier-config",
"dependencies": {
"@doist/integrations-common": "2.0.0",
"@doist/todoist-api-typescript": "2.1.2",
"@doist/integrations-common": "2.1.16",
"@doist/todoist-api-typescript": "4.0.1",
"@doist/ui-extensions-core": "4.1.1",
"@doist/ui-extensions-server": "3.3.1",
"@nestjs/axios": "3.1.2",
Expand All @@ -98,7 +98,7 @@
"@nestjs/core": "10.4.12",
"@nestjs/platform-express": "10.4.12",
"@nestjs/typeorm": "10.0.2",
"axios": "1.7.4",
"axios": "1.8.4",
"dayjs": "1.11.7",
"env-cmd": "10.1.0",
"googleapis": "109.0.1",
Expand Down
265 changes: 261 additions & 4 deletions src/services/actions.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TodoistApi } from '@doist/todoist-api-typescript'
import { Section, Task, TodoistApi } from '@doist/todoist-api-typescript'
import { CoreModule, StateService } from '@doist/ui-extensions-server'

import { HttpModule } from '@nestjs/axios'
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('ActionsService', () => {
setupGetAppToken('kwijibo')

jest.spyOn(TodoistApi.prototype, 'getTasks').mockImplementation(() =>
Promise.resolve([]),
Promise.resolve({ results: [], nextCursor: null }),
)

const noTasksCard = jest.spyOn(target['adaptiveCardsService'], 'noTasksCard')
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('ActionsService', () => {

const getSections = jest
.spyOn(TodoistApi.prototype, 'getSections')
.mockImplementation(() => Promise.resolve([]))
.mockImplementation(() => Promise.resolve({ results: [], nextCursor: null }))

await target.export({
context: { user: { id: 42 } as DoistCardContextUser, theme: 'light' },
Expand Down Expand Up @@ -271,7 +271,11 @@ describe('ActionsService', () => {

const getCompletedItems = jest
.spyOn(TodoistService.prototype, 'getCompletedTasks')
.mockImplementation(() => Promise.resolve([]))
.mockImplementation(() => Promise.resolve({ tasks: [], completedInfo: [] }))

jest.spyOn(TodoistService.prototype, 'getCompletedInfo').mockImplementation(() =>
Promise.resolve([]),
)

await target.export({
context: { user: { id: 42 } as DoistCardContextUser, theme: 'light' },
Expand All @@ -296,6 +300,259 @@ describe('ActionsService', () => {
expect(getCompletedItems).toHaveBeenCalled()
})

it('fetches completed tasks for tasks with completed subtasks', async () => {
setupGetUser(buildUser())
setupGetGoogleToken('kwijibo')
setupGetAppToken('kwijibo')

const parentTask = {
id: 'parent1',
projectId: '1234',
content: 'Parent Task',
isCompleted: false,
} as Task

jest.spyOn(TodoistApi.prototype, 'getTasks').mockImplementation(() =>
Promise.resolve({ results: [parentTask], nextCursor: null }),
)
jest.spyOn(TodoistService.prototype, 'getCompletedInfo').mockImplementation(() =>
Promise.resolve([{ item_id: 'parent1', completed_items: 2 }]),
)

const completedSubtasks = [
{
id: 'sub1',
projectId: '1234',
content: 'Subtask 1',
description: '',
isCompleted: true,
},
{
id: 'sub2',
projectId: '1234',
content: 'Subtask 2',
description: '',
isCompleted: true,
},
] as Task[]

const getCompletedTasks = jest
.spyOn(TodoistService.prototype, 'getCompletedTasks')
.mockImplementation(({ taskId }) => {
if (taskId === 'parent1') {
return Promise.resolve({
tasks: completedSubtasks,
completedInfo: [
{ item_id: 'sub1', completed_items: 0 },
{ item_id: 'sub2', completed_items: 0 },
],
})
}
return Promise.resolve({ tasks: [], completedInfo: [] })
})

jest.spyOn(target['googleSheetsService'], 'exportToSheets').mockImplementation(() =>
Promise.resolve('https://docs.google.com'),
)

await target.export({
context: { user: { id: 42 } as DoistCardContextUser, theme: 'light' },
action: {
actionType: 'submit',
actionId: SheetCardActions.Export,
params: {
source: 'project',
sourceId: '1234',
url: 'https://google.com',
content: 'My Project',
contentPlain: 'My Project',
} as ContextMenuData,
inputs: {
[Inputs.IncludeCompleted]: 'true',
},
},
extensionType: 'context-menu',
maximumDoistCardVersion: 0.5,
})

expect(getCompletedTasks).toHaveBeenCalledWith(
expect.objectContaining({ taskId: 'parent1' }),
)
})

it('fetches completed tasks for sections with completed tasks', async () => {
setupGetUser(buildUser())
setupGetGoogleToken('kwijibo')
setupGetAppToken('kwijibo')
setupGetTasks()

const sections: Section[] = [
{
id: 'section1',
projectId: '1234',
name: 'Section 1',
userId: 'user1',
isDeleted: false,
isCollapsed: false,
isArchived: false,
archivedAt: null,
addedAt: '2024-01-01T00:00:00Z',
updatedAt: '2024-01-01T00:00:00Z',
sectionOrder: 1,
},
]
jest.spyOn(TodoistApi.prototype, 'getSections').mockImplementation(() =>
Promise.resolve({ results: sections, nextCursor: null }),
)

jest.spyOn(TodoistService.prototype, 'getCompletedInfo').mockImplementation(() =>
Promise.resolve([{ section_id: 'section1', completed_items: 1 }]),
)

const completedTask = {
id: 'task1',
projectId: '1234',
content: 'Task 1',
description: '',
isCompleted: true,
} as Task

const getCompletedTasks = jest
.spyOn(TodoistService.prototype, 'getCompletedTasks')
.mockImplementation(({ sectionId }) => {
if (sectionId === 'section1') {
return Promise.resolve({
tasks: [completedTask],
completedInfo: [{ item_id: 'task1', completed_items: 0 }],
})
}
return Promise.resolve({ tasks: [], completedInfo: [] })
})

jest.spyOn(target['googleSheetsService'], 'exportToSheets').mockImplementation(() =>
Promise.resolve('https://docs.google.com'),
)

await target.export({
context: { user: { id: 42 } as DoistCardContextUser, theme: 'light' },
action: {
actionType: 'submit',
actionId: SheetCardActions.Export,
params: {
source: 'project',
sourceId: '1234',
url: 'https://google.com',
content: 'My Project',
contentPlain: 'My Project',
} as ContextMenuData,
inputs: {
[Inputs.IncludeCompleted]: 'true',
'Input.section': 'true',
},
},
extensionType: 'context-menu',
maximumDoistCardVersion: 0.5,
})

expect(getCompletedTasks).toHaveBeenCalledWith(
expect.objectContaining({ sectionId: 'section1' }),
)
})

it('recursively fetches completed subtasks of completed tasks', async () => {
setupGetUser(buildUser())
setupGetGoogleToken('kwijibo')
setupGetAppToken('kwijibo')

const parentTask = {
id: 'parent1',
projectId: '1234',
content: 'Parent Task',
description: '',
isCompleted: false,
} as Task
jest.spyOn(TodoistApi.prototype, 'getTasks').mockImplementation(() =>
Promise.resolve({ results: [parentTask], nextCursor: null }),
)

jest.spyOn(TodoistService.prototype, 'getCompletedInfo').mockImplementation(() =>
Promise.resolve([{ item_id: 'parent1', completed_items: 2 }]),
)

const completedSubtasks = [
{
id: 'sub1',
projectId: '1234',
content: 'Subtask 1',
description: '',
isCompleted: true,
},
] as Task[]

const completedSubSubtasks = [
{
id: 'subsub1',
projectId: '1234',
content: 'Sub-subtask 1',
description: '',
isCompleted: true,
},
] as Task[]

const getCompletedTasks = jest
.spyOn(TodoistService.prototype, 'getCompletedTasks')
.mockImplementation(({ taskId }) => {
if (taskId === 'parent1') {
return Promise.resolve({
tasks: completedSubtasks,
completedInfo: [{ item_id: 'sub1', completed_items: 1 }],
})
}
if (taskId === 'sub1') {
return Promise.resolve({
tasks: completedSubSubtasks,
completedInfo: [],
})
}
return Promise.resolve({ tasks: [], completedInfo: [] })
})

jest.spyOn(target['googleSheetsService'], 'exportToSheets').mockImplementation(() =>
Promise.resolve('https://docs.google.com'),
)

await target.export({
context: { user: { id: 42 } as DoistCardContextUser, theme: 'light' },
action: {
actionType: 'submit',
actionId: SheetCardActions.Export,
params: {
source: 'project',
sourceId: '1234',
url: 'https://google.com',
content: 'My Project',
contentPlain: 'My Project',
} as ContextMenuData,
inputs: {
[Inputs.IncludeCompleted]: 'true',
},
},
extensionType: 'context-menu',
maximumDoistCardVersion: 0.5,
})

expect(getCompletedTasks).toHaveBeenCalledWith(
expect.objectContaining({ projectId: '1234' }),
)
expect(getCompletedTasks).toHaveBeenCalledWith(
expect.objectContaining({ taskId: 'parent1' }),
)
expect(getCompletedTasks).toHaveBeenCalledWith(
expect.objectContaining({ taskId: 'sub1' }),
)
expect(getCompletedTasks).toHaveBeenCalledTimes(3)
})

it('passes the correct data through to google sheets service', async () => {
setupGetUser(buildUser())
setupGetGoogleToken('kwijibo')
Expand Down
Loading
Loading