Skip to content
Extraits de code Groupes Projets
Valider 367e76d2 rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

Complete tests for MRH

parent 7720262d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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>();
}
......@@ -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;
});
});
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter