Commit e9489755 authored by Tim Kinnane's avatar Tim Kinnane

Merge branch 'hotfix/sendFromUser'

parents 7c001690 1654b033
......@@ -36,20 +36,20 @@ FN:218,(anonymous_42)
FN:218,(anonymous_43)
FNF:34
FNH:16
FNDA:33,loggedIn
FNDA:24,getQueryString
FNDA:15,(anonymous_9)
FNDA:39,loggedIn
FNDA:30,getQueryString
FNDA:29,(anonymous_9)
FNDA:8,setAuth
FNDA:45,getHeaders
FNDA:51,getHeaders
FNDA:11,clearHeaders
FNDA:47,success
FNDA:53,success
FNDA:21,post
FNDA:21,(anonymous_16)
FNDA:21,(anonymous_17)
FNDA:0,(anonymous_18)
FNDA:21,get
FNDA:21,(anonymous_21)
FNDA:21,(anonymous_22)
FNDA:27,get
FNDA:27,(anonymous_21)
FNDA:27,(anonymous_22)
FNDA:0,(anonymous_23)
FNDA:20,login
FNDA:21,logout
......@@ -75,30 +75,30 @@ DA:2,1
DA:3,1
DA:17,1
DA:25,1
DA:26,33
DA:26,39
DA:30,1
DA:31,1
DA:37,1
DA:42,1
DA:43,24
DA:44,14
DA:45,15
DA:48,15
DA:43,30
DA:44,20
DA:45,29
DA:48,29
DA:53,1
DA:54,1
DA:57,1
DA:58,8
DA:59,8
DA:63,1
DA:64,45
DA:65,35
DA:64,51
DA:65,41
DA:70,1
DA:72,34
DA:72,40
DA:76,1
DA:77,11
DA:78,11
DA:82,1
DA:83,47
DA:83,53
DA:104,1
DA:110,21
DA:111,21
......@@ -115,19 +115,19 @@ DA:122,21
DA:124,0
DA:125,0
DA:136,1
DA:142,21
DA:143,21
DA:144,21
DA:145,21
DA:146,21
DA:147,21
DA:148,21
DA:149,21
DA:150,21
DA:151,21
DA:142,27
DA:143,27
DA:144,27
DA:145,27
DA:146,27
DA:147,27
DA:148,27
DA:149,27
DA:150,27
DA:151,27
DA:152,0
DA:154,21
DA:155,21
DA:154,27
DA:155,27
DA:157,0
DA:166,1
DA:170,20
......@@ -161,33 +161,33 @@ DA:217,0
DA:218,0
LF:89
LH:77
BRDA:38,0,0,1
BRDA:38,0,1,0
BRDA:38,0,0,0
BRDA:38,0,1,1
BRDA:43,1,0,10
BRDA:43,1,1,14
BRDA:43,2,0,24
BRDA:43,2,1,16
BRDA:43,2,2,16
BRDA:43,1,1,20
BRDA:43,2,0,30
BRDA:43,2,1,22
BRDA:43,2,2,22
BRDA:46,3,0,2
BRDA:46,3,1,13
BRDA:46,3,1,27
BRDA:63,4,0,1
BRDA:64,5,0,10
BRDA:64,5,1,35
BRDA:64,5,1,41
BRDA:65,6,0,1
BRDA:65,6,1,34
BRDA:66,7,0,35
BRDA:66,7,1,34
BRDA:66,7,2,34
BRDA:66,7,3,34
BRDA:92,8,0,45
BRDA:65,6,1,40
BRDA:66,7,0,41
BRDA:66,7,1,40
BRDA:66,7,2,40
BRDA:66,7,3,40
BRDA:92,8,0,51
BRDA:92,8,1,2
BRDA:85,9,0,47
BRDA:85,9,1,47
BRDA:85,9,2,29
BRDA:85,9,3,46
BRDA:85,9,0,53
BRDA:85,9,1,53
BRDA:85,9,2,35
BRDA:85,9,3,52
BRDA:85,9,4,18
BRDA:85,9,5,29
BRDA:85,9,6,27
BRDA:85,9,5,35
BRDA:85,9,6,33
BRDA:85,9,7,2
BRDA:85,9,8,0
BRDA:85,9,9,0
......@@ -200,15 +200,15 @@ BRDA:116,13,0,0
BRDA:116,13,1,21
BRDA:117,14,0,0
BRDA:117,14,1,21
BRDA:139,15,0,1
BRDA:139,15,0,9
BRDA:144,16,0,1
BRDA:144,16,1,20
BRDA:144,17,0,21
BRDA:144,17,1,20
BRDA:144,16,1,26
BRDA:144,17,0,27
BRDA:144,17,1,26
BRDA:149,18,0,0
BRDA:149,18,1,21
BRDA:149,18,1,27
BRDA:150,19,0,0
BRDA:150,19,1,21
BRDA:150,19,1,27
BRDA:166,20,0,6
BRDA:171,21,0,13
BRDA:171,21,1,7
......@@ -218,12 +218,13 @@ BRDA:180,23,0,8
BRDA:180,23,1,0
BRDA:180,24,0,8
BRDA:180,24,1,8
BRDA:180,24,2,8
BRDA:197,25,0,13
BRDA:197,25,1,8
BRDA:213,26,0,0
BRDA:216,27,0,0
BRF:61
BRH:49
BRF:62
BRH:50
end_of_record
TN:
SF:/Volumes/x/code/rocketchat/Rocket.Chat.js.SDK/src/lib/driver.ts
......@@ -606,7 +607,7 @@ FNDA:0,(anonymous_3)
FNDA:0,(anonymous_4)
FNDA:2,replaceLog
FNDA:2,silence
FNDA:214,(anonymous_7)
FNDA:226,(anonymous_7)
FNDA:205,(anonymous_8)
FNDA:0,(anonymous_9)
FNDA:0,(anonymous_10)
......@@ -619,7 +620,7 @@ DA:18,0
DA:22,1
DA:25,2
DA:29,2
DA:30,214
DA:30,226
DA:31,205
DA:32,0
DA:33,0
......@@ -749,13 +750,13 @@ BRDA:3,0,1,9
BRDA:4,1,0,9
BRDA:4,1,1,9
BRDA:8,2,0,9
BRDA:8,2,1,6
BRDA:8,2,1,5
BRDA:10,3,0,2
BRDA:10,3,1,7
BRDA:10,4,0,2
BRDA:10,4,1,0
BRDA:11,5,0,7
BRDA:11,5,1,5
BRDA:11,5,1,4
BRDA:16,6,0,2
BRDA:16,6,1,7
BRDA:16,7,0,2
......
......@@ -174,7 +174,7 @@ function login(user = {
}
}
const result = yield post('login', user, false);
if (result.data && result.data.authToken) {
if (result && result.data && result.data.authToken) {
exports.currentLogin = {
result: result,
username: user.username,
......
This diff is collapsed.
......@@ -6,10 +6,18 @@ export declare function userInfo(username: string): Promise<IUserResultAPI>;
/** Create a user and catch the error if they exist already */
export declare function createUser(user: INewUserAPI): Promise<IUserResultAPI>;
/** Get information about a channel */
export declare function channelInfo(roomName: string): Promise<IChannelResultAPI>;
export declare function channelInfo(query: {
roomName?: string;
roomId?: string;
}): Promise<IChannelResultAPI>;
/** Create a room for tests and catch the error if it exists already */
export declare function createChannel(name: string, members?: string[], readOnly?: boolean): Promise<IChannelResultAPI>;
/** Send message from mock user to channel for tests to listen and respond */
/** @todo Sometimes the post request completes before the change event emits
* the message to the streamer. That's why the interval is used for proof
* of receipt. It would be better for the endpoint to not resolve until
* server side handling is complete. Would require PR to core.
*/
export declare function sendFromUser(payload: any): Promise<IMessageResultAPI>;
/** Update message sent from mock user */
export declare function updateFromUser(payload: IMessageUpdateAPI): Promise<IMessageResultAPI>;
......
......@@ -27,9 +27,9 @@ function createUser(user) {
}
exports.createUser = createUser;
/** Get information about a channel */
function channelInfo(roomName) {
function channelInfo(query) {
return __awaiter(this, void 0, void 0, function* () {
return api_1.get('channels.info', { roomName }, true);
return api_1.get('channels.info', query, true);
});
}
exports.channelInfo = channelInfo;
......@@ -41,13 +41,43 @@ function createChannel(name, members = [], readOnly = false) {
}
exports.createChannel = createChannel;
/** Send message from mock user to channel for tests to listen and respond */
/** @todo Sometimes the post request completes before the change event emits
* the message to the streamer. That's why the interval is used for proof
* of receipt. It would be better for the endpoint to not resolve until
* server side handling is complete. Would require PR to core.
*/
function sendFromUser(payload) {
return __awaiter(this, void 0, void 0, function* () {
const testChannel = yield channelInfo(exports.testChannelName);
const messageDefaults = { roomId: testChannel.channel._id };
const user = yield api_1.login({ username: config_1.mockUser.username, password: config_1.mockUser.password });
const endpoint = (payload.roomId && payload.roomId.indexOf(user.data.userId) !== -1)
? 'dm.history'
: 'channels.history';
const roomId = (payload.roomId)
? payload.roomId
: (yield channelInfo({ roomName: exports.testChannelName })).channel._id;
const messageDefaults = { roomId };
const data = Object.assign({}, messageDefaults, payload);
yield api_1.login({ username: config_1.mockUser.username, password: config_1.mockUser.password });
return api_1.post('chat.postMessage', data, true);
const oldest = new Date().toISOString();
const result = yield api_1.post('chat.postMessage', data, true);
const proof = new Promise((resolve, reject) => {
let looked = 0;
const look = setInterval(() => __awaiter(this, void 0, void 0, function* () {
const { messages } = yield api_1.get(endpoint, { roomId, oldest });
const found = messages.some((message) => {
return result.message._id === message._id;
});
if (found || looked > 10) {
clearInterval(look);
if (found)
resolve();
else
reject('API send from user, proof of receipt timeout');
}
looked++;
}), 100);
});
yield proof;
return result;
});
}
exports.sendFromUser = sendFromUser;
......@@ -111,7 +141,7 @@ function setup() {
console.log(`Mock user (${config_1.mockUser.username}) exists`);
}
// Verify or create channel for tests
let testChannelInfo = yield channelInfo(exports.testChannelName);
let testChannelInfo = yield channelInfo({ roomName: exports.testChannelName });
if (!testChannelInfo.success) {
console.log(`Test channel (${exports.testChannelName}) not found`);
testChannelInfo = yield createChannel(exports.testChannelName);
......
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../src/utils/testing.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,oCAAqD;AACrD,qCAAqD;AAWrD,6CAA6C;AAChC,QAAA,eAAe,GAAG,OAAO,CAAA;AAEtC,mCAAmC;AACnC,kBAAgC,QAAgB;;QAC9C,MAAM,CAAC,SAAG,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC;CAAA;AAFD,4BAEC;AAED,8DAA8D;AAC9D,oBAAkC,IAAiB;;QACjD,MAAM,CAAC,UAAI,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAA;IAC5D,CAAC;CAAA;AAFD,gCAEC;AAED,sCAAsC;AACtC,qBAAmC,QAAgB;;QACjD,MAAM,CAAC,SAAG,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAA;IACjD,CAAC;CAAA;AAFD,kCAEC;AAED,uEAAuE;AACvE,uBACE,IAAY,EACZ,UAAoB,EAAE,EACtB,WAAoB,KAAK;;QAEzB,MAAM,CAAC,UAAI,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAA;IACnE,CAAC;CAAA;AAND,sCAMC;AAED,6EAA6E;AAC7E,sBAAoC,OAAY;;QAC9C,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,uBAAe,CAAC,CAAA;QACtD,MAAM,eAAe,GAAgB,EAAE,MAAM,EAAE,WAA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AAC,CAAA;gBAC1E,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,cAAc,iBAAQ,CAAC,QAAQ,WAAW,CAAC,CAAA;gBACzD,CAAC;YACH,CAAC;YAAC,IAAI,CAAC,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,cAAc,iBAAQ,CAAC,QAAQ,UAAU,CAAC,CAAA;YACxD,CAAC;YAED,qCAAqC;YACrC,IAAI,eAAe,GAAG,MAAM,WAAW,CAAC,uBAAe,CAAC,CAAA;YACxD,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC7B,OAAO,CAAC,GAAG,CAAC,iBAAiB,uBAAe,aAAa,CAAC,CAAA;gBAC1D,eAAe,GAAG,MAAM,aAAa,CAAC,uBAAe,CAAC,CAAA;gBACtD,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;oBAC7B,MAAM,IAAI,KAAK,CAAC,iBAAiB,uBAAe,wBAAwB,CAAC,CAAA;gBAC3E,CAAC;gBAAC,IAAI,CAAC,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,iBAAiB,uBAAe,WAAW,CAAC,CAAA;gBAC1D,CAAC;YACH,CAAC;YAAC,IAAI,CAAC,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,iBAAiB,uBAAe,UAAU,CAAC,CAAA;YACzD,CAAC;YAED,MAAM,YAAM,EAAE,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACX,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;CAAA;AAzDD,sBAyDC","sourcesContent":["import { get, post, login, logout } from '../lib/api'\nimport { apiUser, botUser, mockUser } from './config'\nimport {\n IMessageAPI,\n IMessageUpdateAPI,\n IMessageResultAPI,\n INewUserAPI,\n IUserResultAPI,\n IRoomResultAPI,\n IChannelResultAPI\n} from './interfaces'\n\n/** Define common attributes for DRY tests */\nexport const testChannelName = 'tests'\n\n/** Get information about a user */\nexport async function userInfo (username: string): Promise<IUserResultAPI> {\n return get('users.info', { username }, true)\n}\n\n/** Create a user and catch the error if they exist already */\nexport async function createUser (user: INewUserAPI): Promise<IUserResultAPI> {\n return post('users.create', user, true, /already in use/i)\n}\n\n/** Get information about a channel */\nexport async function channelInfo (roomName: string): Promise<IChannelResultAPI> {\n return get('channels.info', { roomName }, true)\n}\n\n/** Create a room for tests and catch the error if it exists already */\nexport async function createChannel (\n name: string,\n members: string[] = [],\n readOnly: boolean = false\n): Promise<IChannelResultAPI> {\n return post('channels.create', { name, members, readOnly }, true)\n}\n\n/** Send message from mock user to channel for tests to listen and respond */\nexport async function sendFromUser (payload: any): Promise<IMessageResultAPI> {\n const testChannel = await channelInfo(testChannelName)\n const messageDefaults: IMessageAPI = { roomId: testChannel.channel._id }\n const data: IMessageAPI = Object.assign({}, messageDefaults, payload)\n await login({ username: mockUser.username, password: mockUser.password })\n return post('chat.postMessage', data, true)\n}\n\n/** Update message sent from mock user */\nexport async function updateFromUser (payload: IMessageUpdateAPI): Promise<IMessageResultAPI> {\n await login({ username: mockUser.username, password: mockUser.password })\n return post('chat.update', payload, true)\n}\n\n/** Create a direct message session with the mock user */\nexport async function setupDirectFromUser (): Promise<IRoomResultAPI> {\n await login({ username: mockUser.username, password: mockUser.password })\n return post('im.create', { username: botUser.username }, true)\n}\n\n/** Initialise testing instance with the required users for SDK/bot tests */\nexport async function setup () {\n console.log('\\nPreparing instance for tests...')\n try {\n // Verify API user can login\n const loginInfo = await login(apiUser)\n if (loginInfo.status !== 'success') {\n throw new Error(`API user (${apiUser.username}) could not login`)\n } else {\n console.log(`API user (${apiUser.username}) logged in`)\n }\n\n // Verify or create user for bot\n let botInfo = await userInfo(botUser.username)\n if (!botInfo.success) {\n console.log(`Bot user (${botUser.username}) not found`)\n botInfo = await createUser(botUser)\n if (!botInfo.success) {\n throw new Error(`Bot user (${botUser.username}) could not be created`)\n } else {\n console.log(`Bot user (${botUser.username}) created`)\n }\n } else {\n console.log(`Bot user (${botUser.username}) exists`)\n }\n\n // Verify or create mock user for talking to bot\n let mockInfo = await userInfo(mockUser.username)\n if (!mockInfo.success) {\n console.log(`Mock user (${mockUser.username}) not found`)\n mockInfo = await createUser(mockUser)\n if (!mockInfo.success) {\n throw new Error(`Mock user (${mockUser.username}) could not be created`)\n } else {\n console.log(`Mock user (${mockUser.username}) created`)\n }\n } else {\n console.log(`Mock user (${mockUser.username}) exists`)\n }\n\n // Verify or create channel for tests\n let testChannelInfo = await channelInfo(testChannelName)\n if (!testChannelInfo.success) {\n console.log(`Test channel (${testChannelName}) not found`)\n testChannelInfo = await createChannel(testChannelName)\n if (!testChannelInfo.success) {\n throw new Error(`Test channel (${testChannelName}) could not be created`)\n } else {\n console.log(`Test channel (${testChannelName}) created`)\n }\n } else {\n console.log(`Test channel (${testChannelName}) exists`)\n }\n\n await logout()\n } catch (e) {\n throw e\n }\n}\n"]}
\ No newline at end of file
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../../src/utils/testing.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,oCAAqD;AACrD,qCAAqD;AAYrD,6CAA6C;AAChC,QAAA,eAAe,GAAG,OAAO,CAAA;AAEtC,mCAAmC;AACnC,kBAAgC,QAAgB;;QAC9C,MAAM,CAAC,SAAG,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC;CAAA;AAFD,4BAEC;AAED,8DAA8D;AAC9D,oBAAkC,IAAiB;;QACjD,MAAM,CAAC,UAAI,CAAC,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAA;IAC5D,CAAC;CAAA;AAFD,gCAEC;AAED,sCAAsC;AACtC,qBAAmC,KAA6C;;QAC9E,MAAM,CAAC,SAAG,CAAC,eAAe,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;IAC1C,CAAC;CAAA;AAFD,kCAEC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CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,iBAAiB,uBAAe,UAAU,CAAC,CAAA;YACzD,CAAC;YAED,MAAM,YAAM,EAAE,CAAA;QAChB,CAAC;QAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACX,MAAM,CAAC,CAAA;QACT,CAAC;IACH,CAAC;CAAA;AAzDD,sBAyDC","sourcesContent":["import { get, post, login, logout } from '../lib/api'\nimport { apiUser, botUser, mockUser } from './config'\nimport {\n IMessageAPI,\n IMessageUpdateAPI,\n IMessageResultAPI,\n INewUserAPI,\n IUserResultAPI,\n IRoomResultAPI,\n IChannelResultAPI,\n IMessageReceiptAPI\n} from './interfaces'\n\n/** Define common attributes for DRY tests */\nexport const testChannelName = 'tests'\n\n/** Get information about a user */\nexport async function userInfo (username: string): Promise<IUserResultAPI> {\n return get('users.info', { username }, true)\n}\n\n/** Create a user and catch the error if they exist already */\nexport async function createUser (user: INewUserAPI): Promise<IUserResultAPI> {\n return post('users.create', user, true, /already in use/i)\n}\n\n/** Get information about a channel */\nexport async function channelInfo (query: { roomName?: string, roomId?: string }): Promise<IChannelResultAPI> {\n return get('channels.info', query, true)\n}\n\n/** Create a room for tests and catch the error if it exists already */\nexport async function createChannel (\n name: string,\n members: string[] = [],\n readOnly: boolean = false\n): Promise<IChannelResultAPI> {\n return post('channels.create', { name, members, readOnly }, true)\n}\n\n/** Send message from mock user to channel for tests to listen and respond */\n/** @todo Sometimes the post request completes before the change event emits\n * the message to the streamer. That's why the interval is used for proof\n * of receipt. It would be better for the endpoint to not resolve until\n * server side handling is complete. Would require PR to core.\n */\nexport async function sendFromUser (payload: any): Promise<IMessageResultAPI> {\n const user = await login({ username: mockUser.username, password: mockUser.password })\n const endpoint = (payload.roomId && payload.roomId.indexOf(user.data.userId) !== -1)\n ? 'dm.history'\n : 'channels.history'\n const roomId = (payload.roomId)\n ? payload.roomId\n : (await channelInfo({ roomName: testChannelName })).channel._id\n const messageDefaults: IMessageAPI = { roomId }\n const data: IMessageAPI = Object.assign({}, messageDefaults, payload)\n const oldest = new Date().toISOString()\n const result = await post('chat.postMessage', data, true)\n const proof = new Promise((resolve, reject) => {\n let looked = 0\n const look = setInterval(async () => {\n const { messages } = await get(endpoint, { roomId, oldest })\n const found = messages.some((message: IMessageReceiptAPI) => {\n return result.message._id === message._id\n })\n if (found || looked > 10) {\n clearInterval(look)\n if (found) resolve()\n else reject('API send from user, proof of receipt timeout')\n }\n looked++\n }, 100)\n })\n await proof\n return result\n}\n\n/** Update message sent from mock user */\nexport async function updateFromUser (payload: IMessageUpdateAPI): Promise<IMessageResultAPI> {\n await login({ username: mockUser.username, password: mockUser.password })\n return post('chat.update', payload, true)\n}\n\n/** Create a direct message session with the mock user */\nexport async function setupDirectFromUser (): Promise<IRoomResultAPI> {\n await login({ username: mockUser.username, password: mockUser.password })\n return post('im.create', { username: botUser.username }, true)\n}\n\n/** Initialise testing instance with the required users for SDK/bot tests */\nexport async function setup () {\n console.log('\\nPreparing instance for tests...')\n try {\n // Verify API user can login\n const loginInfo = await login(apiUser)\n if (loginInfo.status !== 'success') {\n throw new Error(`API user (${apiUser.username}) could not login`)\n } else {\n console.log(`API user (${apiUser.username}) logged in`)\n }\n\n // Verify or create user for bot\n let botInfo = await userInfo(botUser.username)\n if (!botInfo.success) {\n console.log(`Bot user (${botUser.username}) not found`)\n botInfo = await createUser(botUser)\n if (!botInfo.success) {\n throw new Error(`Bot user (${botUser.username}) could not be created`)\n } else {\n console.log(`Bot user (${botUser.username}) created`)\n }\n } else {\n console.log(`Bot user (${botUser.username}) exists`)\n }\n\n // Verify or create mock user for talking to bot\n let mockInfo = await userInfo(mockUser.username)\n if (!mockInfo.success) {\n console.log(`Mock user (${mockUser.username}) not found`)\n mockInfo = await createUser(mockUser)\n if (!mockInfo.success) {\n throw new Error(`Mock user (${mockUser.username}) could not be created`)\n } else {\n console.log(`Mock user (${mockUser.username}) created`)\n }\n } else {\n console.log(`Mock user (${mockUser.username}) exists`)\n }\n\n // Verify or create channel for tests\n let testChannelInfo = await channelInfo({ roomName: testChannelName })\n if (!testChannelInfo.success) {\n console.log(`Test channel (${testChannelName}) not found`)\n testChannelInfo = await createChannel(testChannelName)\n if (!testChannelInfo.success) {\n throw new Error(`Test channel (${testChannelName}) could not be created`)\n } else {\n console.log(`Test channel (${testChannelName}) created`)\n }\n } else {\n console.log(`Test channel (${testChannelName}) exists`)\n }\n\n await logout()\n } catch (e) {\n throw e\n }\n}\n"]}
\ No newline at end of file
......@@ -177,7 +177,7 @@ export async function login (user: ILoginCredentials = {
}
}
const result = await post('login', user, false)
if (result.data && result.data.authToken) {
if (result && result.data && result.data.authToken) {
currentLogin = {
result: result, // keep to return if login requested again for same user
username: user.username, // keep to compare with following login attempt
......
......@@ -16,7 +16,7 @@ silence() // suppress log during tests (disable this while developing tests)
describe('driver', () => {
before(async () => {
const testChannel = await utils.channelInfo(tName)
const testChannel = await utils.channelInfo({ roomName: tName })
tId = testChannel.channel._id
})
after(() => logout())
......
......@@ -7,7 +7,8 @@ import {
INewUserAPI,
IUserResultAPI,
IRoomResultAPI,
IChannelResultAPI
IChannelResultAPI,
IMessageReceiptAPI
} from './interfaces'
/** Define common attributes for DRY tests */
......@@ -24,8 +25,8 @@ export async function createUser (user: INewUserAPI): Promise<IUserResultAPI> {
}
/** Get information about a channel */
export async function channelInfo (roomName: string): Promise<IChannelResultAPI> {
return get('channels.info', { roomName }, true)
export async function channelInfo (query: { roomName?: string, roomId?: string }): Promise<IChannelResultAPI> {
return get('channels.info', query, true)
}
/** Create a room for tests and catch the error if it exists already */
......@@ -38,12 +39,40 @@ export async function createChannel (
}
/** Send message from mock user to channel for tests to listen and respond */
/** @todo Sometimes the post request completes before the change event emits
* the message to the streamer. That's why the interval is used for proof
* of receipt. It would be better for the endpoint to not resolve until
* server side handling is complete. Would require PR to core.
*/
export async function sendFromUser (payload: any): Promise<IMessageResultAPI> {
const testChannel = await channelInfo(testChannelName)
const messageDefaults: IMessageAPI = { roomId: testChannel.channel._id }
const user = await login({ username: mockUser.username, password: mockUser.password })
const endpoint = (payload.roomId && payload.roomId.indexOf(user.data.userId) !== -1)
? 'dm.history'
: 'channels.history'
const roomId = (payload.roomId)
? payload.roomId
: (await channelInfo({ roomName: testChannelName })).channel._id
const messageDefaults: IMessageAPI = { roomId }
const data: IMessageAPI = Object.assign({}, messageDefaults, payload)
await login({ username: mockUser.username, password: mockUser.password })
return post('chat.postMessage', data, true)
const oldest = new Date().toISOString()
const result = await post('chat.postMessage', data, true)
const proof = new Promise((resolve, reject) => {
let looked = 0
const look = setInterval(async () => {
const { messages } = await get(endpoint, { roomId, oldest })
const found = messages.some((message: IMessageReceiptAPI) => {
return result.message._id === message._id
})
if (found || looked > 10) {
clearInterval(look)
if (found) resolve()
else reject('API send from user, proof of receipt timeout')
}
looked++
}, 100)
})
await proof
return result
}
/** Update message sent from mock user */
......@@ -99,7 +128,7 @@ export async function setup () {
}
// Verify or create channel for tests
let testChannelInfo = await channelInfo(testChannelName)
let testChannelInfo = await channelInfo({ roomName: testChannelName })
if (!testChannelInfo.success) {
console.log(`Test channel (${testChannelName}) not found`)
testChannelInfo = await createChannel(testChannelName)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment