Skip to content
This repository has been archived by the owner on Oct 21, 2019. It is now read-only.

test leaving members disappear from memberlist #36

Merged
merged 1 commit into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/rest/multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
14 changes: 13 additions & 1 deletion src/rest/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = class RestSession {
this.log = new Logger(credentials.userId);
this._credentials = credentials;
this._displayName = null;
this._rooms = {};
}

userId() {
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions src/scenarios/lazy-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down