Commit 1aeabf0f authored by Tim Kinnane's avatar Tim Kinnane
Browse files

test(asteroid): Update tests for Asteroid downgrade

parent 20ffba02
......@@ -22,6 +22,7 @@ or platform of choice.
See full API documentation links in the generated docs. Below is just a summary:
---
### `driver.connect(options, cb?)`
- Options accepts `host` and `timeout`
......@@ -29,6 +30,7 @@ See full API documentation links in the generated docs. Below is just a summary:
- Can return a promise, or use error-first callback pattern
See [Asteroid][asteroid] docs for methods that can be called from that API.
---
## Getting Started
......
......@@ -12,62 +12,62 @@ BRH:0
end_of_record
TN:
SF:/Volumes/x/code/rocketchat-bot-driver/src/lib/driver.ts
FN:83,connect
FN:84,(anonymous_3)
FN:96,(anonymous_4)
FN:97,(anonymous_5)
FN:99,(anonymous_6)
FN:85,connect
FN:86,(anonymous_3)
FN:98,(anonymous_4)
FN:99,(anonymous_5)
FN:101,(anonymous_6)
FN:107,(anonymous_7)
FN:122,disconnect
FN:125,(anonymous_9)
FN:135,setupMethodCache
FN:156,asyncCall
FN:160,(anonymous_12)
FN:164,(anonymous_13)
FN:173,callMethod
FN:182,cacheCall
FN:184,(anonymous_16)
FN:188,(anonymous_17)
FN:200,login
FN:214,(anonymous_19)
FN:221,logout
FN:222,(anonymous_21)
FN:233,subscribe
FN:234,(anonymous_23)
FN:238,(anonymous_24)
FN:260,unsubscribe
FN:270,unsubscribeAll
FN:271,(anonymous_27)
FN:278,subscribeToMessages
FN:280,(anonymous_29)
FN:288,reactToMessages
FN:290,(anonymous_31)
FN:331,getRoomId
FN:336,getRoomName
FN:344,getDirectMessageRoomId
FN:349,joinRoom
FN:350,(anonymous_36)
FN:354,joinRooms
FN:355,(anonymous_38)
FN:362,prepareMessage
FN:373,sendMessageByRoomId
FN:376,(anonymous_41)
FN:380,(anonymous_42)
FN:388,sendMessageByRoom
FN:389,(anonymous_44)
FN:398,sendMessage
FN:407,customMessage
FN:120,disconnect
FN:123,(anonymous_9)
FN:133,setupMethodCache
FN:154,asyncCall
FN:158,(anonymous_12)
FN:162,(anonymous_13)
FN:175,callMethod
FN:186,cacheCall
FN:188,(anonymous_16)
FN:192,(anonymous_17)
FN:204,login
FN:218,(anonymous_19)
FN:225,logout
FN:226,(anonymous_21)
FN:237,subscribe
FN:238,(anonymous_23)
FN:242,(anonymous_24)
FN:264,unsubscribe
FN:274,unsubscribeAll
FN:275,(anonymous_27)
FN:282,subscribeToMessages
FN:284,(anonymous_29)
FN:292,reactToMessages
FN:294,(anonymous_31)
FN:335,getRoomId
FN:340,getRoomName
FN:348,getDirectMessageRoomId
FN:353,joinRoom
FN:354,(anonymous_36)
FN:358,joinRooms
FN:359,(anonymous_38)
FN:366,prepareMessage
FN:377,sendMessageByRoomId
FN:380,(anonymous_41)
FN:384,(anonymous_42)
FN:392,sendMessageByRoom
FN:393,(anonymous_44)
FN:402,sendMessage
FN:411,customMessage
FNF:45
FNH:6
FNDA:5,connect
FNDA:5,(anonymous_3)
FNDA:4,(anonymous_4)
FNDA:9,connect
FNDA:9,(anonymous_3)
FNDA:5,(anonymous_4)
FNDA:0,(anonymous_5)
FNDA:2,(anonymous_6)
FNDA:4,(anonymous_7)
FNDA:4,(anonymous_6)
FNDA:5,(anonymous_7)
FNDA:0,disconnect
FNDA:0,(anonymous_9)
FNDA:5,setupMethodCache
FNDA:9,setupMethodCache
FNDA:0,asyncCall
FNDA:0,(anonymous_12)
FNDA:0,(anonymous_13)
......@@ -114,169 +114,172 @@ DA:36,1
DA:41,1
DA:50,1
DA:62,1
DA:83,1
DA:84,5
DA:85,5
DA:86,5
DA:87,5
DA:95,5
DA:96,5
DA:97,5
DA:99,5
DA:100,2
DA:102,2
DA:105,2
DA:107,5
DA:108,4
DA:111,4
DA:112,4
DA:122,1
DA:85,1
DA:86,9
DA:87,9
DA:88,9
DA:89,9
DA:97,9
DA:98,9
DA:99,9
DA:101,9
DA:102,4
DA:104,4
DA:105,4
DA:107,9
DA:108,5
DA:110,5
DA:111,5
DA:112,5
DA:120,1
DA:121,0
DA:122,0
DA:123,0
DA:124,0
DA:125,0
DA:136,5
DA:137,5
DA:145,5
DA:156,1
DA:134,9
DA:135,9
DA:143,9
DA:154,1
DA:155,0
DA:156,0
DA:157,0
DA:158,0
DA:159,0
DA:161,0
DA:162,0
DA:165,0
DA:168,0
DA:173,1
DA:174,0
DA:182,1
DA:183,0
DA:185,0
DA:186,0
DA:160,0
DA:163,0
DA:166,0
DA:175,1
DA:176,0
DA:186,1
DA:187,0
DA:189,0
DA:192,0
DA:200,1
DA:201,0
DA:203,0
DA:204,0
DA:209,0
DA:211,0
DA:212,0
DA:214,0
DA:190,0
DA:193,0
DA:196,0
DA:204,1
DA:205,0
DA:207,0
DA:208,0
DA:213,0
DA:215,0
DA:216,0
DA:221,1
DA:222,0
DA:223,0
DA:224,0
DA:233,1
DA:234,0
DA:235,0
DA:236,0
DA:237,0
DA:218,0
DA:219,0
DA:220,0
DA:225,1
DA:226,0
DA:227,0
DA:228,0
DA:237,1
DA:238,0
DA:239,0
DA:240,0
DA:260,1
DA:261,0
DA:262,0
DA:263,0
DA:241,0
DA:242,0
DA:243,0
DA:244,0
DA:264,1
DA:265,0
DA:266,0
DA:270,1
DA:271,0
DA:278,1
DA:279,0
DA:281,0
DA:284,0
DA:288,1
DA:289,0
DA:290,0
DA:291,0
DA:292,0
DA:267,0
DA:269,0
DA:270,0
DA:274,1
DA:275,0
DA:282,1
DA:283,0
DA:285,0
DA:288,0
DA:292,1
DA:293,0
DA:294,0
DA:295,0
DA:296,0
DA:297,0
DA:298,0
DA:301,0
DA:331,1
DA:332,0
DA:336,1
DA:337,0
DA:344,1
DA:345,0
DA:349,1
DA:350,0
DA:354,1
DA:355,0
DA:362,1
DA:363,0
DA:364,0
DA:365,0
DA:373,1
DA:374,0
DA:375,0
DA:376,0
DA:299,0
DA:300,0
DA:302,0
DA:305,0
DA:335,1
DA:336,0
DA:340,1
DA:341,0
DA:348,1
DA:349,0
DA:353,1
DA:354,0
DA:358,1
DA:359,0
DA:366,1
DA:367,0
DA:368,0
DA:369,0
DA:377,1
DA:378,0
DA:379,0
DA:380,0
DA:388,1
DA:389,0
DA:398,1
DA:399,0
DA:400,0
DA:407,1
DA:408,0
LF:121
LH:50
DA:382,0
DA:384,0
DA:392,1
DA:393,0
DA:402,1
DA:403,0
DA:404,0
DA:411,1
DA:412,0
LF:122
LH:51
BRDA:37,0,0,1
BRDA:37,0,1,0
BRDA:38,1,0,1
BRDA:38,1,1,1
BRDA:83,2,0,1
BRDA:105,3,0,2
BRDA:105,3,1,0
BRDA:113,4,0,3
BRDA:113,4,1,1
BRDA:138,5,0,5
BRDA:138,5,1,5
BRDA:139,6,0,5
BRDA:139,6,1,5
BRDA:142,7,0,5
BRDA:142,7,1,5
BRDA:143,8,0,5
BRDA:143,8,1,5
BRDA:146,9,0,5
BRDA:146,9,1,5
BRDA:147,10,0,5
BRDA:147,10,1,5
BRDA:157,11,0,0
BRDA:157,11,1,0
BRDA:166,12,0,0
BRDA:166,12,1,0
BRDA:190,13,0,0
BRDA:190,13,1,0
BRDA:201,14,0,0
BRDA:201,14,1,0
BRDA:203,15,0,0
BRDA:203,15,1,0
BRDA:211,16,0,0
BRDA:211,16,1,0
BRDA:211,16,2,0
BRDA:262,17,0,0
BRDA:262,17,1,0
BRDA:292,18,0,0
BRDA:292,18,1,0
BRDA:292,19,0,0
BRDA:292,19,1,0
BRDA:294,20,0,0
BRDA:294,20,1,0
BRDA:364,21,0,0
BRDA:364,21,1,0
BRDA:375,22,0,0
BRDA:375,22,1,0
BRDA:399,23,0,0
BRDA:399,23,1,0
BRF:48
BRH:19
BRDA:85,2,0,2
BRDA:105,3,0,3
BRDA:105,3,1,1
BRDA:111,4,0,2
BRDA:111,4,1,3
BRDA:136,5,0,9
BRDA:136,5,1,9
BRDA:137,6,0,9
BRDA:137,6,1,9
BRDA:140,7,0,9
BRDA:140,7,1,9
BRDA:141,8,0,9
BRDA:141,8,1,9
BRDA:144,9,0,9
BRDA:144,9,1,9
BRDA:145,10,0,9
BRDA:145,10,1,9
BRDA:155,11,0,0
BRDA:155,11,1,0
BRDA:164,12,0,0
BRDA:164,12,1,0
BRDA:177,13,0,0
BRDA:177,13,1,0
BRDA:194,14,0,0
BRDA:194,14,1,0
BRDA:205,15,0,0
BRDA:205,15,1,0
BRDA:207,16,0,0
BRDA:207,16,1,0
BRDA:215,17,0,0
BRDA:215,17,1,0
BRDA:215,17,2,0
BRDA:266,18,0,0
BRDA:266,18,1,0
BRDA:296,19,0,0
BRDA:296,19,1,0
BRDA:296,20,0,0
BRDA:296,20,1,0
BRDA:298,21,0,0
BRDA:298,21,1,0
BRDA:368,22,0,0
BRDA:368,22,1,0
BRDA:379,23,0,0
BRDA:379,23,1,0
BRDA:403,24,0,0
BRDA:403,24,1,0
BRF:50
BRH:20
end_of_record
TN:
SF:/Volumes/x/code/rocketchat-bot-driver/src/lib/message.ts
......@@ -304,61 +307,65 @@ SF:/Volumes/x/code/rocketchat-bot-driver/src/lib/methodCache.ts
FN:15,use
FN:25,create
FN:36,call
FN:59,get
FN:68,clear
FN:78,clearAll
FN:79,(anonymous_7)
FNF:7
FNH:4
FNDA:5,use
FNDA:15,create
FNDA:0,call
FNDA:0,get
FNDA:0,clear
FNDA:1,clearAll
FNDA:3,(anonymous_7)
FN:59,has
FN:68,get
FN:77,reset
FN:87,resetAll
FN:88,(anonymous_8)
FNF:8
FNH:8
FNDA:25,use
FNDA:34,create
FNDA:23,call
FNDA:3,has
FNDA:4,get
FNDA:3,reset
FNDA:20,resetAll
FNDA:126,(anonymous_8)
DA:1,1
DA:5,1
DA:6,1
DA:15,1
DA:16,5
DA:16,25
DA:25,1
DA:26,15
DA:27,15
DA:28,15
DA:26,34
DA:27,34
DA:28,34
DA:36,1
DA:37,0
DA:38,0
DA:41,0
DA:42,0
DA:44,0
DA:47,0
DA:48,0
DA:49,0
DA:51,0
DA:37,23
DA:38,23
DA:41,23
DA:42,2
DA:44,2
DA:47,21
DA:48,21
DA:49,19
DA:51,21
DA:59,1
DA:60,0
DA:60,3
DA:68,1
DA:69,0
DA:70,0
DA:71,0
DA:78,1
DA:69,4
DA:77,1
DA:78,3
DA:79,3
LF:27
LH:14
BRDA:25,0,0,0
BRDA:37,1,0,0
BRDA:37,1,1,0
BRDA:41,2,0,0
BRDA:41,2,1,0
BRDA:60,3,0,0
BRDA:60,3,1,0
BRDA:69,4,0,0
BRDA:69,4,1,0
BRDA:70,5,0,0
BRDA:70,5,1,0
DA:80,1
DA:87,1
DA:88,126
LF:29
LH:29
BRDA:25,0,0,5
BRDA:37,1,0,3
BRDA:37,1,1,20
BRDA:41,2,0,2
BRDA:41,2,1,21
BRDA:69,3,0,4
BRDA:69,3,1,0
BRDA:78,4,0,3
BRDA:78,4,1,0
BRDA:79,5,0,2
BRDA:79,5,1,1
BRF:11
BRH:0
BRH:9
end_of_record
TN:
SF:/Volumes/x/code/rocketchat-bot-driver/src/utils/api.ts
......
......@@ -28,6 +28,8 @@ export declare let subscriptions: ISubscription[];
export declare let messages: ICollection;
/**
* Initialise asteroid instance with given options or defaults.
* Returns promise, resolved with Asteroid instance. Callback follows
* error-first-pattern. Error returned or promise rejected on timeout.
* @example <caption>Use with callback</caption>
* import { driver } from 'rocketchat-bot-driver'
* driver.connect({}, (err) => {
......@@ -40,7 +42,7 @@ export declare let messages: ICollection;
* .then(() => console.log('connected'))
* .catch((err) => console.error(err))
*/
export declare function connect(options?: IOptions, callback?: ICallback): Promise<any>;
export declare function connect(options?: IOptions, callback?: ICallback): any;
/**
* Remove all active subscriptions, logout and disconnect from Rocket.Chat
*/
......@@ -51,8 +53,12 @@ export declare function disconnect(): Promise<void>;
* @param params Single or array of parameters of the method to call
*/
export declare function asyncCall(method: string, params: any | any[]): Promise<any>;
/** @alias asyncCall */
export declare function callMethod(name: string, params: any[]): Promise<any>;
/**
* Call a method as async via Asteroid, or through cache if one is created.
* @param name The Rocket.Chat server method to call
* @param params Single or array of parameters of the method to call
*/
export declare function callMethod(name: string, params: any | any[]): Promise<any>;
/**
* Wraps Asteroid method calls, passed through method cache if cache is valid.
* @param method The Rocket.Chat server method, to call through Asteroid
......
......@@ -59,6 +59,8 @@ exports.events = new events_1.EventEmitter();
exports.subscriptions = [];
/**
* Initialise asteroid instance with given options or defaults.
* Returns promise, resolved with Asteroid instance. Callback follows
* error-first-pattern. Error returned or promise rejected on timeout.
* @example <caption>Use with callback</caption>
* import { driver } from 'rocketchat-bot-driver'
* driver.connect({}, (err) => {
......@@ -73,9 +75,9 @@ exports.subscriptions = [];
*/
function connect(options = {}, callback) {
return new Promise((resolve, reject) => {
options = Object.assign(defaults, options);
console.log('[connect] Connecting', JSON.stringify(options));
exports.asteroid = new asteroid_1.default(options.host, options.useSsl);
const config = Object.assign({}, defaults, options);
console.log('[connect] Connecting', JSON.stringify(config));
exports.asteroid = new asteroid_1.default(config.host, config.useSsl);
// Asteroid ^v2 interface...
/*
asteroid = new Asteroid({
......@@ -87,22 +89,19 @@ function connect(options = {}, callback) {
exports.asteroid.on('connected', () => exports.events.emit('connected'));
exports.asteroid.on('reconnected', () => exports.events.emit('reconnected'));
// let cancelled = false
const rejectionTimeout = setTimeout(() => {
console.log('[connect] Timeout', options.timeout);
const rejectionTimeout = setTimeout(function () {
console.log(`[connect] Timeout (${config.timeout})`);
// cancelled = true
const err = new Error('Asteroid connection timeout');
// if no callback available, reject the promise
// else, return callback using "error-first-pattern"
return callback ? callback(err, exports.asteroid) : reject(err);
}, options.timeout);
callback ? callback(err, exports.asteroid) : reject(err);
}, config.timeout);
exports.events.once('connected', () => {
console.log('[connect] Connected');
// cancel connection and don't resolve if already rejected
// if (cancelled) return asteroid.disconnect()
// if (cancelled) return asteroid.ddp.disconnect() // cancel if already rejected
clearTimeout(rejectionTimeout);
return (callback !== undefined)
? callback(null, exports.asteroid)
: resolve(exports.asteroid);
if (callback)
callback(null, exports.asteroid);
resolve(exports.asteroid);
});
});
}
......@@ -113,7 +112,7 @@ exports.connect = connect;
function disconnect() {
console.log('Unsubscribing, logging out, disconnecting');
unsubscribeAll();
return logout().then(() => exports.asteroid.disconnect());
return logout().then(() => Promise.resolve()); // asteroid.disconnect()) // v2 only
}
exports.disconnect = disconnect;
// ASYNC AND CACHE METHOD UTILS
......@@ -159,9 +158,15 @@ function asyncCall(method, params) {
});
}
exports.asyncCall = asyncCall;
/** @alias asyncCall */
/**