2022-06-19 00:25:21 +00:00
|
|
|
import {expect} from "chai";
|
|
|
|
import parseIrcUri from "../../../../client/js/helpers/parseIrcUri";
|
2019-11-23 22:45:04 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
describe("parseIrcUri helper", function () {
|
|
|
|
it("should parse irc:// without port", function () {
|
2019-11-23 22:45:04 +00:00
|
|
|
expect(parseIrcUri("irc://example.com")).to.deep.equal({
|
|
|
|
tls: false,
|
|
|
|
name: "example.com",
|
|
|
|
host: "example.com",
|
|
|
|
port: "6667",
|
|
|
|
join: "",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should parse ircs:// without port", function () {
|
2019-11-23 22:45:04 +00:00
|
|
|
expect(parseIrcUri("ircs://example.com")).to.deep.equal({
|
|
|
|
tls: true,
|
|
|
|
name: "example.com",
|
|
|
|
host: "example.com",
|
|
|
|
port: "6697",
|
|
|
|
join: "",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should parse irc:// with port", function () {
|
2019-11-23 22:45:04 +00:00
|
|
|
expect(parseIrcUri("irc://example.com:1337")).to.deep.equal({
|
|
|
|
tls: false,
|
|
|
|
name: "example.com",
|
|
|
|
host: "example.com",
|
|
|
|
port: "1337",
|
|
|
|
join: "",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should parse ircs:// with port", function () {
|
2019-11-23 22:45:04 +00:00
|
|
|
expect(parseIrcUri("ircs://example.com:1337")).to.deep.equal({
|
|
|
|
tls: true,
|
|
|
|
name: "example.com",
|
|
|
|
host: "example.com",
|
|
|
|
port: "1337",
|
|
|
|
join: "",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not parse invalid port", function () {
|
2019-11-24 09:37:25 +00:00
|
|
|
expect(parseIrcUri("ircs://example.com:lol")).to.deep.equal({});
|
2019-11-23 22:45:04 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not parse plus in port", function () {
|
2019-11-24 09:37:25 +00:00
|
|
|
expect(parseIrcUri("irc://example.com:+6697")).to.deep.equal({});
|
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should not channel on empty query and hash", function () {
|
2019-11-24 09:37:25 +00:00
|
|
|
const obj = {
|
|
|
|
tls: false,
|
2019-11-23 22:45:04 +00:00
|
|
|
name: "example.com",
|
|
|
|
host: "example.com",
|
2019-11-24 09:37:25 +00:00
|
|
|
port: "6667",
|
|
|
|
join: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(parseIrcUri("irc://example.com#")).to.deep.equal(obj);
|
|
|
|
expect(parseIrcUri("irc://example.com/")).to.deep.equal(obj);
|
|
|
|
expect(parseIrcUri("irc://example.com/#")).to.deep.equal(obj);
|
2019-11-23 22:45:04 +00:00
|
|
|
});
|
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
it("should parse multiple channels", function () {
|
2019-11-23 22:45:04 +00:00
|
|
|
const obj = {
|
|
|
|
tls: true,
|
|
|
|
name: "example.com",
|
|
|
|
host: "example.com",
|
|
|
|
port: "1337",
|
2019-11-24 09:37:25 +00:00
|
|
|
join: "#channel,channel2",
|
2019-11-23 22:45:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(parseIrcUri("ircs://example.com:1337#channel,channel2")).to.deep.equal(obj);
|
|
|
|
expect(parseIrcUri("ircs://example.com:1337/#channel,channel2")).to.deep.equal(obj);
|
|
|
|
|
2019-11-24 09:37:25 +00:00
|
|
|
obj.join = "channel,channel2";
|
|
|
|
expect(parseIrcUri("ircs://example.com:1337/channel,channel2")).to.deep.equal(obj);
|
2019-11-23 22:45:04 +00:00
|
|
|
|
2019-11-24 09:37:25 +00:00
|
|
|
obj.join = "chan,#chan2,#chan3";
|
|
|
|
expect(parseIrcUri("ircs://example.com:1337/chan,#chan2,#chan3")).to.deep.equal(obj);
|
2019-11-23 22:45:04 +00:00
|
|
|
|
2019-11-24 09:37:25 +00:00
|
|
|
obj.join = "&chan,@chan2,#chan3";
|
|
|
|
expect(parseIrcUri("ircs://example.com:1337/&chan,@chan2,#chan3")).to.deep.equal(obj);
|
|
|
|
|
|
|
|
// URL() drops empty hash
|
|
|
|
obj.join = "chan";
|
|
|
|
expect(parseIrcUri("ircs://example.com:1337/chan#")).to.deep.equal(obj);
|
2019-11-23 22:45:04 +00:00
|
|
|
});
|
|
|
|
});
|