Skip to content

Commit

Permalink
Asyncify test
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Oct 13, 2020
1 parent 74c6182 commit 3ddefa8
Showing 1 changed file with 26 additions and 33 deletions.
59 changes: 26 additions & 33 deletions spec/integ/invite-rooms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,55 @@ const envBundle = require("../util/env-bundle");

describe("Invite-only rooms", function() {
const {env, config, roomMapping, botUserId, test} = envBundle();
let testUser = {
const testUser = {
id: "@flibble:wibble",
nick: "flibble"
};
let testIrcUser = {
const testIrcUser = {
localpart: roomMapping.server + "_foobar",
id: "@" + roomMapping.server + "_foobar:" + config.homeserver.domain,
nick: "foobar"
};


beforeEach(test.coroutine(function*() {
yield test.beforeEach(env);
beforeEach(async () => {
await test.beforeEach(env);

env.ircMock._autoConnectNetworks(
roomMapping.server, roomMapping.botNick, roomMapping.server
);

// do the init
yield test.initEnv(env);
}));
await test.initEnv(env);
});

afterEach(test.coroutine(function*() {
yield test.afterEach(env);
}));
afterEach(async () => {
await test.afterEach(env);
});

it("should be joined by the bot if the AS does know the room ID",
function(done) {
let adminRoomId = "!adminroom:id";
let sdk = env.clientMock._client(botUserId);
it("should be joined by the bot if the AS does know the room ID", async() => {
const adminRoomId = "!adminroom:id";
const sdk = env.clientMock._client(botUserId);
let joinRoomCount = 0;
sdk.joinRoom.and.callFake(async (roomId) => {
expect(roomId).toEqual(adminRoomId);
joinRoomCount += 1;
return {room_id: roomId};
});

env.mockAppService._trigger("type:m.room.member", {
await env.mockAppService._trigger("type:m.room.member", {
content: {
membership: "invite",
is_direct: true,
},
state_key: botUserId,
user_id: testUser.id,
room_id: adminRoomId,
type: "m.room.member"
});
expect(joinRoomCount).toEqual(1, "Failed to join admin room");
// inviting them AGAIN to an existing known ADMIN room should trigger a join
await env.mockAppService._trigger("type:m.room.member", {
content: {
membership: "invite",
is_direct: true,
Expand All @@ -49,26 +60,8 @@ describe("Invite-only rooms", function() {
user_id: testUser.id,
room_id: adminRoomId,
type: "m.room.member"
}).then(function() {
expect(joinRoomCount).toEqual(1, "Failed to join admin room");
// inviting them AGAIN to an existing known ADMIN room should trigger a join
return env.mockAppService._trigger("type:m.room.member", {
content: {
membership: "invite",
is_direct: true,
},
state_key: botUserId,
user_id: testUser.id,
room_id: adminRoomId,
type: "m.room.member"
});
}).then(function() {
expect(joinRoomCount).toEqual(2, "Failed to join admin room again");
done();
}, function(err) {
expect(true).toBe(false, "Failed to join admin room again: " + err);
done();
});
expect(joinRoomCount).toEqual(2, "Failed to join admin room again");
});

it("should be joined by a virtual IRC user if the bot invited them, " +
Expand Down

0 comments on commit 3ddefa8

Please sign in to comment.