-
Notifications
You must be signed in to change notification settings - Fork 18
feat(tasks): add support for Google Tasks #106
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
Draft
allenhutchison
wants to merge
5
commits into
main
Choose a base branch
from
adh/feat/tasks-service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4149c3b
feat(tasks): add support for Google Tasks
allenhutchison 515c88a
fix(tasks): fix return types for MCP compatibility
allenhutchison f38a45e
feat: add typecheck script for workspace-server
allenhutchison f20bb1f
Update workspace-server/src/services/TasksService.ts
allenhutchison ae1a93a
Update workspace-server/src/services/TasksService.ts
allenhutchison File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
workspace-server/src/__tests__/services/TasksService.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { jest } from '@jest/globals'; | ||
| import { AuthManager } from '../../auth/AuthManager'; | ||
| import { TasksService } from '../../services/TasksService'; | ||
|
|
||
| // Mock the AuthManager | ||
| const mockGetTasksClient = jest.fn<() => Promise<any>>(); | ||
| const mockAuthManager = { | ||
| getTasksClient: mockGetTasksClient, | ||
| } as unknown as AuthManager; | ||
|
|
||
| describe('TasksService', () => { | ||
| let tasksService: TasksService; | ||
| let mockTasksClient: any; | ||
|
|
||
| beforeEach(() => { | ||
| mockTasksClient = { | ||
| tasklists: { | ||
| list: jest.fn(), | ||
| }, | ||
| tasks: { | ||
| list: jest.fn(), | ||
| insert: jest.fn(), | ||
| patch: jest.fn(), | ||
| delete: jest.fn(), | ||
| }, | ||
| }; | ||
| mockGetTasksClient.mockResolvedValue(mockTasksClient); | ||
| tasksService = new TasksService(mockAuthManager); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('listTaskLists', () => { | ||
| it('should list task lists', async () => { | ||
| const mockResponse = { | ||
| data: { | ||
| items: [{ id: 'list1', title: 'My Tasks' }], | ||
| }, | ||
| }; | ||
| mockTasksClient.tasklists.list.mockResolvedValue(mockResponse); | ||
|
|
||
| const result = await tasksService.listTaskLists(); | ||
|
|
||
| expect(mockTasksClient.tasklists.list).toHaveBeenCalledWith({ | ||
| maxResults: undefined, | ||
| pageToken: undefined, | ||
| }); | ||
| expect(result).toEqual({ | ||
| content: [{ type: 'text', text: JSON.stringify(mockResponse.data.items, null, 2) }], | ||
| }); | ||
| }); | ||
|
|
||
| it('should pass pagination parameters', async () => { | ||
| const mockResponse = { data: { items: [] } }; | ||
| mockTasksClient.tasklists.list.mockResolvedValue(mockResponse); | ||
|
|
||
| await tasksService.listTaskLists({ maxResults: 10, pageToken: 'token' }); | ||
|
|
||
| expect(mockTasksClient.tasklists.list).toHaveBeenCalledWith({ | ||
| maxResults: 10, | ||
| pageToken: 'token', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('listTasks', () => { | ||
| it('should list tasks in a task list', async () => { | ||
| const mockResponse = { | ||
| data: { | ||
| items: [{ id: 'task1', title: 'Buy milk' }], | ||
| }, | ||
| }; | ||
| mockTasksClient.tasks.list.mockResolvedValue(mockResponse); | ||
|
|
||
| const result = await tasksService.listTasks({ taskListId: 'list1', showAssigned: true }); | ||
|
|
||
| expect(mockTasksClient.tasks.list).toHaveBeenCalledWith({ | ||
| tasklist: 'list1', | ||
| showCompleted: undefined, | ||
| showDeleted: undefined, | ||
| showHidden: undefined, | ||
| showAssigned: true, | ||
| maxResults: undefined, | ||
| pageToken: undefined, | ||
| dueMin: undefined, | ||
| dueMax: undefined, | ||
| }); | ||
| expect(result).toEqual({ | ||
| content: [{ type: 'text', text: JSON.stringify(mockResponse.data.items, null, 2) }], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('createTask', () => { | ||
| it('should create a task', async () => { | ||
| const mockResponse = { | ||
| data: { id: 'task1', title: 'New Task' }, | ||
| }; | ||
| mockTasksClient.tasks.insert.mockResolvedValue(mockResponse); | ||
|
|
||
| const result = await tasksService.createTask({ | ||
| taskListId: 'list1', | ||
| title: 'New Task', | ||
| notes: 'Some notes', | ||
| }); | ||
|
|
||
| expect(mockTasksClient.tasks.insert).toHaveBeenCalledWith({ | ||
| tasklist: 'list1', | ||
| requestBody: { | ||
| title: 'New Task', | ||
| notes: 'Some notes', | ||
| due: undefined, | ||
| }, | ||
| }); | ||
| expect(result).toEqual({ | ||
| content: [{ type: 'text', text: JSON.stringify(mockResponse.data, null, 2) }], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('updateTask', () => { | ||
| it('should update a task', async () => { | ||
| const mockResponse = { | ||
| data: { id: 'task1', title: 'Updated Task' }, | ||
| }; | ||
| mockTasksClient.tasks.patch.mockResolvedValue(mockResponse); | ||
|
|
||
| const result = await tasksService.updateTask({ | ||
| taskListId: 'list1', | ||
| taskId: 'task1', | ||
| title: 'Updated Task', | ||
| }); | ||
|
|
||
| expect(mockTasksClient.tasks.patch).toHaveBeenCalledWith({ | ||
| tasklist: 'list1', | ||
| task: 'task1', | ||
| requestBody: { | ||
| title: 'Updated Task', | ||
| }, | ||
| }); | ||
| expect(result).toEqual({ | ||
| content: [{ type: 'text', text: JSON.stringify(mockResponse.data, null, 2) }], | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('completeTask', () => { | ||
| it('should mark a task as completed', async () => { | ||
| const mockResponse = { | ||
| data: { id: 'task1', title: 'Task 1', status: 'completed' } | ||
| }; | ||
| mockTasksClient.tasks.patch.mockResolvedValue(mockResponse); | ||
|
|
||
| await tasksService.completeTask({ taskListId: 'list1', taskId: 'task1' }); | ||
|
|
||
| expect(mockTasksClient.tasks.patch).toHaveBeenCalledWith({ | ||
| tasklist: 'list1', | ||
| task: 'task1', | ||
| requestBody: { | ||
| status: 'completed', | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('deleteTask', () => { | ||
| it('should delete a task', async () => { | ||
| mockTasksClient.tasks.delete.mockResolvedValue({}); | ||
|
|
||
| const result = await tasksService.deleteTask({ taskListId: 'list1', taskId: 'task1' }); | ||
|
|
||
| expect(mockTasksClient.tasks.delete).toHaveBeenCalledWith({ | ||
| tasklist: 'list1', | ||
| task: 'task1', | ||
| }); | ||
| expect(result).toEqual({ | ||
| content: [{ type: 'text', text: 'Task task1 deleted successfully from list list1.' }], | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for
completeTaskverifies that thepatchmethod is called with the correct arguments, but it doesn't check the return value ofcompleteTask. For consistency with other tests in this file (likeupdateTask), you should also assert that the returned result is correct.