diff --git a/test/mocks/channel.ts b/test/mocks/channel.ts index c9669f94ec275ffd3e035b3a57074639e5816b5c..ba68309187303133ed360346ba130c2e46c66b6c 100644 --- a/test/mocks/channel.ts +++ b/test/mocks/channel.ts @@ -1,9 +1,8 @@ -import {MockUser} from "./user"; -import * as Discord from "discord.js"; import {MockMember} from "./member"; import {MockCollection} from "./collection"; // Mocking TextChannel export class MockChannel { + constructor (public id: string = "", public guild: any = null) { } public members = new MockCollection<string, MockMember>(); } diff --git a/test/test_matrixroomhandler.ts b/test/test_matrixroomhandler.ts index b846ed0dd482873c4366350868c6498522a8a909..343bfb2422189d7b68906a8aa6d58589e89ddd04 100644 --- a/test/test_matrixroomhandler.ts +++ b/test/test_matrixroomhandler.ts @@ -11,6 +11,7 @@ import {MockChannel} from "./mocks/channel"; import {MockMember} from "./mocks/member"; import * as Bluebird from "bluebird"; import {MockGuild} from "./mocks/guild"; +import {Guild} from "discord.js"; Chai.use(ChaiAsPromised); const expect = Chai.expect; @@ -479,4 +480,57 @@ describe("MatrixRoomHandler", () => { return expect(handler.tpParseUser("alias")).to.eventually.be.rejected; }); }); + describe("joinRoom", () => { + it("will join immediately", () => { + const handler: any = createRH({}); + const intent = { + getClient: () => { + return { + joinRoom: () => { + return Promise.resolve(); + } + }; + } + }; + const startTime = Date.now(); + const MAXTIME = 1000; + return expect(handler.joinRoom(intent, "#test:localhost")).to.eventually.be.fulfilled.and.satisfy(() => { + return (Date.now() - startTime) < MAXTIME; + }); + }); + it("will fail first, join after", () => { + log.level = "error"; + const handler: any = createRH({}); + let shouldFail = true; + const intent = { + getClient: () => { + return { + joinRoom: () => { + if (shouldFail) { + shouldFail = false; + return Promise.reject("Test failed first time"); + } + return Promise.resolve(); + }, + getUserId: () => "@test:localhost", + }; + } + }; + const startTime = Date.now(); + const MINTIME = 1000; + return expect(handler.joinRoom(intent, "#test:localhost")).to.eventually.be.fulfilled.and.satisfy(() => { + expect(shouldFail).to.be.false; + return (Date.now() - startTime) > MINTIME; + }); + }); + }); + describe("createMatrixRoom", () => { + it("will return an object", () => { + const handler: any = createRH({}); + const channel = new MockChannel("123", new MockGuild("456")); + const roomOpts = handler.createMatrixRoom(channel, "#test:localhost"); + expect(roomOpts.creationOpts).to.exist; + expect(roomOpts.remote).to.exist; + }); + }); });