-
Notifications
You must be signed in to change notification settings - Fork 502
fix(tasks): refresh open windows when a task is archived headlessly #2514
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
dfox288
wants to merge
1
commit into
generalaction:main
Choose a base branch
from
dfox288:fix/task-archive-refresh
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.
+128
−1
Open
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions
82
apps/emdash-desktop/src/main/core/tasks/task-service.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,82 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { events } from '@main/lib/events'; | ||
| import { taskArchivedChannel } from '@shared/core/tasks/taskEvents'; | ||
| import { archiveTask as archiveTaskOp } from './operations/archiveTask'; | ||
|
|
||
| // task-service pulls in the full main-process graph at import time; mock the | ||
| // heavy singletons / db so the module loads in a plain node test, and stub | ||
| // every task operation so we can drive the service in isolation. | ||
| vi.mock('@main/lib/events', () => ({ | ||
| events: { emit: vi.fn(), on: vi.fn(() => vi.fn()) }, | ||
| })); | ||
| vi.mock('@main/lib/logger', () => ({ log: { error: vi.fn(), warn: vi.fn(), info: vi.fn() } })); | ||
| vi.mock('@main/db/client', () => ({ db: {} })); | ||
| vi.mock('@main/db/schema', () => ({ tasks: {}, workspaces: {} })); | ||
| vi.mock('@main/core/projects/project-manager', () => ({ projectManager: {} })); | ||
| vi.mock('@main/core/workspaces/workspace-bootstrap-service', () => ({ | ||
| workspaceBootstrapService: {}, | ||
| })); | ||
| vi.mock('@main/core/workspaces/workspace-registry', () => ({ workspaceRegistry: {} })); | ||
| vi.mock('./task-session-manager', () => ({ taskSessionManager: {} })); | ||
| vi.mock('./utils/utils', () => ({ mapTaskRowToTask: vi.fn() })); | ||
| vi.mock('./operations/archiveTask', () => ({ archiveTask: vi.fn(async () => undefined) })); | ||
| vi.mock('./operations/createTask', () => ({ createTask: vi.fn() })); | ||
| vi.mock('./operations/deleteTask', () => ({ deleteTask: vi.fn() })); | ||
| vi.mock('./operations/getDeletePreflight', () => ({ getDeletePreflight: vi.fn() })); | ||
| vi.mock('./operations/getTasks', () => ({ getTasks: vi.fn() })); | ||
| vi.mock('./operations/renameTask', () => ({ renameTask: vi.fn() })); | ||
| vi.mock('./operations/restoreTask', () => ({ restoreTask: vi.fn() })); | ||
| vi.mock('./operations/setTaskPinned', () => ({ setTaskPinned: vi.fn() })); | ||
| vi.mock('./operations/updateLinkedIssue', () => ({ updateLinkedIssue: vi.fn() })); | ||
| vi.mock('./operations/updateTaskStatus', () => ({ updateTaskStatus: vi.fn() })); | ||
|
|
||
| const { TaskService } = await import('./task-service'); | ||
|
|
||
| const mockEmit = vi.mocked(events.emit); | ||
| const mockArchiveOp = vi.mocked(archiveTaskOp); | ||
|
|
||
| describe('TaskService.archiveTask', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('archives via the operation and notifies open windows', async () => { | ||
| const service = new TaskService(); | ||
| await service.archiveTask('project-1', 'task-1'); | ||
|
|
||
| expect(mockArchiveOp).toHaveBeenCalledWith('project-1', 'task-1'); | ||
| expect(mockEmit).toHaveBeenCalledWith(taskArchivedChannel, { | ||
| taskId: 'task-1', | ||
| projectId: 'project-1', | ||
| }); | ||
| }); | ||
|
|
||
| it('emits the archived event only after the archive operation completes', async () => { | ||
| const order: string[] = []; | ||
| mockArchiveOp.mockImplementationOnce(async () => { | ||
| order.push('archive-op'); | ||
| }); | ||
| mockEmit.mockImplementationOnce(() => { | ||
| order.push('emit'); | ||
| return undefined as never; | ||
| }); | ||
|
|
||
| const service = new TaskService(); | ||
| await service.archiveTask('project-1', 'task-1'); | ||
|
|
||
| expect(order).toEqual(['archive-op', 'emit']); | ||
| }); | ||
|
|
||
| it('does not emit the archived event when the archive operation fails', async () => { | ||
| mockArchiveOp.mockRejectedValueOnce(new Error('db constraint violation')); | ||
|
|
||
| const service = new TaskService(); | ||
| await expect(service.archiveTask('project-1', 'task-1')).rejects.toThrow( | ||
| 'db constraint violation' | ||
| ); | ||
|
|
||
| // An emitted event here would make every open window hide a task that is | ||
| // still alive in the database. | ||
| expect(mockEmit).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.