taskOwnership.test.ts2.0 KBView on GitHub import { partitionTasksByOwner } from '@/modules/userTasks/utils/task-ownership';
/**
* A conversation's task list is org-shared, so every surface that renders it (the overview's
* Due/Scheduled checklists, the chat panel's tasks card, the Next Steps list) renders other
* people's follow-ups too. This split is what keeps those buckets answering "what's on me":
* a teammate's task is read-only here — every mutation is owner-scoped server side — so mixed
* into today's bucket it reads as your own work, forgotten.
*/
describe('partitionTasksByOwner', () => {
const mine = { id: 't1', owner: { id: 'me' } };
const theirs = { id: 't2', owner: { id: 'you' } };
const unowned = { id: 't3', owner: null };
it('sends other people’s tasks to `theirs` and keeps the viewer’s in `mine`', () => {
const { mine: kept, theirs: sunk } = partitionTasksByOwner([mine, theirs], 'me');
expect(kept).toEqual([mine]);
expect(sunk).toEqual([theirs]);
});
it('keeps a task with no attributable owner as the viewer’s', () => {
// An owner the payload could not resolve is unattributable, not foreign — the same rule
// the owner badge uses. Demoting it would hide a real task of yours at the bottom.
const { mine: kept, theirs: sunk } = partitionTasksByOwner([unowned], 'me');
expect(kept).toEqual([unowned]);
expect(sunk).toEqual([]);
});
it('treats every task as the viewer’s while the viewer is unknown', () => {
// `useSession()` resolves asynchronously and yields nothing on the server render. Guessing
// there would sink the whole list under someone else's heading on first paint.
const { mine: kept, theirs: sunk } = partitionTasksByOwner([mine, theirs], null);
expect(kept).toEqual([mine, theirs]);
expect(sunk).toEqual([]);
});
it('preserves the incoming order within each side', () => {
const second = { id: 't4', owner: { id: 'you' } };
const { theirs: sunk } = partitionTasksByOwner([theirs, mine, second], 'me');
expect(sunk.map((t) => t.id)).toEqual(['t2', 't4']);
});
});