diff --git a/test/mocks/guild.ts b/test/mocks/guild.ts index 30c85a23decfc45a89aaa5903a8ded6896cee95a..670d298392d9bfc0c105a39059a84f76a917083b 100644 --- a/test/mocks/guild.ts +++ b/test/mocks/guild.ts @@ -6,8 +6,10 @@ export class MockGuild { public channels = new MockCollection<string, Channel>(); public members = new MockCollection<string, MockMember>(); public id: string; - constructor(id: string, channels: any[]) { + public name: string; + constructor(id: string, channels: any[] = [], name: string = null) { this.id = id; + this.name = name || id; channels.forEach((item) => { this.channels.set(item.id, item); }); diff --git a/test/test_matrixroomhandler.ts b/test/test_matrixroomhandler.ts index 6ddf14aa1d32e6a307e6e7bbf7de234a0f8df91f..b846ed0dd482873c4366350868c6498522a8a909 100644 --- a/test/test_matrixroomhandler.ts +++ b/test/test_matrixroomhandler.ts @@ -10,6 +10,7 @@ import {MatrixRoomHandler} from "../src/matrixroomhandler"; import {MockChannel} from "./mocks/channel"; import {MockMember} from "./mocks/member"; import * as Bluebird from "bluebird"; +import {MockGuild} from "./mocks/guild"; Chai.use(ChaiAsPromised); const expect = Chai.expect; @@ -30,6 +31,7 @@ function buildRequest(eventData) { } function createRH(opts: any = {}) { + log.level = "silent"; USERSJOINED = 0; const bot = { GetChannelFromRoomId: (roomid: string) => { @@ -65,6 +67,10 @@ function createRH(opts: any = {}) { const channel = new MockChannel(); return Promise.resolve({channel, botUser: true }); }, + GetGuilds: () => [new MockGuild("123", [])], + ThirdpartySearchForChannels: () => { + return []; + }, }; const config = new DiscordBridgeConfig(); config.limits.roomGhostJoinDelay = 0; @@ -432,4 +438,45 @@ describe("MatrixRoomHandler", () => { "_discord_123")).to.be.undefined; }); }); + describe("tpGetProtocol", () => { + it("will return an object", () => { + const handler: any = createRH({}); + return handler.tpGetProtocol("").then((protocol) => { + expect(protocol).to.not.be.null; + expect(protocol.instances[0].network_id).to.equal("123"); + expect(protocol.instances[0].bot_user_id).to.equal("@botuser:localhost"); + expect(protocol.instances[0].desc).to.equal("123"); + expect(protocol.instances[0].network_id).to.equal("123"); + }); + }); + }); + describe("tpGetLocation", () => { + it("will return an array", () => { + const handler: any = createRH({}); + return handler.tpGetLocation("", { + guild_id: "", + channel_name: "", + }).then((channels) => { + expect(channels).to.be.a("array"); + }); + }); + }); + describe("tpParseLocation", () => { + it("will reject", () => { + const handler: any = createRH({}); + return expect(handler.tpParseLocation("alias")).to.eventually.be.rejected; + }); + }); + describe("tpGetUser", () => { + it("will reject", () => { + const handler: any = createRH({}); + return expect(handler.tpGetUser("", {})).to.eventually.be.rejected; + }); + }); + describe("tpParseUser", () => { + it("will reject", () => { + const handler: any = createRH({}); + return expect(handler.tpParseUser("alias")).to.eventually.be.rejected; + }); + }); });