fca-project-orion 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. package/.gitattributes +2 -2
  2. package/Extra/Database/index.js +468 -468
  3. package/Extra/ExtraAddons.js +81 -81
  4. package/Extra/ExtraFindUID.js +61 -61
  5. package/Extra/ExtraGetThread.js +339 -339
  6. package/Extra/ExtraScreenShot.js +430 -430
  7. package/Extra/ExtraUptimeRobot.js +37 -37
  8. package/Extra/Html/Classic/script.js +118 -118
  9. package/Extra/Html/Classic/style.css +7 -7
  10. package/Extra/Security/Base/Step_1.js +5 -5
  11. package/Extra/Security/Base/Step_2.js +22 -22
  12. package/Extra/Security/Base/Step_3.js +22 -22
  13. package/Extra/Security/Base/index.js +172 -172
  14. package/Extra/Security/Index.js +4 -4
  15. package/Extra/Security/Step_1.js +5 -5
  16. package/Extra/Security/Step_2.js +22 -22
  17. package/Extra/Security/Step_3.js +22 -22
  18. package/Extra/Src/Change_Environment.js +23 -23
  19. package/Extra/Src/Check_Update.js +65 -65
  20. package/Extra/Src/History.js +114 -114
  21. package/Extra/Src/Instant_Update.js +64 -64
  22. package/Extra/Src/Last-Run.js +64 -64
  23. package/Extra/Src/Premium.js +80 -80
  24. package/Extra/Src/Release_Memory.js +40 -40
  25. package/Extra/Src/Websocket.js +212 -212
  26. package/Extra/Src/uuid.js +137 -137
  27. package/Func/AcceptAgreement.js +31 -31
  28. package/Func/ClearCache.js +64 -64
  29. package/Func/ReportV1.js +54 -54
  30. package/LICENSE +21 -21
  31. package/Language/index.json +216 -216
  32. package/Main.js +1215 -1215
  33. package/README.md +138 -138
  34. package/SECURITY.md +18 -18
  35. package/broadcast.js +39 -39
  36. package/index.js +385 -385
  37. package/logger.js +66 -66
  38. package/package.json +93 -93
  39. package/src/Dev_Horizon_Data.js +124 -124
  40. package/src/Premium.js +24 -24
  41. package/src/Screenshot.js +82 -82
  42. package/src/addExternalModule.js +16 -16
  43. package/src/addUserToGroup.js +79 -79
  44. package/src/changeAdminStatus.js +79 -79
  45. package/src/changeArchivedStatus.js +41 -41
  46. package/src/changeAvt.js +84 -84
  47. package/src/changeBio.js +65 -65
  48. package/src/changeBlockedStatus.js +36 -36
  49. package/src/changeGroupImage.js +106 -106
  50. package/src/changeNickname.js +45 -45
  51. package/src/changeThreadColor.js +62 -62
  52. package/src/changeThreadEmoji.js +42 -42
  53. package/src/createNewGroup.js +70 -70
  54. package/src/createPoll.js +60 -60
  55. package/src/deleteMessage.js +45 -45
  56. package/src/deleteThread.js +43 -43
  57. package/src/forwardAttachment.js +48 -48
  58. package/src/getAccessToken.js +27 -27
  59. package/src/getCurrentUserID.js +7 -7
  60. package/src/getEmojiUrl.js +27 -27
  61. package/src/getFriendsList.js +73 -73
  62. package/src/getMessage.js +79 -79
  63. package/src/getThreadHistory.js +537 -537
  64. package/src/getThreadInfo.js +424 -424
  65. package/src/getThreadList.js +213 -213
  66. package/src/getThreadMain.js +219 -219
  67. package/src/getThreadPictures.js +59 -59
  68. package/src/getUID.js +58 -58
  69. package/src/getUserID.js +62 -62
  70. package/src/getUserInfo.js +113 -113
  71. package/src/getUserInfoMain.js +64 -64
  72. package/src/getUserInfoV2.js +31 -31
  73. package/src/getUserInfoV3.js +62 -62
  74. package/src/getUserInfoV4.js +54 -54
  75. package/src/getUserInfoV5.js +60 -60
  76. package/src/handleFriendRequest.js +46 -46
  77. package/src/handleMessageRequest.js +49 -49
  78. package/src/httpGet.js +49 -49
  79. package/src/httpPost.js +48 -48
  80. package/src/httpPostFormData.js +40 -40
  81. package/src/listenMqtt.js +786 -786
  82. package/src/logout.js +68 -68
  83. package/src/markAsDelivered.js +48 -48
  84. package/src/markAsRead.js +70 -70
  85. package/src/markAsReadAll.js +42 -42
  86. package/src/markAsSeen.js +51 -51
  87. package/src/muteThread.js +47 -47
  88. package/src/removeUserFromGroup.js +49 -49
  89. package/src/resolvePhotoUrl.js +37 -37
  90. package/src/searchForThread.js +43 -43
  91. package/src/sendMessage.js +378 -378
  92. package/src/sendTypingIndicator.js +80 -80
  93. package/src/setMessageReaction.js +109 -109
  94. package/src/setPostReaction.js +101 -101
  95. package/src/setTitle.js +74 -74
  96. package/src/threadColors.js +38 -38
  97. package/src/unfriend.js +43 -43
  98. package/src/unsendMessage.js +40 -40
  99. package/test/Database_Test.js +3 -3
  100. package/test/Db2.js +529 -529
  101. package/test/data/shareAttach.js +146 -146
  102. package/test/data/test.txt +7 -7
  103. package/test/example-config.json +18 -18
  104. package/test/memoryleak.js +18 -18
  105. package/test/test-page.js +140 -140
  106. package/test/test.js +385 -385
  107. package/test/testv2.js +17 -17
  108. package/utils.js +1682 -1682
