From 1a2254677c91dc291180a26a5f736bb3e852e6ca Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 9 Oct 2018 15:15:03 +0200 Subject: [PATCH] test leaving members disappear from memberlist --- src/rest/multi.js | 7 ++++++- src/rest/session.js | 14 +++++++++++++- src/scenarios/lazy-loading.js | 15 +++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/rest/multi.js b/src/rest/multi.js index 3d24245ddf..b930a27c1e 100644 --- a/src/rest/multi.js +++ b/src/rest/multi.js @@ -59,6 +59,11 @@ module.exports = class RestMultiSession { this.log.done(); return new RestMultiRoom(rooms, roomIdOrAlias, this.log); } + + room(roomIdOrAlias) { + const rooms = this.sessions.map(s => s.room(roomIdOrAlias)); + return new RestMultiRoom(rooms, roomIdOrAlias, this.log); + } } class RestMultiRoom { @@ -82,7 +87,7 @@ class RestMultiRoom { this.log.step(`leave ${this.roomIdOrAlias}`) await Promise.all(this.rooms.map(async (r) => { r.log.mute(); - await r.leave(message); + await r.leave(); r.log.unmute(); })); this.log.done(); diff --git a/src/rest/session.js b/src/rest/session.js index 21922a69f1..de05cd4b5c 100644 --- a/src/rest/session.js +++ b/src/rest/session.js @@ -24,6 +24,7 @@ module.exports = class RestSession { this.log = new Logger(credentials.userId); this._credentials = credentials; this._displayName = null; + this._rooms = {}; } userId() { @@ -51,7 +52,18 @@ module.exports = class RestSession { this.log.step(`joins ${roomIdOrAlias}`); const {room_id} = await this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`); this.log.done(); - return new RestRoom(this, room_id, this.log); + const room = new RestRoom(this, room_id, this.log); + this._rooms[room_id] = room; + this._rooms[roomIdOrAlias] = room; + return room; + } + + room(roomIdOrAlias) { + if (this._rooms.hasOwnProperty(roomIdOrAlias)) { + return this._rooms[roomIdOrAlias]; + } else { + throw new Error(`${this._credentials.userId} is not in ${roomIdOrAlias}`); + } } async createRoom(name, options) { diff --git a/src/scenarios/lazy-loading.js b/src/scenarios/lazy-loading.js index c33e83215c..7fd67153f0 100644 --- a/src/scenarios/lazy-loading.js +++ b/src/scenarios/lazy-loading.js @@ -40,6 +40,10 @@ module.exports = async function lazyLoadingScenarios(alice, bob, charlies) { await checkMemberList(alice, charly1to5); await joinCharliesWhileAliceIsOffline(alice, charly6to10); await checkMemberList(alice, charly6to10); + await charlies.room(alias).leave(); + await delay(1000); + await checkMemberListLacksCharlies(alice, charlies); + await checkMemberListLacksCharlies(bob, charlies); } const room = "Lazy Loading Test"; @@ -92,6 +96,17 @@ async function checkMemberList(alice, charlies) { alice.log.done(); } +async function checkMemberListLacksCharlies(session, charlies) { + session.log.step(`checks the memberlist doesn't contain ${charlies.log.username}`); + const displayNames = (await getMembersInMemberlist(session)).map((m) => m.displayName); + charlies.sessions.forEach((charly) => { + assert(!displayNames.includes(charly.displayName()), + `${charly.displayName()} should not be in the member list, ` + + `only have ${displayNames}`); + }); + session.log.done(); +} + async function joinCharliesWhileAliceIsOffline(alice, charly6to10) { await alice.setOffline(true); await delay(1000);