signal-sdk 0.1.1 → 0.1.3
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/README.md +23 -11
- package/dist/MultiAccountManager.js +11 -19
- package/dist/SignalBot.js +40 -36
- package/dist/SignalCli.d.ts +25 -301
- package/dist/SignalCli.js +226 -971
- package/dist/__tests__/DeviceManager.test.d.ts +1 -0
- package/dist/__tests__/DeviceManager.test.js +135 -0
- package/dist/__tests__/MultiAccountManager.coverage.test.d.ts +1 -0
- package/dist/__tests__/MultiAccountManager.coverage.test.js +33 -0
- package/dist/__tests__/MultiAccountManager.test.js +3 -3
- package/dist/__tests__/SignalBot.additional.test.js +40 -37
- package/dist/__tests__/SignalBot.coverage.test.d.ts +1 -0
- package/dist/__tests__/SignalBot.coverage.test.js +385 -0
- package/dist/__tests__/SignalBot.test.js +8 -8
- package/dist/__tests__/SignalCli.advanced.test.js +47 -58
- package/dist/__tests__/SignalCli.connections.test.d.ts +1 -0
- package/dist/__tests__/SignalCli.connections.test.js +110 -0
- package/dist/__tests__/SignalCli.e2e.test.js +28 -32
- package/dist/__tests__/SignalCli.events.test.d.ts +1 -0
- package/dist/__tests__/SignalCli.events.test.js +113 -0
- package/dist/__tests__/SignalCli.integration.test.js +6 -5
- package/dist/__tests__/SignalCli.methods.test.js +150 -66
- package/dist/__tests__/SignalCli.parsing.test.js +4 -13
- package/dist/__tests__/SignalCli.simple.test.d.ts +1 -0
- package/dist/__tests__/SignalCli.simple.test.js +77 -0
- package/dist/__tests__/SignalCli.test.js +133 -74
- package/dist/__tests__/config.test.js +19 -29
- package/dist/__tests__/errors.test.js +2 -2
- package/dist/__tests__/retry.test.js +10 -8
- package/dist/__tests__/robustness.test.d.ts +1 -0
- package/dist/__tests__/robustness.test.js +59 -0
- package/dist/__tests__/security.test.d.ts +1 -0
- package/dist/__tests__/security.test.js +50 -0
- package/dist/config.js +3 -3
- package/dist/interfaces.d.ts +27 -0
- package/dist/managers/AccountManager.d.ts +27 -0
- package/dist/managers/AccountManager.js +147 -0
- package/dist/managers/BaseManager.d.ts +9 -0
- package/dist/managers/BaseManager.js +17 -0
- package/dist/managers/ContactManager.d.ts +15 -0
- package/dist/managers/ContactManager.js +123 -0
- package/dist/managers/DeviceManager.d.ts +11 -0
- package/dist/managers/DeviceManager.js +139 -0
- package/dist/managers/GroupManager.d.ts +12 -0
- package/dist/managers/GroupManager.js +78 -0
- package/dist/managers/MessageManager.d.ts +18 -0
- package/dist/managers/MessageManager.js +301 -0
- package/dist/managers/StickerManager.d.ts +8 -0
- package/dist/managers/StickerManager.js +39 -0
- package/dist/retry.js +3 -3
- package/dist/validators.d.ts +9 -0
- package/dist/validators.js +20 -0
- package/package.json +11 -4
- package/scripts/install.js +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const SignalCli_1 = require("../SignalCli");
|
|
4
|
+
// Mock dependencies
|
|
5
|
+
jest.mock('child_process');
|
|
6
|
+
jest.mock('../config', () => ({
|
|
7
|
+
Logger: jest.fn().mockImplementation(() => ({
|
|
8
|
+
debug: jest.fn(),
|
|
9
|
+
info: jest.fn(),
|
|
10
|
+
warn: jest.fn(),
|
|
11
|
+
error: jest.fn(),
|
|
12
|
+
})),
|
|
13
|
+
validateConfig: jest.fn().mockReturnValue({
|
|
14
|
+
verbose: false,
|
|
15
|
+
logFile: undefined,
|
|
16
|
+
maxConcurrentRequests: 10,
|
|
17
|
+
minRequestInterval: 100,
|
|
18
|
+
}),
|
|
19
|
+
}));
|
|
20
|
+
describe('SignalCli - Simple Features', () => {
|
|
21
|
+
let signalCli;
|
|
22
|
+
const mockAccount = '+1234567890';
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
// Reset mocks and instance
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
signalCli = new SignalCli_1.SignalCli(mockAccount);
|
|
27
|
+
// Mock the internal request method to avoid real calls
|
|
28
|
+
signalCli.sendJsonRpcRequest = jest.fn();
|
|
29
|
+
});
|
|
30
|
+
describe('isRegistered', () => {
|
|
31
|
+
it('should return true when user is registered', async () => {
|
|
32
|
+
const mockResponse = [
|
|
33
|
+
{
|
|
34
|
+
number: '+1987654321',
|
|
35
|
+
isRegistered: true,
|
|
36
|
+
uuid: 'uuid-123',
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
signalCli.sendJsonRpcRequest.mockResolvedValue({
|
|
40
|
+
recipients: mockResponse,
|
|
41
|
+
});
|
|
42
|
+
const result = await signalCli.isRegistered('+1987654321');
|
|
43
|
+
expect(result).toBe(true);
|
|
44
|
+
expect(signalCli.sendJsonRpcRequest).toHaveBeenCalledWith('getUserStatus', expect.objectContaining({ recipients: ['+1987654321'] }));
|
|
45
|
+
});
|
|
46
|
+
it('should return false when user is not registered', async () => {
|
|
47
|
+
const mockResponse = [
|
|
48
|
+
{
|
|
49
|
+
number: '+1987654321',
|
|
50
|
+
isRegistered: false,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
signalCli.sendJsonRpcRequest.mockResolvedValue({
|
|
54
|
+
recipients: mockResponse,
|
|
55
|
+
});
|
|
56
|
+
const result = await signalCli.isRegistered('+1987654321');
|
|
57
|
+
expect(result).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('sendNoteToSelf', () => {
|
|
61
|
+
it('should send message to self account', async () => {
|
|
62
|
+
const message = 'Note to self test';
|
|
63
|
+
const mockResponse = {
|
|
64
|
+
timestamp: 123456789,
|
|
65
|
+
results: [],
|
|
66
|
+
};
|
|
67
|
+
// Mock sendMessage to verify it's called correctly
|
|
68
|
+
const sendMessageSpy = jest.spyOn(signalCli, 'sendMessage').mockResolvedValue(mockResponse);
|
|
69
|
+
await signalCli.sendNoteToSelf(message);
|
|
70
|
+
expect(sendMessageSpy).toHaveBeenCalledWith(mockAccount, message, expect.objectContaining({ noteToSelf: true }));
|
|
71
|
+
});
|
|
72
|
+
it('should throw error if account is not configured', async () => {
|
|
73
|
+
const noAccountCli = new SignalCli_1.SignalCli();
|
|
74
|
+
await expect(noAccountCli.sendNoteToSelf('fail')).rejects.toThrow('Account must be configured');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -54,7 +54,8 @@ describe('SignalCli', () => {
|
|
|
54
54
|
});
|
|
55
55
|
it('should send JSON-RPC request for sendMessage', async () => {
|
|
56
56
|
// Mock sendJsonRpcRequest directly
|
|
57
|
-
const sendJsonRpcRequestSpy = jest
|
|
57
|
+
const sendJsonRpcRequestSpy = jest
|
|
58
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
58
59
|
.mockResolvedValue({ results: [{ type: 'SUCCESS' }], timestamp: 123456 });
|
|
59
60
|
await signalCli.sendMessage('+10987654321', 'Hello, world!');
|
|
60
61
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('send', {
|
|
@@ -82,97 +83,96 @@ describe('SignalCli', () => {
|
|
|
82
83
|
jest.spyOn(signalCli, 'sendJsonRpcRequest').mockResolvedValue({});
|
|
83
84
|
});
|
|
84
85
|
it('should remove contact', async () => {
|
|
85
|
-
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
86
|
-
.mockResolvedValue({});
|
|
86
|
+
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest').mockResolvedValue({});
|
|
87
87
|
await signalCli.removeContact('+1234567890', { forget: true });
|
|
88
88
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('removeContact', {
|
|
89
89
|
account: '+1234567890',
|
|
90
90
|
recipient: '+1234567890',
|
|
91
|
-
forget: true
|
|
91
|
+
forget: true,
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
94
|
it('should get user status', async () => {
|
|
95
95
|
const mockResponse = {
|
|
96
|
-
recipients: [
|
|
97
|
-
{ number: '+1234567890', isRegistered: true, uuid: 'test-uuid' }
|
|
98
|
-
]
|
|
96
|
+
recipients: [{ number: '+1234567890', isRegistered: true, uuid: 'test-uuid' }],
|
|
99
97
|
};
|
|
100
|
-
const sendJsonRpcRequestSpy = jest
|
|
98
|
+
const sendJsonRpcRequestSpy = jest
|
|
99
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
101
100
|
.mockResolvedValue(mockResponse);
|
|
102
101
|
const result = await signalCli.getUserStatus(['+1234567890']);
|
|
103
102
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('getUserStatus', {
|
|
104
103
|
account: '+1234567890',
|
|
105
|
-
recipients: ['+1234567890']
|
|
104
|
+
recipients: ['+1234567890'],
|
|
106
105
|
});
|
|
107
106
|
expect(result).toEqual([
|
|
108
|
-
{ number: '+1234567890', isRegistered: true, uuid: 'test-uuid', username: undefined }
|
|
107
|
+
{ number: '+1234567890', isRegistered: true, uuid: 'test-uuid', username: undefined },
|
|
109
108
|
]);
|
|
110
109
|
});
|
|
111
110
|
it('should send payment notification', async () => {
|
|
112
|
-
const sendJsonRpcRequestSpy = jest
|
|
111
|
+
const sendJsonRpcRequestSpy = jest
|
|
112
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
113
113
|
.mockResolvedValue({ timestamp: 123456 });
|
|
114
114
|
await signalCli.sendPaymentNotification('+1234567890', {
|
|
115
115
|
receipt: 'base64-receipt',
|
|
116
|
-
note: 'Payment for coffee'
|
|
116
|
+
note: 'Payment for coffee',
|
|
117
117
|
});
|
|
118
118
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('sendPaymentNotification', {
|
|
119
119
|
account: '+1234567890',
|
|
120
120
|
recipient: '+1234567890',
|
|
121
121
|
receipt: 'base64-receipt',
|
|
122
|
-
note: 'Payment for coffee'
|
|
122
|
+
note: 'Payment for coffee',
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
125
|
it('should upload sticker pack', async () => {
|
|
126
126
|
const mockResponse = {
|
|
127
127
|
packId: 'pack-id',
|
|
128
128
|
packKey: 'pack-key',
|
|
129
|
-
installUrl: 'https://signal.org/stickers/pack-id'
|
|
129
|
+
installUrl: 'https://signal.org/stickers/pack-id',
|
|
130
130
|
};
|
|
131
|
-
const sendJsonRpcRequestSpy = jest
|
|
131
|
+
const sendJsonRpcRequestSpy = jest
|
|
132
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
132
133
|
.mockResolvedValue(mockResponse);
|
|
133
134
|
const result = await signalCli.uploadStickerPack({
|
|
134
|
-
path: '/path/to/manifest.json'
|
|
135
|
+
path: '/path/to/manifest.json',
|
|
135
136
|
});
|
|
136
137
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('uploadStickerPack', {
|
|
137
138
|
account: '+1234567890',
|
|
138
|
-
path: '/path/to/manifest.json'
|
|
139
|
+
path: '/path/to/manifest.json',
|
|
139
140
|
});
|
|
140
141
|
expect(result).toEqual(mockResponse);
|
|
141
142
|
});
|
|
142
143
|
it('should submit rate limit challenge', async () => {
|
|
143
144
|
const mockResponse = {
|
|
144
145
|
success: true,
|
|
145
|
-
message: 'Challenge accepted'
|
|
146
|
+
message: 'Challenge accepted',
|
|
146
147
|
};
|
|
147
|
-
const sendJsonRpcRequestSpy = jest
|
|
148
|
+
const sendJsonRpcRequestSpy = jest
|
|
149
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
148
150
|
.mockResolvedValue(mockResponse);
|
|
149
151
|
const result = await signalCli.submitRateLimitChallenge('challenge-token', 'captcha-token');
|
|
150
152
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('submitRateLimitChallenge', {
|
|
151
153
|
account: '+1234567890',
|
|
152
154
|
challenge: 'challenge-token',
|
|
153
|
-
captcha: 'captcha-token'
|
|
155
|
+
captcha: 'captcha-token',
|
|
154
156
|
});
|
|
155
157
|
expect(result).toEqual(mockResponse);
|
|
156
158
|
});
|
|
157
159
|
it('should start change number', async () => {
|
|
158
|
-
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
159
|
-
.mockResolvedValue({});
|
|
160
|
+
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest').mockResolvedValue({});
|
|
160
161
|
await signalCli.startChangeNumber('+1987654321');
|
|
161
162
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('startChangeNumber', {
|
|
162
163
|
account: '+1234567890',
|
|
163
164
|
number: '+1987654321',
|
|
164
|
-
voice: false
|
|
165
|
+
voice: false,
|
|
165
166
|
});
|
|
166
167
|
});
|
|
167
168
|
it('should finish change number', async () => {
|
|
168
|
-
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
169
|
-
.mockResolvedValue({});
|
|
169
|
+
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest').mockResolvedValue({});
|
|
170
170
|
await signalCli.finishChangeNumber('+1987654321', '123456', 'pin-code');
|
|
171
171
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('finishChangeNumber', {
|
|
172
172
|
account: '+1234567890',
|
|
173
173
|
number: '+1987654321',
|
|
174
174
|
verificationCode: '123456',
|
|
175
|
-
pin: 'pin-code'
|
|
175
|
+
pin: 'pin-code',
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
178
|
});
|
|
@@ -231,67 +231,71 @@ describe('SignalCli', () => {
|
|
|
231
231
|
});
|
|
232
232
|
it('should create a poll', async () => {
|
|
233
233
|
const mockResponse = { timestamp: 123456789 };
|
|
234
|
-
const sendJsonRpcRequestSpy = jest
|
|
234
|
+
const sendJsonRpcRequestSpy = jest
|
|
235
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
235
236
|
.mockResolvedValue(mockResponse);
|
|
236
237
|
const result = await signalCli.sendPollCreate({
|
|
237
238
|
recipients: ['+1234567890'],
|
|
238
239
|
question: 'What is your favorite color?',
|
|
239
|
-
options: ['Red', 'Blue', 'Green']
|
|
240
|
+
options: ['Red', 'Blue', 'Green'],
|
|
240
241
|
});
|
|
241
242
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('sendPollCreate', {
|
|
242
243
|
account: '+1234567890',
|
|
243
244
|
recipients: ['+1234567890'],
|
|
244
245
|
question: 'What is your favorite color?',
|
|
245
|
-
options: ['Red', 'Blue', 'Green']
|
|
246
|
+
options: ['Red', 'Blue', 'Green'],
|
|
246
247
|
});
|
|
247
248
|
expect(result).toEqual(mockResponse);
|
|
248
249
|
});
|
|
249
250
|
it('should create a group poll', async () => {
|
|
250
251
|
const mockResponse = { timestamp: 123456789 };
|
|
251
|
-
const sendJsonRpcRequestSpy = jest
|
|
252
|
+
const sendJsonRpcRequestSpy = jest
|
|
253
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
252
254
|
.mockResolvedValue(mockResponse);
|
|
253
255
|
const result = await signalCli.sendPollCreate({
|
|
254
256
|
groupId: 'group-123',
|
|
255
257
|
question: 'Best meeting time?',
|
|
256
|
-
options: ['9 AM', '2 PM', '4 PM']
|
|
258
|
+
options: ['9 AM', '2 PM', '4 PM'],
|
|
257
259
|
});
|
|
258
260
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('sendPollCreate', {
|
|
259
261
|
account: '+1234567890',
|
|
260
262
|
groupId: 'group-123',
|
|
261
263
|
question: 'Best meeting time?',
|
|
262
|
-
options: ['9 AM', '2 PM', '4 PM']
|
|
264
|
+
options: ['9 AM', '2 PM', '4 PM'],
|
|
263
265
|
});
|
|
264
266
|
expect(result).toEqual(mockResponse);
|
|
265
267
|
});
|
|
266
268
|
it('should vote on a poll', async () => {
|
|
267
269
|
const mockResponse = { timestamp: 123456790 };
|
|
268
|
-
const sendJsonRpcRequestSpy = jest
|
|
270
|
+
const sendJsonRpcRequestSpy = jest
|
|
271
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
269
272
|
.mockResolvedValue(mockResponse);
|
|
270
273
|
const result = await signalCli.sendPollVote('+1234567890', {
|
|
271
274
|
pollAuthor: '+9876543210',
|
|
272
275
|
pollTimestamp: 123456789,
|
|
273
|
-
optionIndexes: [0, 1]
|
|
276
|
+
optionIndexes: [0, 1],
|
|
274
277
|
});
|
|
275
278
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('sendPollVote', {
|
|
276
279
|
account: '+1234567890',
|
|
277
280
|
recipient: '+1234567890',
|
|
278
281
|
pollAuthor: '+9876543210',
|
|
279
282
|
pollTimestamp: 123456789,
|
|
280
|
-
options: [0, 1]
|
|
283
|
+
options: [0, 1],
|
|
281
284
|
});
|
|
282
285
|
expect(result).toEqual(mockResponse);
|
|
283
286
|
});
|
|
284
287
|
it('should terminate a poll', async () => {
|
|
285
288
|
const mockResponse = { timestamp: 123456791 };
|
|
286
|
-
const sendJsonRpcRequestSpy = jest
|
|
289
|
+
const sendJsonRpcRequestSpy = jest
|
|
290
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
287
291
|
.mockResolvedValue(mockResponse);
|
|
288
292
|
const result = await signalCli.sendPollTerminate('+1234567890', {
|
|
289
|
-
pollTimestamp: 123456789
|
|
293
|
+
pollTimestamp: 123456789,
|
|
290
294
|
});
|
|
291
295
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('sendPollTerminate', {
|
|
292
296
|
account: '+1234567890',
|
|
293
297
|
recipient: '+1234567890',
|
|
294
|
-
pollTimestamp: 123456789
|
|
298
|
+
pollTimestamp: 123456789,
|
|
295
299
|
});
|
|
296
300
|
expect(result).toEqual(mockResponse);
|
|
297
301
|
});
|
|
@@ -303,68 +307,73 @@ describe('SignalCli', () => {
|
|
|
303
307
|
});
|
|
304
308
|
it('should get attachment by ID', async () => {
|
|
305
309
|
const mockBase64 = 'base64-encoded-data';
|
|
306
|
-
const sendJsonRpcRequestSpy = jest
|
|
310
|
+
const sendJsonRpcRequestSpy = jest
|
|
311
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
307
312
|
.mockResolvedValue(mockBase64);
|
|
308
313
|
const result = await signalCli.getAttachment({
|
|
309
|
-
id: 'attachment-123'
|
|
314
|
+
id: 'attachment-123',
|
|
310
315
|
});
|
|
311
316
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('getAttachment', {
|
|
312
317
|
account: '+1234567890',
|
|
313
|
-
id: 'attachment-123'
|
|
318
|
+
id: 'attachment-123',
|
|
314
319
|
});
|
|
315
320
|
expect(result).toBe(mockBase64);
|
|
316
321
|
});
|
|
317
322
|
it('should get contact avatar', async () => {
|
|
318
323
|
const mockBase64 = 'base64-avatar-data';
|
|
319
|
-
const sendJsonRpcRequestSpy = jest
|
|
324
|
+
const sendJsonRpcRequestSpy = jest
|
|
325
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
320
326
|
.mockResolvedValue(mockBase64);
|
|
321
327
|
const result = await signalCli.getAvatar({
|
|
322
|
-
contact: '+9876543210'
|
|
328
|
+
contact: '+9876543210',
|
|
323
329
|
});
|
|
324
330
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('getAvatar', {
|
|
325
331
|
account: '+1234567890',
|
|
326
|
-
contact: '+9876543210'
|
|
332
|
+
contact: '+9876543210',
|
|
327
333
|
});
|
|
328
334
|
expect(result).toBe(mockBase64);
|
|
329
335
|
});
|
|
330
336
|
it('should get profile avatar', async () => {
|
|
331
337
|
const mockBase64 = 'base64-profile-avatar';
|
|
332
|
-
const sendJsonRpcRequestSpy = jest
|
|
338
|
+
const sendJsonRpcRequestSpy = jest
|
|
339
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
333
340
|
.mockResolvedValue(mockBase64);
|
|
334
341
|
const result = await signalCli.getAvatar({
|
|
335
|
-
profile: '+1234567890'
|
|
342
|
+
profile: '+1234567890',
|
|
336
343
|
});
|
|
337
344
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('getAvatar', {
|
|
338
345
|
account: '+1234567890',
|
|
339
|
-
profile: '+1234567890'
|
|
346
|
+
profile: '+1234567890',
|
|
340
347
|
});
|
|
341
348
|
expect(result).toBe(mockBase64);
|
|
342
349
|
});
|
|
343
350
|
it('should get group avatar', async () => {
|
|
344
351
|
const mockBase64 = 'base64-group-avatar';
|
|
345
|
-
const sendJsonRpcRequestSpy = jest
|
|
352
|
+
const sendJsonRpcRequestSpy = jest
|
|
353
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
346
354
|
.mockResolvedValue(mockBase64);
|
|
347
355
|
const result = await signalCli.getAvatar({
|
|
348
|
-
groupId: 'group-123'
|
|
356
|
+
groupId: 'group-123',
|
|
349
357
|
});
|
|
350
358
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('getAvatar', {
|
|
351
359
|
account: '+1234567890',
|
|
352
|
-
groupId: 'group-123'
|
|
360
|
+
groupId: 'group-123',
|
|
353
361
|
});
|
|
354
362
|
expect(result).toBe(mockBase64);
|
|
355
363
|
});
|
|
356
364
|
it('should get sticker data', async () => {
|
|
357
365
|
const mockBase64 = 'base64-sticker-data';
|
|
358
|
-
const sendJsonRpcRequestSpy = jest
|
|
366
|
+
const sendJsonRpcRequestSpy = jest
|
|
367
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
359
368
|
.mockResolvedValue(mockBase64);
|
|
360
369
|
const result = await signalCli.getSticker({
|
|
361
370
|
packId: 'pack-123',
|
|
362
|
-
stickerId: 5
|
|
371
|
+
stickerId: 5,
|
|
363
372
|
});
|
|
364
373
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('getSticker', {
|
|
365
374
|
account: '+1234567890',
|
|
366
375
|
packId: 'pack-123',
|
|
367
|
-
stickerId: 5
|
|
376
|
+
stickerId: 5,
|
|
368
377
|
});
|
|
369
378
|
expect(result).toBe(mockBase64);
|
|
370
379
|
});
|
|
@@ -377,18 +386,19 @@ describe('SignalCli', () => {
|
|
|
377
386
|
it('should update account settings', async () => {
|
|
378
387
|
const mockResponse = {
|
|
379
388
|
username: 'myusername',
|
|
380
|
-
usernameLink: 'https://signal.me/#myusername'
|
|
389
|
+
usernameLink: 'https://signal.me/#myusername',
|
|
381
390
|
};
|
|
382
|
-
const sendJsonRpcRequestSpy = jest
|
|
391
|
+
const sendJsonRpcRequestSpy = jest
|
|
392
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
383
393
|
.mockResolvedValue(mockResponse);
|
|
384
394
|
const result = await signalCli.updateAccount({
|
|
385
395
|
deviceName: 'My Device',
|
|
386
|
-
username: 'myusername'
|
|
396
|
+
username: 'myusername',
|
|
387
397
|
});
|
|
388
398
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('updateAccount', {
|
|
389
399
|
account: '+1234567890',
|
|
390
400
|
deviceName: 'My Device',
|
|
391
|
-
username: 'myusername'
|
|
401
|
+
username: 'myusername',
|
|
392
402
|
});
|
|
393
403
|
expect(result.success).toBe(true);
|
|
394
404
|
expect(result.username).toBe('myusername');
|
|
@@ -397,27 +407,74 @@ describe('SignalCli', () => {
|
|
|
397
407
|
const mockResponse = {
|
|
398
408
|
accounts: [
|
|
399
409
|
{ number: '+1234567890', name: 'Account 1', uuid: 'uuid-1' },
|
|
400
|
-
{ number: '+9876543210', name: 'Account 2', uuid: 'uuid-2' }
|
|
401
|
-
]
|
|
410
|
+
{ number: '+9876543210', name: 'Account 2', uuid: 'uuid-2' },
|
|
411
|
+
],
|
|
402
412
|
};
|
|
403
|
-
const sendJsonRpcRequestSpy = jest
|
|
413
|
+
const sendJsonRpcRequestSpy = jest
|
|
414
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
404
415
|
.mockResolvedValue(mockResponse);
|
|
405
416
|
const result = await signalCli.listAccountsDetailed();
|
|
406
417
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('listAccounts');
|
|
407
418
|
expect(result).toEqual(mockResponse.accounts);
|
|
408
419
|
});
|
|
409
420
|
});
|
|
421
|
+
// Test device management (v0.13.23+)
|
|
422
|
+
describe('Device Management', () => {
|
|
423
|
+
beforeEach(() => {
|
|
424
|
+
jest.spyOn(signalCli, 'sendJsonRpcRequest').mockResolvedValue({});
|
|
425
|
+
});
|
|
426
|
+
it('should list devices', async () => {
|
|
427
|
+
const mockDevices = [
|
|
428
|
+
{ id: 1, name: 'Device 1' },
|
|
429
|
+
{ id: 2, name: 'Device 2' },
|
|
430
|
+
];
|
|
431
|
+
const sendJsonRpcRequestSpy = jest
|
|
432
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
433
|
+
.mockResolvedValue(mockDevices);
|
|
434
|
+
const result = await signalCli.listDevices();
|
|
435
|
+
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('listDevices', {
|
|
436
|
+
account: '+1234567890',
|
|
437
|
+
});
|
|
438
|
+
expect(result).toEqual(mockDevices);
|
|
439
|
+
});
|
|
440
|
+
it('should update device name', async () => {
|
|
441
|
+
const sendJsonRpcRequestSpy = jest
|
|
442
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
443
|
+
.mockResolvedValue(undefined);
|
|
444
|
+
await signalCli.updateDevice({
|
|
445
|
+
deviceId: 2,
|
|
446
|
+
deviceName: 'My Updated Device',
|
|
447
|
+
});
|
|
448
|
+
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('updateDevice', {
|
|
449
|
+
account: '+1234567890',
|
|
450
|
+
deviceId: 2,
|
|
451
|
+
deviceName: 'My Updated Device',
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
it('should validate device ID when updating', async () => {
|
|
455
|
+
await expect(signalCli.updateDevice({
|
|
456
|
+
deviceId: -1,
|
|
457
|
+
deviceName: 'Invalid',
|
|
458
|
+
})).rejects.toThrow();
|
|
459
|
+
});
|
|
460
|
+
it('should validate device name length', async () => {
|
|
461
|
+
const longName = 'a'.repeat(201);
|
|
462
|
+
await expect(signalCli.updateDevice({
|
|
463
|
+
deviceId: 2,
|
|
464
|
+
deviceName: longName,
|
|
465
|
+
})).rejects.toThrow();
|
|
466
|
+
});
|
|
467
|
+
});
|
|
410
468
|
// Test v0.1.0 features: Synchronization
|
|
411
469
|
describe('Synchronization', () => {
|
|
412
470
|
beforeEach(() => {
|
|
413
471
|
jest.spyOn(signalCli, 'sendJsonRpcRequest').mockResolvedValue({});
|
|
414
472
|
});
|
|
415
473
|
it('should send contacts to linked devices', async () => {
|
|
416
|
-
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
417
|
-
.mockResolvedValue({});
|
|
474
|
+
const sendJsonRpcRequestSpy = jest.spyOn(signalCli, 'sendJsonRpcRequest').mockResolvedValue({});
|
|
418
475
|
await signalCli.sendContacts();
|
|
419
476
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('sendContacts', {
|
|
420
|
-
account: '+1234567890'
|
|
477
|
+
account: '+1234567890',
|
|
421
478
|
});
|
|
422
479
|
});
|
|
423
480
|
it('should list groups with detailed information', async () => {
|
|
@@ -426,23 +483,24 @@ describe('SignalCli', () => {
|
|
|
426
483
|
id: 'group-1',
|
|
427
484
|
name: 'Test Group 1',
|
|
428
485
|
members: ['+1111111111', '+2222222222'],
|
|
429
|
-
groupType: 'GROUP_V2'
|
|
486
|
+
groupType: 'GROUP_V2',
|
|
430
487
|
},
|
|
431
488
|
{
|
|
432
489
|
id: 'group-2',
|
|
433
490
|
name: 'Test Group 2',
|
|
434
491
|
members: ['+3333333333'],
|
|
435
|
-
groupType: 'GROUP_V2'
|
|
436
|
-
}
|
|
492
|
+
groupType: 'GROUP_V2',
|
|
493
|
+
},
|
|
437
494
|
];
|
|
438
|
-
const sendJsonRpcRequestSpy = jest
|
|
495
|
+
const sendJsonRpcRequestSpy = jest
|
|
496
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
439
497
|
.mockResolvedValue(mockGroups);
|
|
440
498
|
const result = await signalCli.listGroupsDetailed({
|
|
441
|
-
detailed: true
|
|
499
|
+
detailed: true,
|
|
442
500
|
});
|
|
443
501
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('listGroups', {
|
|
444
502
|
account: '+1234567890',
|
|
445
|
-
detailed: true
|
|
503
|
+
detailed: true,
|
|
446
504
|
});
|
|
447
505
|
expect(result).toEqual(mockGroups);
|
|
448
506
|
});
|
|
@@ -451,19 +509,20 @@ describe('SignalCli', () => {
|
|
|
451
509
|
{
|
|
452
510
|
id: 'group-1',
|
|
453
511
|
name: 'Specific Group',
|
|
454
|
-
members: ['+1111111111']
|
|
455
|
-
}
|
|
512
|
+
members: ['+1111111111'],
|
|
513
|
+
},
|
|
456
514
|
];
|
|
457
|
-
const sendJsonRpcRequestSpy = jest
|
|
515
|
+
const sendJsonRpcRequestSpy = jest
|
|
516
|
+
.spyOn(signalCli, 'sendJsonRpcRequest')
|
|
458
517
|
.mockResolvedValue(mockGroups);
|
|
459
518
|
const result = await signalCli.listGroupsDetailed({
|
|
460
519
|
groupIds: ['group-1'],
|
|
461
|
-
detailed: true
|
|
520
|
+
detailed: true,
|
|
462
521
|
});
|
|
463
522
|
expect(sendJsonRpcRequestSpy).toHaveBeenCalledWith('listGroups', {
|
|
464
523
|
account: '+1234567890',
|
|
465
524
|
detailed: true,
|
|
466
|
-
groupId: ['group-1']
|
|
525
|
+
groupId: ['group-1'],
|
|
467
526
|
});
|
|
468
527
|
expect(result).toEqual(mockGroups);
|
|
469
528
|
});
|