Display search property alongside host in relay name (#452)

This commit is contained in:
heyhoe
2023-03-23 22:25:07 +09:00
committed by GitHub
parent d5f828ffb8
commit e95f1fe369
4 changed files with 30 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { splitByUrl, magnetURIDecode } from "./Util";
import { splitByUrl, magnetURIDecode, getRelayName } from "./Util";
describe("splitByUrl", () => {
it("should split a string by URLs", () => {
@ -56,3 +56,22 @@ describe("magnet", () => {
]);
});
});
describe("getRelayName", () => {
it("should return relay name", () => {
const url = "wss://relay.snort.social/";
const output = getRelayName(url);
expect(output).toEqual("relay.snort.social");
});
it("should return relay name with search property", () => {
const url = "wss://relay.example1.com/?lang=en";
const output = getRelayName(url);
expect(output).toEqual("relay.example1.com?lang=en");
});
it("should return relay name without pathname", () => {
const url =
"wss://relay.example2.com/npub1sn0rtcjcf543gj4wsg7fa59s700d5ztys5ctj0g69g2x6802npjqhjjtws?broadcast=true";
const output = getRelayName(url);
expect(output).toEqual("relay.example2.com?broadcast=true");
});
});