Skip to content

Commit

Permalink
spec/: fix tests to match previous changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ferass El Hafidi <[email protected]>
  • Loading branch information
Ferass El Hafidi committed Aug 10, 2024
1 parent 5dd615d commit 2c99119
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
6 changes: 2 additions & 4 deletions spec/integ/admin-rooms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,12 @@ describe("Admin rooms", function() {
cmdIx++;
});

// 5 commands should be executed
// rubbishserver should not be accepted
// 4 commands should be executed
const commands = [
`!cmd ${roomMapping.server} JOIN ${newChannel}`,
`!cmd ${roomMapping.server} TOPIC ${newChannel} :some new fancy topic`,
`!cmd ${roomMapping.server} PART ${newChannel}`,
`!cmd ${roomMapping.server} STUPID COMMANDS`,
`!cmd rubbishserver SOME COMMAND`];
`!cmd ${roomMapping.server} STUPID COMMANDS`];

for (let i = 0; i < commands.length; i++) {
// send commands
Expand Down
34 changes: 15 additions & 19 deletions spec/integ/matrix-to-irc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe("Matrix-to-IRC message bridging", function() {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
expect(text).toEqual(`<${repliesUser.nick}> "This is the real message" <- Reply Text`);
expect(text).toEqual(`${repliesUser.nick}: "This is the real message" <- Reply Text`);
}
);
const formatted_body = constructHTMLReply(
Expand Down Expand Up @@ -389,7 +389,7 @@ describe("Matrix-to-IRC message bridging", function() {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
expect(text).toEqual(`<${repliesUser.nick}> "This..." <- Reply Text`);
expect(text).toEqual(`${repliesUser.nick}: "This..." <- Reply Text`);
}
);
const formatted_body = constructHTMLReply(
Expand Down Expand Up @@ -499,7 +499,7 @@ describe("Matrix-to-IRC message bridging", function() {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
expect(text).toEqual('<M-friend> "Message #2" <- Message #3');
expect(text).toEqual('M-friend: "Message #2" <- Message #3');
}
);

Expand Down Expand Up @@ -650,7 +650,7 @@ describe("Matrix-to-IRC message bridging", function() {
});
});

it("should bridge mutliline code blocks as IRC action with URL", function(done) {
it("should bridge mutliline code blocks as a URL", function(done) {
let tBody =
"```javascript\n" +
" expect(text.indexOf(\"javascript\")).not.toEqual(-1);\n" +
Expand All @@ -662,13 +662,12 @@ describe("Matrix-to-IRC message bridging", function() {
const sdk = env.clientMock._client(config._botUserId);
sdk.uploadContent.and.returnValue(Promise.resolve("mxc://deadbeefcafe"));

env.ircMock._whenClient(roomMapping.server, testUser.nick, "action", (client, channel, text) => {
env.ircMock._whenClient(roomMapping.server, testUser.nick, "say", (client, channel, text) => {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
// don't be too brittle when checking this, but I expect to see the
// code type and the mxc fragment.
expect(text.indexOf('javascript')).not.toEqual(-1);
// mxc fragment.
expect(text.indexOf('deadbeefcafe')).not.toEqual(-1);
done();
});
Expand Down Expand Up @@ -713,18 +712,17 @@ describe("Matrix-to-IRC message bridging", function() {
});
});

it("should bridge matrix images as IRC action with a URL", function(done) {
it("should bridge matrix images as a URL", function(done) {
const tBody = "the_image.jpg";
const tMxcSegment = "/somecontentid";
const tHsUrl = "https://some.home.server.goeshere/";

env.ircMock._whenClient(roomMapping.server, testUser.nick, "action", (client, channel, text) => {
env.ircMock._whenClient(roomMapping.server, testUser.nick, "say", (client, channel, text) => {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
// don't be too brittle when checking this, but I expect to see the
// filename (body) and the http url.
expect(text.indexOf(tBody)).not.toEqual(-1);
// http url.
expect(text.indexOf(tHsUrl)).not.toEqual(-1);
expect(text.indexOf(tMxcSegment)).not.toEqual(-1);
done();
Expand All @@ -742,18 +740,17 @@ describe("Matrix-to-IRC message bridging", function() {
});
});

it("should bridge matrix files as IRC action with a URL", function(done) {
it("should bridge matrix files as a URL", function(done) {
const tBody = "a_file.apk";
const tMxcSegment = "/somecontentid";
const tHsUrl = "https://some.home.server.goeshere/";

env.ircMock._whenClient(roomMapping.server, testUser.nick, "action", (client, channel, text) => {
env.ircMock._whenClient(roomMapping.server, testUser.nick, "say", (client, channel, text) => {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
// don't be too brittle when checking this, but I expect to see the
// filename (body) and the http url.
expect(text.indexOf(tBody)).not.toEqual(-1);
// http url.
expect(text.indexOf(tHsUrl)).not.toEqual(-1);
expect(text.indexOf(tMxcSegment)).not.toEqual(-1);
done();
Expand Down Expand Up @@ -1084,21 +1081,20 @@ describe("Matrix-to-IRC message bridging with media URL and drop time", function
expect(said).toBe(true);
});

it("should bridge matrix files as IRC action with a configured media URL", function(done) {
it("should bridge matrix files as IRC message with a configured media URL", function(done) {
let tBody = "a_file.apk";
let tMxcSegment = "/somecontentid";
let tMediaUrl = mediaUrl;
let tHsUrl = "http://somedomain.com";
const sdk = env.clientMock._client(config._botUserId);

env.ircMock._whenClient(roomMapping.server, testUser.nick, "action",
env.ircMock._whenClient(roomMapping.server, testUser.nick, "say",
function(client, channel, text) {
expect(client.nick).toEqual(testUser.nick);
expect(client.addr).toEqual(roomMapping.server);
expect(channel).toEqual(roomMapping.channel);
// don't be too brittle when checking this, but I expect to see the
// filename (body) and the http url.
expect(text.indexOf(tBody)).not.toEqual(-1, "File name not present");
// http url.
expect(text.indexOf(tHsUrl)).toEqual(-1, "HS URL present instead of media URL");
expect(text.indexOf(tMediaUrl)).not.toEqual(-1, "No media URL");
expect(text.indexOf(tMxcSegment)).not.toEqual(-1, "No Mxc segment");
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/BridgedClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe("BridgedClient", function() {
expect(BridgedClient.getValidNick("f+/\u3052oobar", false, STATE_DISC)).toBe("foobar");
});
it("will ensure nicks start with a letter or special character", function() {
expect(BridgedClient.getValidNick("-foobar", false, STATE_DISC)).toBe("M-foobar");
expect(BridgedClient.getValidNick("12345", false, STATE_DISC)).toBe("M12345");
expect(BridgedClient.getValidNick("-foobar", false, STATE_DISC)).toBe("`-foobar");
expect(BridgedClient.getValidNick("12345", false, STATE_DISC)).toBe("`12345");
});
it("will throw if the nick is invalid", function() {
expect(() => BridgedClient.getValidNick("f+/\u3052oobar", true, STATE_DISC)).toThrowError();
Expand Down

0 comments on commit 2c99119

Please sign in to comment.