@urugus/slack-cli 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +2 -1
- package/dist/commands/channels.d.ts.map +1 -1
- package/dist/commands/channels.js +7 -4
- package/dist/commands/channels.js.map +1 -1
- package/dist/commands/unread.d.ts.map +1 -1
- package/dist/commands/unread.js +17 -21
- package/dist/commands/unread.js.map +1 -1
- package/dist/utils/config/config-file-manager.d.ts +13 -0
- package/dist/utils/config/config-file-manager.d.ts.map +1 -0
- package/dist/utils/config/config-file-manager.js +85 -0
- package/dist/utils/config/config-file-manager.js.map +1 -0
- package/dist/utils/config/profile-manager.d.ts +16 -0
- package/dist/utils/config/profile-manager.d.ts.map +1 -0
- package/dist/utils/config/profile-manager.js +64 -0
- package/dist/utils/config/profile-manager.js.map +1 -0
- package/dist/utils/config/token-crypto-service.d.ts +11 -0
- package/dist/utils/config/token-crypto-service.d.ts.map +1 -0
- package/dist/utils/config/token-crypto-service.js +111 -0
- package/dist/utils/config/token-crypto-service.js.map +1 -0
- package/dist/utils/format-utils.d.ts.map +1 -1
- package/dist/utils/format-utils.js +2 -1
- package/dist/utils/format-utils.js.map +1 -1
- package/dist/utils/formatters/base-formatter.d.ts +23 -0
- package/dist/utils/formatters/base-formatter.d.ts.map +1 -0
- package/dist/utils/formatters/base-formatter.js +26 -0
- package/dist/utils/formatters/base-formatter.js.map +1 -0
- package/dist/utils/formatters/channel-formatters.d.ts +4 -13
- package/dist/utils/formatters/channel-formatters.d.ts.map +1 -1
- package/dist/utils/formatters/channel-formatters.js +18 -26
- package/dist/utils/formatters/channel-formatters.js.map +1 -1
- package/dist/utils/formatters/channels-list-formatters.d.ts +3 -10
- package/dist/utils/formatters/channels-list-formatters.d.ts.map +1 -1
- package/dist/utils/formatters/channels-list-formatters.js +15 -22
- package/dist/utils/formatters/channels-list-formatters.js.map +1 -1
- package/dist/utils/formatters/message-formatters.d.ts +9 -0
- package/dist/utils/formatters/message-formatters.d.ts.map +1 -0
- package/dist/utils/formatters/message-formatters.js +72 -0
- package/dist/utils/formatters/message-formatters.js.map +1 -0
- package/dist/utils/mention-utils.d.ts +17 -0
- package/dist/utils/mention-utils.d.ts.map +1 -0
- package/dist/utils/mention-utils.js +45 -0
- package/dist/utils/mention-utils.js.map +1 -0
- package/dist/utils/option-parsers.d.ts +47 -0
- package/dist/utils/option-parsers.d.ts.map +1 -0
- package/dist/utils/option-parsers.js +75 -0
- package/dist/utils/option-parsers.js.map +1 -0
- package/dist/utils/profile-config-refactored.d.ts +20 -0
- package/dist/utils/profile-config-refactored.d.ts.map +1 -0
- package/dist/utils/profile-config-refactored.js +174 -0
- package/dist/utils/profile-config-refactored.js.map +1 -0
- package/dist/utils/slack-operations/message-operations.d.ts.map +1 -1
- package/dist/utils/slack-operations/message-operations.js +3 -2
- package/dist/utils/slack-operations/message-operations.js.map +1 -1
- package/dist/utils/slack-patterns.d.ts +6 -0
- package/dist/utils/slack-patterns.d.ts.map +1 -0
- package/dist/utils/slack-patterns.js +11 -0
- package/dist/utils/slack-patterns.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/channels.ts +7 -4
- package/src/commands/unread.ts +18 -21
- package/src/utils/config/config-file-manager.ts +56 -0
- package/src/utils/config/profile-manager.ts +79 -0
- package/src/utils/config/token-crypto-service.ts +80 -0
- package/src/utils/format-utils.ts +3 -1
- package/src/utils/formatters/base-formatter.ts +34 -0
- package/src/utils/formatters/channel-formatters.ts +25 -23
- package/src/utils/formatters/channels-list-formatters.ts +27 -31
- package/src/utils/formatters/message-formatters.ts +85 -0
- package/src/utils/mention-utils.ts +47 -0
- package/src/utils/option-parsers.ts +100 -0
- package/src/utils/profile-config-refactored.ts +161 -0
- package/src/utils/slack-operations/message-operations.ts +3 -2
- package/src/utils/slack-patterns.ts +9 -0
- package/tests/commands/unread.test.ts +112 -0
- package/tests/utils/config/config-file-manager.test.ts +118 -0
- package/tests/utils/config/profile-manager.test.ts +266 -0
- package/tests/utils/config/token-crypto-service.test.ts +98 -0
- package/tests/utils/mention-utils.test.ts +100 -0
- package/tests/utils/slack-operations/message-operations.test.ts +126 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { beforeEach, describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { MessageOperations } from '../../../src/utils/slack-operations/message-operations';
|
|
3
|
+
import { channelResolver } from '../../../src/utils/channel-resolver';
|
|
4
|
+
|
|
5
|
+
vi.mock('@slack/web-api', () => ({
|
|
6
|
+
WebClient: vi.fn().mockImplementation(() => ({
|
|
7
|
+
conversations: {
|
|
8
|
+
history: vi.fn(),
|
|
9
|
+
},
|
|
10
|
+
users: {
|
|
11
|
+
info: vi.fn(),
|
|
12
|
+
},
|
|
13
|
+
chat: {
|
|
14
|
+
postMessage: vi.fn(),
|
|
15
|
+
},
|
|
16
|
+
})),
|
|
17
|
+
LogLevel: {
|
|
18
|
+
ERROR: 'error',
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
vi.mock('../../../src/utils/channel-resolver');
|
|
23
|
+
|
|
24
|
+
describe('MessageOperations', () => {
|
|
25
|
+
let messageOps: MessageOperations;
|
|
26
|
+
let mockClient: any;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
vi.clearAllMocks();
|
|
30
|
+
messageOps = new MessageOperations('test-token');
|
|
31
|
+
mockClient = (messageOps as any).client;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('getHistory with mentions', () => {
|
|
35
|
+
it('should fetch user info for mentioned users in message text', async () => {
|
|
36
|
+
const mockMessages = [
|
|
37
|
+
{
|
|
38
|
+
type: 'message',
|
|
39
|
+
text: 'Hello <@U123456789> can you check this?',
|
|
40
|
+
user: 'U987654321',
|
|
41
|
+
ts: '1234567890.123456',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
type: 'message',
|
|
45
|
+
text: '<@U111111111> and <@U222222222> please review',
|
|
46
|
+
user: 'U333333333',
|
|
47
|
+
ts: '1234567891.123456',
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const mockUsersInfo = {
|
|
52
|
+
U123456789: { ok: true, user: { name: 'john.doe' } },
|
|
53
|
+
U987654321: { ok: true, user: { name: 'jane.smith' } },
|
|
54
|
+
U111111111: { ok: true, user: { name: 'alice.brown' } },
|
|
55
|
+
U222222222: { ok: true, user: { name: 'bob.wilson' } },
|
|
56
|
+
U333333333: { ok: true, user: { name: 'charlie.davis' } },
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
mockClient.conversations.history.mockResolvedValue({
|
|
60
|
+
ok: true,
|
|
61
|
+
messages: mockMessages,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
mockClient.users.info.mockImplementation(({ user }: { user: string }) => {
|
|
65
|
+
return Promise.resolve(mockUsersInfo[user] || { ok: false });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
vi.mocked(channelResolver.resolveChannelId).mockResolvedValue('C123456789');
|
|
69
|
+
|
|
70
|
+
const result = await messageOps.getHistory('test-channel', { limit: 10 });
|
|
71
|
+
|
|
72
|
+
// Verify all user IDs were fetched (both message authors and mentioned users)
|
|
73
|
+
expect(mockClient.users.info).toHaveBeenCalledTimes(5);
|
|
74
|
+
expect(mockClient.users.info).toHaveBeenCalledWith({ user: 'U987654321' });
|
|
75
|
+
expect(mockClient.users.info).toHaveBeenCalledWith({ user: 'U333333333' });
|
|
76
|
+
expect(mockClient.users.info).toHaveBeenCalledWith({ user: 'U123456789' });
|
|
77
|
+
expect(mockClient.users.info).toHaveBeenCalledWith({ user: 'U111111111' });
|
|
78
|
+
expect(mockClient.users.info).toHaveBeenCalledWith({ user: 'U222222222' });
|
|
79
|
+
|
|
80
|
+
// Verify the returned users map contains all users
|
|
81
|
+
expect(result.users.get('U123456789')).toBe('john.doe');
|
|
82
|
+
expect(result.users.get('U987654321')).toBe('jane.smith');
|
|
83
|
+
expect(result.users.get('U111111111')).toBe('alice.brown');
|
|
84
|
+
expect(result.users.get('U222222222')).toBe('bob.wilson');
|
|
85
|
+
expect(result.users.get('U333333333')).toBe('charlie.davis');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should handle messages with own mentions correctly', async () => {
|
|
89
|
+
const mockMessages = [
|
|
90
|
+
{
|
|
91
|
+
type: 'message',
|
|
92
|
+
text: '<@U07L5D50RAL> please check this task',
|
|
93
|
+
user: 'U123456789',
|
|
94
|
+
ts: '1234567890.123456',
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const mockUsersInfo = {
|
|
99
|
+
U123456789: { ok: true, user: { name: 'john.doe' } },
|
|
100
|
+
U07L5D50RAL: { ok: true, user: { name: 'koguchi_s' } },
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
mockClient.conversations.history.mockResolvedValue({
|
|
104
|
+
ok: true,
|
|
105
|
+
messages: mockMessages,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
mockClient.users.info.mockImplementation(({ user }: { user: string }) => {
|
|
109
|
+
return Promise.resolve(mockUsersInfo[user] || { ok: false });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
vi.mocked(channelResolver.resolveChannelId).mockResolvedValue('C123456789');
|
|
113
|
+
|
|
114
|
+
const result = await messageOps.getHistory('test-channel', { limit: 10 });
|
|
115
|
+
|
|
116
|
+
// Verify both users were fetched
|
|
117
|
+
expect(mockClient.users.info).toHaveBeenCalledTimes(2);
|
|
118
|
+
expect(mockClient.users.info).toHaveBeenCalledWith({ user: 'U123456789' });
|
|
119
|
+
expect(mockClient.users.info).toHaveBeenCalledWith({ user: 'U07L5D50RAL' });
|
|
120
|
+
|
|
121
|
+
// Verify the returned users map contains both users
|
|
122
|
+
expect(result.users.get('U123456789')).toBe('john.doe');
|
|
123
|
+
expect(result.users.get('U07L5D50RAL')).toBe('koguchi_s');
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|