Skip to content
Merged
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: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
],
"dependencies": {
"@doist/cli-core": "0.26.2",
"@doist/comms-sdk": "2.0.2",
"@doist/comms-sdk": "3.0.0",
"@pnpm/tabtab": "0.5.4",
"chalk": "5.6.2",
"commander": "14.0.3",
Expand Down
27 changes: 16 additions & 11 deletions src/commands/channel/members.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const createProgram = () => createTestProgram(registerChannelCommand)

function createChannel(userIds: number[], overrides: Record<string, unknown> = {}) {
return {
id: 'CH1',
id: 'CeRAj1WU3YFhsTejuePLW',
name: 'General',
public: true,
workspaceId: 1,
Expand Down Expand Up @@ -100,7 +100,7 @@ describe('tdc channel members list (default)', () => {
await program.parseAsync(['node', 'tdc', 'channel', 'members', 'General', '--json'])

const payload = JSON.parse(consoleSpy.mock.calls[0][0] as string)
expect(payload.id).toBe('CH1')
expect(payload.id).toBe('CeRAj1WU3YFhsTejuePLW')
expect(payload.members).toHaveLength(3)
expect(payload.members[0]).toEqual({ id: 1, name: 'Alice', email: 'a@d.com' })
expect(payload.groupsFullyInChannel).toEqual([
Expand Down Expand Up @@ -159,7 +159,7 @@ describe('tdc channel members add', () => {
'alice',
])

expect(apiMocks.addUsersToChannel).toHaveBeenCalledWith('CH1', [3])
expect(apiMocks.addUsersToChannel).toHaveBeenCalledWith('CeRAj1WU3YFhsTejuePLW', [3])
const output = consoleSpy.mock.calls.map((c) => c[0]).join('\n')
expect(output).toContain('Added 1 user to "General" (now 3 members)')
expect(output).toContain('Already members: 1')
Expand All @@ -184,7 +184,7 @@ describe('tdc channel members add', () => {
'group:Frontend',
])

expect(apiMocks.addUsersToChannel).toHaveBeenCalledWith('CH1', [2, 3])
expect(apiMocks.addUsersToChannel).toHaveBeenCalledWith('CeRAj1WU3YFhsTejuePLW', [2, 3])
const output = consoleSpy.mock.calls.map((c) => c[0]).join('\n')
expect(output).toContain('Expanded group "Frontend"')
})
Expand Down Expand Up @@ -230,7 +230,7 @@ describe('tdc channel members add', () => {

const payload = JSON.parse(consoleSpy.mock.calls[0][0] as string)
expect(payload).toEqual({
id: 'CH1',
id: 'CeRAj1WU3YFhsTejuePLW',
memberCount: 3,
added: [3],
alreadyMembers: [1],
Expand All @@ -256,7 +256,7 @@ describe('tdc channel members remove', () => {
'id:9',
])

expect(apiMocks.removeUsersFromChannel).toHaveBeenCalledWith('CH1', [3])
expect(apiMocks.removeUsersFromChannel).toHaveBeenCalledWith('CeRAj1WU3YFhsTejuePLW', [3])
const output = consoleSpy.mock.calls.map((c) => c[0]).join('\n')
expect(output).toContain('Removed 1 user from "General" (now 2 members)')
expect(output).toContain('Not members: 9')
Expand Down Expand Up @@ -317,8 +317,8 @@ describe('tdc channel members set', () => {
'--apply',
])

expect(apiMocks.addUsersToChannel).toHaveBeenCalledWith('CH1', [3])
expect(apiMocks.removeUsersFromChannel).toHaveBeenCalledWith('CH1', [2])
expect(apiMocks.addUsersToChannel).toHaveBeenCalledWith('CeRAj1WU3YFhsTejuePLW', [3])
expect(apiMocks.removeUsersFromChannel).toHaveBeenCalledWith('CeRAj1WU3YFhsTejuePLW', [2])
const output = consoleSpy.mock.calls.map((c) => c[0]).join('\n')
expect(output).toContain('Set "General": +1 / -1 (now 2 members)')
})
Expand All @@ -343,7 +343,12 @@ describe('tdc channel members set', () => {
])

const payload = JSON.parse(consoleSpy.mock.calls[0][0] as string)
expect(payload).toEqual({ id: 'CH1', memberCount: 2, added: [3], removed: [2] })
expect(payload).toEqual({
id: 'CeRAj1WU3YFhsTejuePLW',
memberCount: 2,
added: [3],
removed: [2],
})
})

it('emits JSON (not text) on dry-run --json without --apply', async () => {
Expand All @@ -367,7 +372,7 @@ describe('tdc channel members set', () => {
expect(apiMocks.addUsersToChannel).not.toHaveBeenCalled()
const payload = JSON.parse(consoleSpy.mock.calls[0][0] as string)
expect(payload).toEqual({
id: 'CH1',
id: 'CeRAj1WU3YFhsTejuePLW',
dryRun: true,
memberCount: 2,
added: [3],
Expand All @@ -392,6 +397,6 @@ describe('tdc channel members set', () => {
'--include-self',
])

expect(apiMocks.removeUsersFromChannel).toHaveBeenCalledWith('CH1', [1])
expect(apiMocks.removeUsersFromChannel).toHaveBeenCalledWith('CeRAj1WU3YFhsTejuePLW', [1])
})
})
2 changes: 1 addition & 1 deletion src/commands/inbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('inbox empty output (channel filter)', () => {
vi.clearAllMocks()
apiMocks.getCurrentWorkspaceId.mockResolvedValue(1)
const thread = {
id: 'TH1',
id: 'CeRAj1WU3YFhsVZGDyPr9',
channelId: 'CH10',
title: 't',
posted: '2026-05-01T00:00:00Z',
Expand Down
14 changes: 10 additions & 4 deletions src/commands/react.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ describe('react refs', () => {
'tdc',
'react',
'thread',
'https://comms.todoist.com/a/1/ch/2/t/99',
'https://comms.todoist.com/a/1/ch/CeRAj1WU3YFhsTejuePLW/t/CeRAj1WU3YFhsVZGDyPr9',
'+1',
])

expect(apiMocks.addReaction).toHaveBeenCalledWith({ threadId: '99', reaction: '👍' })
expect(apiMocks.addReaction).toHaveBeenCalledWith({
threadId: 'CeRAj1WU3YFhsVZGDyPr9',
reaction: '👍',
})
})

it('accepts message URLs for unreact', async () => {
Expand All @@ -53,11 +56,14 @@ describe('react refs', () => {
'tdc',
'unreact',
'message',
'https://comms.todoist.com/a/1/msg/33/m/44',
'https://comms.todoist.com/a/1/msg/CeRAj1WU3YFhsatbAs43L/m/CeRAj1WU3YFhsbp9GT1ir',
'heart',
])

expect(apiMocks.removeReaction).toHaveBeenCalledWith({ messageId: '44', reaction: '❤️' })
expect(apiMocks.removeReaction).toHaveBeenCalledWith({
messageId: 'CeRAj1WU3YFhsbp9GT1ir',
reaction: '❤️',
})
})

it('outputs JSON for react --json', async () => {
Expand Down
22 changes: 16 additions & 6 deletions src/commands/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('tdc view <url> routing', () => {
'node',
'tdc',
'view',
'https://comms.todoist.com/a/1585/ch/100/t/200',
'https://comms.todoist.com/a/1585/ch/CeRAj1WU3YFhsTejuePLW/t/CeRAj1WU3YFhsVZGDyPr9',
]),
).rejects.toThrow('ROUTED_TO_THREAD')
})
Expand All @@ -57,22 +57,32 @@ describe('tdc view <url> routing', () => {
'node',
'tdc',
'view',
'https://comms.todoist.com/a/1585/ch/100/t/200/c/300',
'https://comms.todoist.com/a/1585/ch/CeRAj1WU3YFhsTejuePLW/t/CeRAj1WU3YFhsVZGDyPr9/c/CeRAj1WU3YFhsY6fUxMhj',
]),
).rejects.toThrow('ROUTED_TO_THREAD')
})

it('routes conversation URL to conversation view', async () => {
const program = createProgram()
await expect(
program.parseAsync(['node', 'tdc', 'view', 'https://comms.todoist.com/a/1585/msg/400']),
program.parseAsync([
'node',
'tdc',
'view',
'https://comms.todoist.com/a/1585/msg/CeRAj1WU3YFhsatbAs43L',
]),
).rejects.toThrow('ROUTED_TO_CONVERSATION')
})

it('routes short conversation URL to conversation view', async () => {
const program = createProgram()
await expect(
program.parseAsync(['node', 'tdc', 'view', 'https://comms.todoist.com/1585/msg/400']),
program.parseAsync([
'node',
'tdc',
'view',
'https://comms.todoist.com/1585/msg/CeRAj1WU3YFhsatbAs43L',
]),
).rejects.toThrow('ROUTED_TO_CONVERSATION')
})

Expand All @@ -83,7 +93,7 @@ describe('tdc view <url> routing', () => {
'node',
'tdc',
'view',
'https://comms.todoist.com/a/1585/msg/400/m/500',
'https://comms.todoist.com/a/1585/msg/CeRAj1WU3YFhsatbAs43L/m/CeRAj1WU3YFhsbp9GT1ir',
]),
).rejects.toThrow('ROUTED_TO_MSG')
})
Expand All @@ -102,7 +112,7 @@ describe('tdc view <url> routing', () => {
'node',
'tdc',
'view',
'https://comms.todoist.com/20/inbox/t/TH1/msg/CV1',
'https://comms.todoist.com/20/inbox/t/CeRAj1WU3YFhsVZGDyPr9/msg/CeRAj1WU3YFhsatbAs43L',
]),
).rejects.toThrow('Not a recognized Comms URL')
})
Expand Down
4 changes: 2 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('CLI entrypoint', () => {
'tdc',
'conversation',
'view',
'https://comms.todoist.com/123/msg/ANON_MESSAGE_ID/',
'https://comms.todoist.com/123/msg/CeRAj1WU3YFhsatbAs43L/',
'--from',
'2026-06-26',
])
Expand All @@ -84,7 +84,7 @@ describe('CLI entrypoint', () => {
'node',
'tdc',
'view',
'https://comms.todoist.com/a/123/msg/456',
'https://comms.todoist.com/a/123/msg/CeRAj1WU3YFhsatbAs43L',
'--from',
'2026-06-26',
])
Expand Down
12 changes: 8 additions & 4 deletions src/lib/public-channels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@ describe('getPublicChannelIds', () => {
it('returns only public channel IDs', async () => {
mockGetCommsClient.mockImplementation(() =>
makeMockChannels([
{ id: 'CH1', public: true },
{ id: 'CeRAj1WU3YFhsTejuePLW', public: true },
{ id: 'CH2', public: false },
{ id: 'CH3', public: true },
]),
)

const ids = await getPublicChannelIds(100)
expect(ids).toEqual(new Set(['CH1', 'CH3']))
expect(ids).toEqual(new Set(['CeRAj1WU3YFhsTejuePLW', 'CH3']))
})

it('caches results per workspace', async () => {
const getChannels = vi.fn().mockResolvedValue([{ id: 'CH1', public: true }])
const getChannels = vi
.fn()
.mockResolvedValue([{ id: 'CeRAj1WU3YFhsTejuePLW', public: true }])
mockGetCommsClient.mockResolvedValue({
channels: { getChannels },
} as unknown as Awaited<ReturnType<typeof getCommsClient>>)
Expand All @@ -107,7 +109,9 @@ describe('getPublicChannelIds', () => {
})

it('fetches separately for different workspaces', async () => {
const getChannels = vi.fn().mockResolvedValue([{ id: 'CH1', public: true }])
const getChannels = vi
.fn()
.mockResolvedValue([{ id: 'CeRAj1WU3YFhsTejuePLW', public: true }])
mockGetCommsClient.mockResolvedValue({
channels: { getChannels },
} as unknown as Awaited<ReturnType<typeof getCommsClient>>)
Expand Down
Loading
Loading