Skip to content
Extraits de code Groupes Projets
Valider ce9dc4f1 rédigé par Christian Paul's avatar Christian Paul
Parcourir les fichiers

Chai: Use expect() everywhere

parent c29cfc72
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -14,16 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import * as Chai from "chai";
import { expect } from "chai";
import { DiscordStore, CURRENT_SCHEMA } from "../../src/store";
import { RemoteStoreRoom, MatrixStoreRoom } from "../../src/db/roomstore";
// we are a test file and thus need those
/* tslint:disable: no-any no-unused-expression */
const expect = Chai.expect;
// const assert = Chai.assert;
let store: DiscordStore;
describe("RoomStore", () => {
before(async () => {
......
......@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import * as Chai from "chai";
import { expect } from "chai";
import * as Proxyquire from "proxyquire";
import { MockChannel } from "./mocks/channel";
......@@ -25,8 +25,6 @@ import { AppserviceMock } from "./mocks/appservicemock";
// we are a test file and thus need those
/* tslint:disable:no-unused-expression max-file-line-count no-any */
const expect = Chai.expect;
let ROOMSUNBRIDGED = 0;
let MARKED = -1;
function createCH(opts: any = {}) {
......
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import * as Chai from "chai"; // TODO: Use expect
import { expect } from "chai";
import * as Discord from "better-discord.js";
import { DiscordMessageProcessor } from "../src/discordmessageprocessor";
import { DiscordBot } from "../src/bot";
......@@ -53,8 +53,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "Hello World!";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "Hello World!");
Chai.assert.equal(result.formattedBody, "Hello World!");
expect(result.body).to.equal("Hello World!");
expect(result.formattedBody).to.equal("Hello World!");
});
it("processes markdown messages correctly.", async () => {
const processor = new DiscordMessageProcessor(
......@@ -63,8 +63,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "Hello *World*!";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "Hello *World*!");
Chai.assert.equal(result.formattedBody, "Hello <em>World</em>!");
expect(result.body).to.equal("Hello *World*!");
expect(result.formattedBody).to.equal("Hello <em>World</em>!");
});
it("processes non-discord markdown correctly.", async () => {
const processor = new DiscordMessageProcessor(
......@@ -73,14 +73,14 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = ">inb4 tests";
let result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, ">inb4 tests");
Chai.assert.equal(result.formattedBody, "&gt;inb4 tests");
expect(result.body).to.equal(">inb4 tests");
expect(result.formattedBody).to.equal("&gt;inb4 tests");
msg.embeds = [];
msg.content = "[test](http://example.com)";
result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "[test](http://example.com)");
Chai.assert.equal(result.formattedBody,
expect(result.body).to.equal("[test](http://example.com)");
expect(result.formattedBody).to.equal(
"[test](<a href=\"http://example.com\">http://example.com</a>)");
});
it("processes discord-specific markdown correctly.", async () => {
......@@ -90,8 +90,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "_ italic _";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "_ italic _");
Chai.assert.equal(result.formattedBody, "<em> italic </em>");
expect(result.body).to.equal("_ italic _");
expect(result.formattedBody).to.equal("<em> italic </em>");
});
it("replaces @everyone correctly", async () => {
const processor = new DiscordMessageProcessor(
......@@ -100,13 +100,13 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "hey @everyone!";
let result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "hey @everyone!");
Chai.assert.equal(result.formattedBody, "hey @everyone!");
expect(result.body).to.equal("hey @everyone!");
expect(result.formattedBody).to.equal("hey @everyone!");
msg.mentions.everyone = true;
result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "hey @room!");
Chai.assert.equal(result.formattedBody, "hey @room!");
expect(result.body).to.equal("hey @room!");
expect(result.formattedBody).to.equal("hey @room!");
});
it("replaces @here correctly", async () => {
const processor = new DiscordMessageProcessor(
......@@ -115,13 +115,13 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "hey @here!";
let result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "hey @here!");
Chai.assert.equal(result.formattedBody, "hey @here!");
expect(result.body).to.equal("hey @here!");
expect(result.formattedBody).to.equal("hey @here!");
msg.mentions.everyone = true;
result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "hey @room!");
Chai.assert.equal(result.formattedBody, "hey @room!");
expect(result.body).to.equal("hey @room!");
expect(result.formattedBody).to.equal("hey @room!");
});
});
describe("InsertUser / HTML", () => {
......@@ -134,8 +134,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "<@12345>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "@_discord_12345:localhost");
Chai.assert.equal(result.formattedBody, "<a href=\"https://matrix.to/#/@_discord_12345:l" +
expect(result.body).to.equal("@_discord_12345:localhost");
expect(result.formattedBody).to.equal("<a href=\"https://matrix.to/#/@_discord_12345:l" +
"ocalhost\">@_discord_12345:localhost</a>");
});
it("processes members with usernames correctly", async () => {
......@@ -148,8 +148,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "<@12345>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "TestUsername");
Chai.assert.equal(result.formattedBody, "<a href=\"https://matrix.to/#/@_discord_123" +
expect(result.body).to.equal("TestUsername");
expect(result.formattedBody).to.equal("<a href=\"https://matrix.to/#/@_discord_123" +
"45:localhost\">TestUsername</a>");
});
it("processes members with nickname correctly", async () => {
......@@ -162,8 +162,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "<@12345>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "TestNickname");
Chai.assert.equal(result.formattedBody, "<a href=\"https://matrix.to/#/@_disc" +
expect(result.body).to.equal("TestNickname");
expect(result.formattedBody).to.equal("<a href=\"https://matrix.to/#/@_disc" +
"ord_12345:localhost\">TestNickname</a>");
});
});
......@@ -177,8 +177,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "Hello <:hello:123456789>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "Hello <:hello:123456789>");
Chai.assert.equal(result.formattedBody, "Hello &lt;:hello:123456789&gt;");
expect(result.body).to.equal("Hello <:hello:123456789>");
expect(result.formattedBody).to.equal("Hello &lt;:hello:123456789&gt;");
});
it("processes emoji correctly", async () => {
const processor = new DiscordMessageProcessor(
......@@ -190,8 +190,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "Hello <:hello:3333333>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "Hello :hello:");
Chai.assert.equal(result.formattedBody, "Hello <img alt=\":hello:\" ti" +
expect(result.body).to.equal("Hello :hello:");
expect(result.formattedBody).to.equal("Hello <img alt=\":hello:\" ti" +
"tle=\":hello:\" height=\"32\" src=\"mxc://image\" data-mx-emoticon />");
});
});
......@@ -206,8 +206,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "Hello <#3333333>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "Hello <#3333333>");
Chai.assert.equal(result.formattedBody, "Hello &lt;#3333333&gt;");
expect(result.body).to.equal("Hello <#3333333>");
expect(result.formattedBody).to.equal("Hello &lt;#3333333&gt;");
});
it("processes channels correctly", async () => {
const processor = new DiscordMessageProcessor(
......@@ -219,8 +219,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "Hello <#456>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "Hello #TestChannel");
Chai.assert.equal(result.formattedBody, "Hello <a href=\"https://matrix.to/#/#_discord_123" +
expect(result.body).to.equal("Hello #TestChannel");
expect(result.formattedBody).to.equal("Hello <a href=\"https://matrix.to/#/#_discord_123" +
"_456:localhost\">#TestChannel</a>");
});
it("processes channels without alias correctly", async () => {
......@@ -233,8 +233,8 @@ describe("DiscordMessageProcessor", () => {
msg.embeds = [];
msg.content = "Hello <#678>";
const result = await processor.FormatMessage(msg);
Chai.assert.equal(result.body, "Hello <#678>");
Chai.assert.equal(result.formattedBody, "Hello &lt;#678&gt;");
expect(result.body).to.equal("Hello <#678>");
expect(result.formattedBody).to.equal("Hello &lt;#678&gt;");
});
});
});
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import * as Chai from "chai";
import { expect } from "chai";
import { DiscordStore } from "../src/store";
import { DbEmoji } from "../src/db/dbdataemoji";
import { DbEvent } from "../src/db/dbdataevent";
......@@ -57,14 +57,14 @@ describe("DiscordStore", () => {
insertEmoji.MxcUrl = "TestUrl";
await store.Insert(insertEmoji);
const getEmoji = await store.Get(DbEmoji, {emoji_id: "123"});
Chai.assert.equal(getEmoji!.Name, "TestEmoji");
Chai.assert.equal(getEmoji!.MxcUrl, "TestUrl");
expect(getEmoji!.Name).to.equal("TestEmoji");
expect(getEmoji!.MxcUrl).to.equal("TestUrl");
});
it("should not return nonexistant emoji", async () => {
const store = new DiscordStore(":memory:");
await store.init();
const getEmoji = await store.Get(DbEmoji, {emoji_id: "123"});
Chai.assert.isFalse(getEmoji!.Result);
expect(getEmoji!.Result).to.be.false;
});
it("should update successfully", async () => {
const store = new DiscordStore(":memory:");
......@@ -81,9 +81,9 @@ describe("DiscordStore", () => {
insertEmoji.MxcUrl = "NewURL";
await store.Update(insertEmoji);
const getEmoji = await store.Get(DbEmoji, {emoji_id: "123"});
Chai.assert.equal(getEmoji!.Name, "TestEmoji2");
Chai.assert.equal(getEmoji!.MxcUrl, "NewURL");
Chai.assert.notEqual(getEmoji!.CreatedAt, getEmoji!.UpdatedAt);
expect(getEmoji!.Name).to.equal("TestEmoji2");
expect(getEmoji!.MxcUrl).to.equal("NewURL");
expect(getEmoji!.CreatedAt).to.not.equal(getEmoji!.UpdatedAt);
});
});
describe("Get|Insert|Delete<DbEvent>", () => {
......@@ -108,16 +108,16 @@ describe("DiscordStore", () => {
await store.Insert(event);
const getEventDiscord = await store.Get(DbEvent, {discord_id: "456"});
getEventDiscord!.Next();
Chai.assert.equal(getEventDiscord!.MatrixId, "123");
Chai.assert.equal(getEventDiscord!.DiscordId, "456");
Chai.assert.equal(getEventDiscord!.GuildId, "123");
Chai.assert.equal(getEventDiscord!.ChannelId, "123");
expect(getEventDiscord!.MatrixId).to.equal("123");
expect(getEventDiscord!.DiscordId).to.equal("456");
expect(getEventDiscord!.GuildId).to.equal("123");
expect(getEventDiscord!.ChannelId).to.equal("123");
const getEventMatrix = await store.Get(DbEvent, {matrix_id: "123"});
getEventMatrix!.Next();
Chai.assert.equal(getEventMatrix!.MatrixId, "123");
Chai.assert.equal(getEventMatrix!.DiscordId, "456");
Chai.assert.equal(getEventMatrix!.GuildId, "123");
Chai.assert.equal(getEventMatrix!.ChannelId, "123");
expect(getEventMatrix!.MatrixId).to.equal("123");
expect(getEventMatrix!.DiscordId).to.equal("456");
expect(getEventMatrix!.GuildId).to.equal("123");
expect(getEventMatrix!.ChannelId).to.equal("123");
});
const MSG_COUNT = 5;
it("should get multiple discord msgs successfully", async () => {
......@@ -132,7 +132,7 @@ describe("DiscordStore", () => {
await store.Insert(event);
}
const getEventDiscord = await store.Get(DbEvent, {matrix_id: "123"});
Chai.assert.equal(getEventDiscord!.ResultCount, MSG_COUNT);
expect(getEventDiscord!.ResultCount).to.equal(MSG_COUNT);
});
it("should get multiple matrix msgs successfully", async () => {
const store = new DiscordStore(":memory:");
......@@ -146,13 +146,13 @@ describe("DiscordStore", () => {
await store.Insert(event);
}
const getEventMatrix = await store.Get(DbEvent, {discord_id: "456"});
Chai.assert.equal(getEventMatrix!.ResultCount, MSG_COUNT);
expect(getEventMatrix!.ResultCount).to.equal(MSG_COUNT);
});
it("should not return nonexistant event", async () => {
const store = new DiscordStore(":memory:");
await store.init();
const getMessage = await store.Get(DbEvent, {matrix_id: "123"});
Chai.assert.isFalse(getMessage!.Result);
expect(getMessage!.Result).to.be.false;
});
it("should delete successfully", async () => {
const store = new DiscordStore(":memory:");
......@@ -166,7 +166,7 @@ describe("DiscordStore", () => {
await store.Delete(event);
const getEvent = await store.Get(DbEvent, {matrix_id: "123"});
getEvent!.Next();
Chai.assert.isFalse(getEvent!.Result);
expect(getEvent!.Result).to.be.false;
});
});
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter