Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
dont assert the first time in receiveMessage, as it will show an ugly…
Browse files Browse the repository at this point in the history
… assert error while everything is fine, just need to wait longer
  • Loading branch information
bwindels committed Sep 14, 2018
1 parent 9f4cf77 commit af255c6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/usecases/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,23 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
// wait for a response to come in that contains the message
// crude, but effective

async function assertLastMessage() {
async function getLastMessage() {
const lastTile = await getLastEventTile(session);
const lastMessage = await getMessageFromEventTile(lastTile);
await assertMessage(lastMessage, expectedMessage);
return getMessageFromEventTile(lastTile);
}

// first try to see if the message is already the last message in the timeline
let lastMessage = null;
let isExpectedMessage = false;
try {
assertLastMessage();
isExpectedMessage = true;
lastMessage = await getLastMessage();
isExpectedMessage = lastMessage &&
lastMessage.body === expectedMessage.body &&
lastMessage.sender === expectedMessage.sender;
} catch(ex) {}

if (!isExpectedMessage) {
// first try to see if the message is already the last message in the timeline
if (isExpectedMessage) {
assertMessage(lastMessage, expectedMessage);
} else {
await session.page.waitForResponse(async (response) => {
if (response.request().url().indexOf("/sync") === -1) {
return false;
Expand All @@ -75,7 +78,8 @@ module.exports.receiveMessage = async function(session, expectedMessage) {
});
// wait a bit for the incoming event to be rendered
await session.delay(1000);
await assertLastMessage();
lastMessage = await getLastMessage();
assertMessage(lastMessage, expectedMessage);
}

session.log.done();
Expand Down

0 comments on commit af255c6

Please sign in to comment.