package/test/test.js CHANGED
@@ -1,385 +1,385 @@
1
- var login = require('../index.js');
2
- var fs = require('fs');
3
- var assert = require('assert');
4
-
5
- var conf = JSON.parse(process.env.testconfig || fs.readFileSync('test/test-config.json', 'utf8'));
6
- var credentials = {
7
- email: conf.user.email,
8
- password: conf.user.password,
9
- };
10
-
11
- var userIDs = conf.userIDs;
12
-
13
- var options = { selfListen: true, listenEvents: true, logLevel: "silent"};
14
- var pageOptions = {logLevel: 'silent', pageID: conf.pageID};
15
- var getType = require('../utils').getType;
16
- var formatDeltaMessage = require('../utils').formatDeltaMessage;
17
- var shareAttachmentFixture = require('./data/shareAttach');
18
-
19
- var userID = conf.user.id;
20
-
21
- var groupChatID;
22
- var groupChatName;
23
-
24
- function checkErr(done){
25
- return function(err) {
26
- if (err) done(err);
27
- };
28
- }
29
-
30
- describe('Login:', function() {
31
- var api = null;
32
- process.on('SIGINT', () => api && !api.logout() && console.log("Logged out :)"));
33
- var tests = [];
34
- var stopListening;
35
- this.timeout(20000);
36
-
37
- function listen(done, matcher) {
38
- tests.push({matcher:matcher, done:done});
39
- }
40
-
41
- before(function(done) {
42
- login(credentials, options, function (err, localAPI) {
43
- if(err) return done(err);
44
-
45
- assert(localAPI);
46
- api = localAPI;
47
- stopListening = api.listen(function (err, msg) {
48
- if (err) throw err;
49
- if (msg.type === "message") {
50
- assert(msg.senderID && !isNaN(msg.senderID));
51
- assert(msg.threadID && !isNaN(msg.threadID));
52
- assert(msg.timestamp && !isNaN(msg.timestamp));
53
- assert(msg.messageID != null && msg.messageID.length > 0);
54
- assert(msg.body != null || msg.attachments.length > 0);
55
- }
56
- // Removes matching function and calls corresponding done
57
- tests = tests.filter(function(test) {
58
- return !(test.matcher(msg) && (test.done() || true));
59
- });
60
- });
61
-
62
- done();
63
- });
64
- });
65
-
66
- it('should login without error', function (){
67
- assert(api);
68
- });
69
-
70
- it('should get the current user ID', function (){
71
- assert(userID === api.getCurrentUserID());
72
- });
73
-
74
- it('should send text message object (user)', function (done){
75
- var body = "text-msg-obj-" + Date.now();
76
- listen(done, msg =>
77
- msg.type === 'message' &&
78
- msg.body === body &&
79
- msg.isGroup === false
80
- );
81
- api.sendMessage({body: body}, userID, checkErr(done));
82
- });
83
-
84
- it('should send sticker message object (user)', function (done){
85
- var stickerID = '767334526626290';
86
- listen(done, msg =>
87
- msg.type === 'message' &&
88
- msg.attachments.length > 0 &&
89
- msg.attachments[0].type === 'sticker' &&
90
- msg.attachments[0].stickerID === stickerID &&
91
- msg.isGroup === false
92
- );
93
- api.sendMessage({sticker: stickerID}, userID, checkErr(done));
94
- });
95
-
96
- it('should send basic string (user)', function (done){
97
- var body = "basic-str-" + Date.now();
98
- listen(done, msg =>
99
- msg.type === 'message' &&
100
- msg.body === body &&
101
- msg.isGroup === false
102
- );
103
- api.sendMessage(body, userID, checkErr(done));
104
- });
105
-
106
- it('should get thread info (user)', function (done){
107
- api.getThreadInfo(userID, (err, info) => {
108
- if (err) done(err);
109
-
110
- assert(info.participantIDs != null && info.participantIDs.length > 0);
111
- assert(!info.participantIDs.some(isNaN));
112
- assert(!info.participantIDs.some(v => v.length == 0));
113
- assert(info.name != null);
114
- assert(info.messageCount != null && !isNaN(info.messageCount));
115
- assert(info.hasOwnProperty('emoji'));
116
- assert(info.hasOwnProperty('nicknames'));
117
- assert(info.hasOwnProperty('color'));
118
- done();
119
- });
120
- });
121
-
122
-
123
- it('should get the history of the chat (user)', function (done) {
124
- api.getThreadHistory(userID, 5, null, function(err, data) {
125
- checkErr(done)(err);
126
- assert(getType(data) === "Array");
127
- assert(data.every(function(v) {return getType(v) == "Object";}));
128
- done();
129
- });
130
- });
131
-
132
- it('should get the history of the chat (user) (graphql)', function (done) {
133
- api.getThreadHistoryGraphQL(userID, 5, null, function(err, data) {
134
- checkErr(done)(err);
135
- assert(getType(data) === "Array");
136
- assert(data.every(function(v) {return getType(v) == "Object";}));
137
- done();
138
- });
139
- });
140
-
141
- it('should create a chat', function (done){
142
- var body = "new-chat-" + Date.now();
143
- var inc = 0;
144
-
145
- function doneHack(){
146
- if (inc === 1) return done();
147
- inc++;
148
- }
149
-
150
- listen(doneHack, msg =>
151
- msg.type === 'message' && msg.body === body
152
- );
153
- api.sendMessage(body, userIDs, function(err, info){
154
- checkErr(done)(err);
155
- groupChatID = info.threadID;
156
- doneHack();
157
- });
158
- });
159
-
160
- it('should send text message object (group)', function (done){
161
- var body = "text-msg-obj-" + Date.now();
162
- listen(done, msg =>
163
- msg.type === 'message' &&
164
- msg.body === body &&
165
- msg.isGroup === true
166
- );
167
- api.sendMessage({body: body}, groupChatID, function(err, info){
168
- checkErr(done)(err);
169
- assert(groupChatID === info.threadID);
170
- });
171
- });
172
-
173
- it('should send basic string (group)', function (done){
174
- var body = "basic-str-" + Date.now();
175
- listen(done, msg =>
176
- msg.type === 'message' &&
177
- msg.body === body &&
178
- msg.isGroup === true
179
- );
180
- api.sendMessage(body, groupChatID, function(err, info) {
181
- checkErr(done)(err);
182
- assert(groupChatID === info.threadID);
183
- });
184
- });
185
-
186
- it('should send sticker message object (group)', function (done){
187
- var stickerID = '767334526626290';
188
- listen(done, function (msg) {
189
- return msg.type === 'message' &&
190
- msg.attachments.length > 0 &&
191
- msg.attachments[0].type === 'sticker' &&
192
- msg.attachments[0].stickerID === stickerID;
193
- });
194
- api.sendMessage({sticker: stickerID}, groupChatID, function (err, info) {
195
- assert(groupChatID === info.threadID);
196
- checkErr(done)(err);
197
- });
198
- });
199
-
200
- it('should send an attachment with a body (group)', function (done){
201
- var body = "attach-" + Date.now();
202
- var attach = [];
203
- attach.push(fs.createReadStream("test/data/test.txt"));
204
- attach.push(fs.createReadStream("test/data/test.png"));
205
- listen(done, function (msg) {
206
- return msg.type === 'message' && msg.body === body;
207
- });
208
- api.sendMessage({attachment: attach, body: body}, groupChatID, function(err, info){
209
- checkErr(done)(err);
210
- assert(groupChatID === info.threadID);
211
- });
212
- });
213
-
214
- it('should get the history of the chat (group)', function (done) {
215
- api.getThreadHistory(groupChatID, 5, null, function(err, data) {
216
- checkErr(done)(err);
217
- assert(getType(data) === "Array");
218
- assert(data.every(function(v) {return getType(v) == "Object";}));
219
- done();
220
- });
221
- });
222
-
223
- it('should get the history of the chat (group) (graphql)', function (done) {
224
- api.getThreadHistoryGraphQL(groupChatID, 5, null, function(err, data) {
225
- checkErr(done)(err);
226
- assert(getType(data) === "Array");
227
- assert(data.every(function(v) {return getType(v) == "Object";}));
228
- done();
229
- });
230
- });
231
-
232
-
233
- it('should change chat title', function (done){
234
- var title = 'test-chat-title-' + Date.now();
235
- listen(done, function (msg) {
236
- return msg.type === 'event' &&
237
- msg.logMessageType === 'log:thread-name' &&
238
- msg.logMessageData.name === title;
239
- });
240
- groupChatName = title;
241
- api.setTitle(title, groupChatID, checkErr(done));
242
- });
243
-
244
- it('should kick user', function (done) {
245
- var id = userIDs[0];
246
- listen(done, function (msg) {
247
- return msg.type === 'event' &&
248
- msg.logMessageType === 'log:unsubscribe' &&
249
- msg.logMessageData.leftParticipantFbId === id;
250
- });
251
- api.removeUserFromGroup(id, groupChatID, checkErr(done));
252
- });
253
-
254
- it('should add user', function (done) {
255
- var id = userIDs[0];
256
- listen(done, function (msg) {
257
- return (msg.type === 'event' &&
258
- msg.logMessageType === 'log:subscribe' &&
259
- msg.logMessageData.addedParticipants.length > 0 &&
260
- msg.logMessageData.addedParticipants[0].userFbId === id);
261
- });
262
- // TODO: we don't check for errors inside this because FB changed and
263
- // returns an error, even though we receive the event that the user was
264
- // added
265
- api.addUserToGroup(id, groupChatID, function() {});
266
- });
267
-
268
- xit('should get thread info (group)', function (done){
269
- api.getThreadInfo(groupChatID, (err, info) => {
270
- if (err) done(err);
271
-
272
- assert(info.participantIDs != null && info.participantIDs.length > 0);
273
- assert(!info.participantIDs.some(isNaN));
274
- assert(!info.participantIDs.some(v => v.length == 0));
275
- assert(info.name != null);
276
- assert(info.messageCount != null && !isNaN(info.messageCount));
277
- assert(info.hasOwnProperty('emoji'));
278
- assert(info.hasOwnProperty('nicknames'));
279
- assert(info.hasOwnProperty('color'));
280
- done();
281
- });
282
- });
283
-
284
- it('should retrieve a list of threads', function (done) {
285
- api.getThreadList(0, 20, function(err, res) {
286
- checkErr(done)(err);
287
-
288
- // This checks to see if the group chat we just made
289
- // is in the list... it should be.
290
- assert(res.some(function (v) {
291
- return (
292
- v.threadID === groupChatID &&
293
- userIDs.every(function (val) {
294
- return v.participants.indexOf(val) > -1;
295
- }) &&
296
- v.name === groupChatName
297
- );
298
- }));
299
- done();
300
- });
301
- });
302
-
303
- it('should mark as read', function (done){
304
- api.markAsRead(groupChatID, done);
305
- });
306
-
307
- it('should send typing indicator', function (done) {
308
- var stopType = api.sendTypingIndicator(groupChatID, function(err) {
309
- checkErr(done)(err);
310
- stopType();
311
- done();
312
- });
313
- });
314
-
315
-
316
- it('should get the right user info', function (done) {
317
- api.getUserInfo(userID, function(err, data) {
318
- checkErr(done)(err);
319
- var user = data[userID];
320
- assert(user.name);
321
- assert(user.firstName);
322
- assert(user.vanity !== null);
323
- assert(user.profileUrl);
324
- assert(user.gender);
325
- assert(user.type);
326
- assert(!user.isFriend);
327
- done();
328
- });
329
- });
330
-
331
- it('should get the user ID', function(done) {
332
- api.getUserInfo(userIDs[0], function(err, data) {
333
- checkErr(done)(err);
334
- var user = data[userIDs[0]];
335
- api.getUserID(user.name, function(err, data) {
336
- checkErr(done)(err);
337
- assert(getType(data) === "Array");
338
- assert(data.some(function(val) {
339
- return val.userID === userIDs[0];
340
- }));
341
- done();
342
- });
343
- });
344
- });
345
-
346
- it('should get the list of friends', function (done) {
347
- api.getFriendsList(function(err, data) {
348
- try {
349
- checkErr(done)(err);
350
- assert(getType(data) === "Array");
351
- data.map(v => {
352
- assert(getType(v.firstName) === "String");
353
- assert(getType(v.gender) === "String");
354
- assert(getType(v.userID) === "String");
355
- assert(getType(v.isFriend) === "Boolean");
356
- assert(getType(v.fullName) === "String");
357
- assert(getType(v.profilePicture) === "String");
358
- assert(getType(v.type) === "String");
359
- assert(v.hasOwnProperty("profileUrl")); // This can be null if the account is disabled
360
- assert(getType(v.isBirthday) === "Boolean");
361
- });
362
- done();
363
- } catch(e){
364
- done(e);
365
- }
366
- });
367
- });
368
-
369
- it('should parse share attachment correctly', function () {
370
- var formatted = formatDeltaMessage(shareAttachmentFixture);
371
- assert(formatted.attachments[0].type === "share");
372
- assert(formatted.attachments[0].title === "search engines");
373
- assert(formatted.attachments[0].target.items[0].name === "search engines");
374
- assert(formatted.attachments[0].target.items[0].call_to_actions.length === 3);
375
- assert(formatted.attachments[0].target.items[0].call_to_actions[0].title === "Google");
376
- });
377
-
378
- it('should log out', function (done) {
379
- api.logout(done);
380
- });
381
-
382
- after(function (){
383
- if (stopListening) stopListening();
384
- });
385
- });
1
+ var login = require('../index.js');
2
+ var fs = require('fs');
3
+ var assert = require('assert');
4
+
5
+ var conf = JSON.parse(process.env.testconfig || fs.readFileSync('test/test-config.json', 'utf8'));
6
+ var credentials = {
7
+ email: conf.user.email,
8
+ password: conf.user.password,
9
+ };
10
+
11
+ var userIDs = conf.userIDs;
12
+
13
+ var options = { selfListen: true, listenEvents: true, logLevel: "silent"};
14
+ var pageOptions = {logLevel: 'silent', pageID: conf.pageID};
15
+ var getType = require('../utils').getType;
16
+ var formatDeltaMessage = require('../utils').formatDeltaMessage;
17
+ var shareAttachmentFixture = require('./data/shareAttach');
18
+
19
+ var userID = conf.user.id;
20
+
21
+ var groupChatID;
22
+ var groupChatName;
23
+
24
+ function checkErr(done){
25
+ return function(err) {
26
+ if (err) done(err);
27
+ };
28
+ }
29
+
30
+ describe('Login:', function() {
31
+ var api = null;
32
+ process.on('SIGINT', () => api && !api.logout() && console.log("Logged out :)"));
33
+ var tests = [];
34
+ var stopListening;
35
+ this.timeout(20000);
36
+
37
+ function listen(done, matcher) {
38
+ tests.push({matcher:matcher, done:done});
39
+ }
40
+
41
+ before(function(done) {
42
+ login(credentials, options, function (err, localAPI) {
43
+ if(err) return done(err);
44
+
45
+ assert(localAPI);
46
+ api = localAPI;
47
+ stopListening = api.listen(function (err, msg) {
48
+ if (err) throw err;
49
+ if (msg.type === "message") {
50
+ assert(msg.senderID && !isNaN(msg.senderID));
51
+ assert(msg.threadID && !isNaN(msg.threadID));
52
+ assert(msg.timestamp && !isNaN(msg.timestamp));
53
+ assert(msg.messageID != null && msg.messageID.length > 0);
54
+ assert(msg.body != null || msg.attachments.length > 0);
55
+ }
56
+ // Removes matching function and calls corresponding done
57
+ tests = tests.filter(function(test) {
58
+ return !(test.matcher(msg) && (test.done() || true));
59
+ });
60
+ });
61
+
62
+ done();
63
+ });
64
+ });
65
+
66
+ it('should login without error', function (){
67
+ assert(api);
68
+ });
69
+
70
+ it('should get the current user ID', function (){
71
+ assert(userID === api.getCurrentUserID());
72
+ });
73
+
74
+ it('should send text message object (user)', function (done){
75
+ var body = "text-msg-obj-" + Date.now();
76
+ listen(done, msg =>
77
+ msg.type === 'message' &&
78
+ msg.body === body &&
79
+ msg.isGroup === false
80
+ );
81
+ api.sendMessage({body: body}, userID, checkErr(done));
82
+ });
83
+
84
+ it('should send sticker message object (user)', function (done){
85
+ var stickerID = '767334526626290';
86
+ listen(done, msg =>
87
+ msg.type === 'message' &&
88
+ msg.attachments.length > 0 &&
89
+ msg.attachments[0].type === 'sticker' &&
90
+ msg.attachments[0].stickerID === stickerID &&
91
+ msg.isGroup === false
92
+ );
93
+ api.sendMessage({sticker: stickerID}, userID, checkErr(done));
94
+ });
95
+
96
+ it('should send basic string (user)', function (done){
97
+ var body = "basic-str-" + Date.now();
98
+ listen(done, msg =>
99
+ msg.type === 'message' &&
100
+ msg.body === body &&
101
+ msg.isGroup === false
102
+ );
103
+ api.sendMessage(body, userID, checkErr(done));
104
+ });
105
+
106
+ it('should get thread info (user)', function (done){
107
+ api.getThreadInfo(userID, (err, info) => {
108
+ if (err) done(err);
109
+
110
+ assert(info.participantIDs != null && info.participantIDs.length > 0);
111
+ assert(!info.participantIDs.some(isNaN));
112
+ assert(!info.participantIDs.some(v => v.length == 0));
113
+ assert(info.name != null);
114
+ assert(info.messageCount != null && !isNaN(info.messageCount));
115
+ assert(info.hasOwnProperty('emoji'));
116
+ assert(info.hasOwnProperty('nicknames'));
117
+ assert(info.hasOwnProperty('color'));
118
+ done();
119
+ });
120
+ });
121
+
122
+
123
+ it('should get the history of the chat (user)', function (done) {
124
+ api.getThreadHistory(userID, 5, null, function(err, data) {
125
+ checkErr(done)(err);
126
+ assert(getType(data) === "Array");
127
+ assert(data.every(function(v) {return getType(v) == "Object";}));
128
+ done();
129
+ });
130
+ });
131
+
132
+ it('should get the history of the chat (user) (graphql)', function (done) {
133
+ api.getThreadHistoryGraphQL(userID, 5, null, function(err, data) {
134
+ checkErr(done)(err);
135
+ assert(getType(data) === "Array");
136
+ assert(data.every(function(v) {return getType(v) == "Object";}));
137
+ done();
138
+ });
139
+ });
140
+
141
+ it('should create a chat', function (done){
142
+ var body = "new-chat-" + Date.now();
143
+ var inc = 0;
144
+
145
+ function doneHack(){
146
+ if (inc === 1) return done();
147
+ inc++;
148
+ }
149
+
150
+ listen(doneHack, msg =>
151
+ msg.type === 'message' && msg.body === body
152
+ );
153
+ api.sendMessage(body, userIDs, function(err, info){
154
+ checkErr(done)(err);
155
+ groupChatID = info.threadID;
156
+ doneHack();
157
+ });
158
+ });
159
+
160
+ it('should send text message object (group)', function (done){
161
+ var body = "text-msg-obj-" + Date.now();
162
+ listen(done, msg =>
163
+ msg.type === 'message' &&
164
+ msg.body === body &&
165
+ msg.isGroup === true
166
+ );
167
+ api.sendMessage({body: body}, groupChatID, function(err, info){
168
+ checkErr(done)(err);
169
+ assert(groupChatID === info.threadID);
170
+ });
171
+ });
172
+
173
+ it('should send basic string (group)', function (done){
174
+ var body = "basic-str-" + Date.now();
175
+ listen(done, msg =>
176
+ msg.type === 'message' &&
177
+ msg.body === body &&
178
+ msg.isGroup === true
179
+ );
180
+ api.sendMessage(body, groupChatID, function(err, info) {
181
+ checkErr(done)(err);
182
+ assert(groupChatID === info.threadID);
183
+ });
184
+ });
185
+
186
+ it('should send sticker message object (group)', function (done){
187
+ var stickerID = '767334526626290';
188
+ listen(done, function (msg) {
189
+ return msg.type === 'message' &&
190
+ msg.attachments.length > 0 &&
191
+ msg.attachments[0].type === 'sticker' &&
192
+ msg.attachments[0].stickerID === stickerID;
193
+ });
194
+ api.sendMessage({sticker: stickerID}, groupChatID, function (err, info) {
195
+ assert(groupChatID === info.threadID);
196
+ checkErr(done)(err);
197
+ });
198
+ });
199
+
200
+ it('should send an attachment with a body (group)', function (done){
201
+ var body = "attach-" + Date.now();
202
+ var attach = [];
203
+ attach.push(fs.createReadStream("test/data/test.txt"));
204
+ attach.push(fs.createReadStream("test/data/test.png"));
205
+ listen(done, function (msg) {
206
+ return msg.type === 'message' && msg.body === body;
207
+ });
208
+ api.sendMessage({attachment: attach, body: body}, groupChatID, function(err, info){
209
+ checkErr(done)(err);
210
+ assert(groupChatID === info.threadID);
211
+ });
212
+ });
213
+
214
+ it('should get the history of the chat (group)', function (done) {
215
+ api.getThreadHistory(groupChatID, 5, null, function(err, data) {
216
+ checkErr(done)(err);
217
+ assert(getType(data) === "Array");
218
+ assert(data.every(function(v) {return getType(v) == "Object";}));
219
+ done();
220
+ });
221
+ });
222
+
223
+ it('should get the history of the chat (group) (graphql)', function (done) {
224
+ api.getThreadHistoryGraphQL(groupChatID, 5, null, function(err, data) {
225
+ checkErr(done)(err);
226
+ assert(getType(data) === "Array");
227
+ assert(data.every(function(v) {return getType(v) == "Object";}));
228
+ done();
229
+ });
230
+ });
231
+
232
+
233
+ it('should change chat title', function (done){
234
+ var title = 'test-chat-title-' + Date.now();
235
+ listen(done, function (msg) {
236
+ return msg.type === 'event' &&
237
+ msg.logMessageType === 'log:thread-name' &&
238
+ msg.logMessageData.name === title;
239
+ });
240
+ groupChatName = title;
241
+ api.setTitle(title, groupChatID, checkErr(done));
242
+ });
243
+
244
+ it('should kick user', function (done) {
245
+ var id = userIDs[0];
246
+ listen(done, function (msg) {
247
+ return msg.type === 'event' &&
248
+ msg.logMessageType === 'log:unsubscribe' &&
249
+ msg.logMessageData.leftParticipantFbId === id;
250
+ });
251
+ api.removeUserFromGroup(id, groupChatID, checkErr(done));
252
+ });
253
+
254
+ it('should add user', function (done) {
255
+ var id = userIDs[0];
256
+ listen(done, function (msg) {
257
+ return (msg.type === 'event' &&
258
+ msg.logMessageType === 'log:subscribe' &&
259
+ msg.logMessageData.addedParticipants.length > 0 &&
260
+ msg.logMessageData.addedParticipants[0].userFbId === id);
261
+ });
262
+ // TODO: we don't check for errors inside this because FB changed and
263
+ // returns an error, even though we receive the event that the user was
264
+ // added
265
+ api.addUserToGroup(id, groupChatID, function() {});
266
+ });
267
+
268
+ xit('should get thread info (group)', function (done){
269
+ api.getThreadInfo(groupChatID, (err, info) => {
270
+ if (err) done(err);
271
+
272
+ assert(info.participantIDs != null && info.participantIDs.length > 0);
273
+ assert(!info.participantIDs.some(isNaN));
274
+ assert(!info.participantIDs.some(v => v.length == 0));
275
+ assert(info.name != null);
276
+ assert(info.messageCount != null && !isNaN(info.messageCount));
277
+ assert(info.hasOwnProperty('emoji'));
278
+ assert(info.hasOwnProperty('nicknames'));
279
+ assert(info.hasOwnProperty('color'));
280
+ done();
281
+ });
282
+ });
283
+
284
+ it('should retrieve a list of threads', function (done) {
285
+ api.getThreadList(0, 20, function(err, res) {
286
+ checkErr(done)(err);
287
+
288
+ // This checks to see if the group chat we just made
289
+ // is in the list... it should be.
290
+ assert(res.some(function (v) {
291
+ return (
292
+ v.threadID === groupChatID &&
293
+ userIDs.every(function (val) {
294
+ return v.participants.indexOf(val) > -1;
295
+ }) &&
296
+ v.name === groupChatName
297
+ );
298
+ }));
299
+ done();
300
+ });
301
+ });
302
+
303
+ it('should mark as read', function (done){
304
+ api.markAsRead(groupChatID, done);
305
+ });
306
+
307
+ it('should send typing indicator', function (done) {
308
+ var stopType = api.sendTypingIndicator(groupChatID, function(err) {
309
+ checkErr(done)(err);
310
+ stopType();
311
+ done();
312
+ });
313
+ });
314
+
315
+
316
+ it('should get the right user info', function (done) {
317
+ api.getUserInfo(userID, function(err, data) {
318
+ checkErr(done)(err);
319
+ var user = data[userID];
320
+ assert(user.name);
321
+ assert(user.firstName);
322
+ assert(user.vanity !== null);
323
+ assert(user.profileUrl);
324
+ assert(user.gender);
325
+ assert(user.type);
326
+ assert(!user.isFriend);
327
+ done();
328
+ });
329
+ });
330
+
331
+ it('should get the user ID', function(done) {
332
+ api.getUserInfo(userIDs[0], function(err, data) {
333
+ checkErr(done)(err);
334
+ var user = data[userIDs[0]];
335
+ api.getUserID(user.name, function(err, data) {
336
+ checkErr(done)(err);
337
+ assert(getType(data) === "Array");
338
+ assert(data.some(function(val) {
339
+ return val.userID === userIDs[0];
340
+ }));
341
+ done();
342
+ });
343
+ });
344
+ });
345
+
346
+ it('should get the list of friends', function (done) {
347
+ api.getFriendsList(function(err, data) {
348
+ try {
349
+ checkErr(done)(err);
350
+ assert(getType(data) === "Array");
351
+ data.map(v => {
352
+ assert(getType(v.firstName) === "String");
353
+ assert(getType(v.gender) === "String");
354
+ assert(getType(v.userID) === "String");
355
+ assert(getType(v.isFriend) === "Boolean");
356
+ assert(getType(v.fullName) === "String");
357
+ assert(getType(v.profilePicture) === "String");
358
+ assert(getType(v.type) === "String");
359
+ assert(v.hasOwnProperty("profileUrl")); // This can be null if the account is disabled
360
+ assert(getType(v.isBirthday) === "Boolean");
361
+ });
362
+ done();
363
+ } catch(e){
364
+ done(e);
365
+ }
366
+ });
367
+ });
368
+
369
+ it('should parse share attachment correctly', function () {
370
+ var formatted = formatDeltaMessage(shareAttachmentFixture);
371
+ assert(formatted.attachments[0].type === "share");
372
+ assert(formatted.attachments[0].title === "search engines");
373
+ assert(formatted.attachments[0].target.items[0].name === "search engines");
374
+ assert(formatted.attachments[0].target.items[0].call_to_actions.length === 3);
375
+ assert(formatted.attachments[0].target.items[0].call_to_actions[0].title === "Google");
376
+ });
377
+
378
+ it('should log out', function (done) {
379
+ api.logout(done);
380
+ });
381
+
382
+ after(function (){
383
+ if (stopListening) stopListening();
384
+ });
385
+ });