make receiveMessage more robust by checking first if the message is not already in the timeline
This commit is contained in:
parent
239e6a4bce
commit
9f4cf776c5
1 changed files with 32 additions and 17 deletions
|
@ -46,23 +46,38 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
|
|||
session.log.step(`receives message "${expectedMessage.body}" from ${expectedMessage.sender}`);
|
||||
// wait for a response to come in that contains the message
|
||||
// crude, but effective
|
||||
await session.page.waitForResponse(async (response) => {
|
||||
if (response.request().url().indexOf("/sync") === -1) {
|
||||
return false;
|
||||
}
|
||||
const body = await response.text();
|
||||
if (expectedMessage.encrypted) {
|
||||
return body.indexOf(expectedMessage.sender) !== -1 &&
|
||||
body.indexOf("m.room.encrypted") !== -1;
|
||||
} else {
|
||||
return body.indexOf(expectedMessage.body) !== -1;
|
||||
}
|
||||
});
|
||||
// wait a bit for the incoming event to be rendered
|
||||
await session.delay(1000);
|
||||
const lastTile = await getLastEventTile(session);
|
||||
const foundMessage = await getMessageFromEventTile(lastTile);
|
||||
assertMessage(foundMessage, expectedMessage);
|
||||
|
||||
async function assertLastMessage() {
|
||||
const lastTile = await getLastEventTile(session);
|
||||
const lastMessage = await getMessageFromEventTile(lastTile);
|
||||
await assertMessage(lastMessage, expectedMessage);
|
||||
}
|
||||
|
||||
// first try to see if the message is already the last message in the timeline
|
||||
let isExpectedMessage = false;
|
||||
try {
|
||||
assertLastMessage();
|
||||
isExpectedMessage = true;
|
||||
} catch(ex) {}
|
||||
|
||||
if (!isExpectedMessage) {
|
||||
await session.page.waitForResponse(async (response) => {
|
||||
if (response.request().url().indexOf("/sync") === -1) {
|
||||
return false;
|
||||
}
|
||||
const body = await response.text();
|
||||
if (expectedMessage.encrypted) {
|
||||
return body.indexOf(expectedMessage.sender) !== -1 &&
|
||||
body.indexOf("m.room.encrypted") !== -1;
|
||||
} else {
|
||||
return body.indexOf(expectedMessage.body) !== -1;
|
||||
}
|
||||
});
|
||||
// wait a bit for the incoming event to be rendered
|
||||
await session.delay(1000);
|
||||
await assertLastMessage();
|
||||
}
|
||||
|
||||
session.log.done();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue