import { beforeAll, describe, it } from "@std/testing/bdd"; import { expect } from "@std/expect"; import { replaceNostrUris } from "../../nostr/links.ts"; describe("Nostr links", () => { describe("#replaceNostrUris", () => { let mdContent: string; let result: string; beforeAll(async () => { mdContent = Deno.readTextFileSync("tests/fixtures/article-2.md"); result = await replaceNostrUris(mdContent); }); it("does not replace URIs in URLs", () => { expect(result).toMatch( new RegExp( "https://badges.page/p/npub1cpmvpsqtzxl4px44dp4544xwgu0ryv2lscl3qexq42dfakuza02s4fsapc", ), ); }); it("does not replace URIs in fenced code blocks", () => { expect(result).toMatch( new RegExp( "Follow nostr:npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7", ), ); }); it("does not replace URIs in inline code blocks", () => { expect(result).toMatch( new RegExp( "raucao: nostr:npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees", ), ); }); describe("for unknown usernames", () => { it("replaces plain nostr:id URIs with a markdown link", () => { expect(result).toMatch( /Amber scheme 1\: \[npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\]\(https\:\/\/njump\.me\/npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\)/, ); expect(result).toMatch( /Amber scheme 2\: \[npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\]\(https\:\/\/njump\.me\/npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\)/, ); }); it("replaces @id URIs with a markdown link", () => { expect(result).toMatch( /Amber at 1\: \[@npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\]\(https\:\/\/njump\.me\/npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\)/, ); expect(result).toMatch( /Amber at 2\: \[@npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\]\(https\:\/\/njump\.me\/npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\)/, ); }); it("replaces nostr links with external links", () => { expect(result).toMatch( /Amber scheme link 1\: \[Amber\]\(https\:\/\/njump\.me\/npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\)/, ); expect(result).toMatch( /Amber scheme link 2\: \[Amber\]\(https\:\/\/njump\.me\/npub1am3ermkr250dywukzqnaug64cred3x5jht6f3kdhfp3h0rgtjlpqecxrv7\)/, ); }); }); describe("for known usernames", () => { it("replaces plain nostr:id URIs with a markdown link", () => { expect(result).toMatch( /raucao scheme 1\: \[npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees\]\(\/@raucao\)/, ); expect(result).toMatch( /raucao scheme 2\: \[npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees\]\(\/@raucao\)/, ); }); it("replaces @id URIs with a markdown link", () => { expect(result).toMatch( /raucao at 1\: \[@npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees\]\(\/@raucao\)/, ); expect(result).toMatch( /raucao at 2\: \[@npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees\]\(\/@raucao\)/, ); }); it("replaces scheme links with internal links", () => { expect(result).toMatch( /raucao scheme link 1\: \[raucao\]\(\/@raucao\)/, ); expect(result).toMatch( /raucao scheme link 2\: \[raucao\]\(\/@raucao\)/, ); }); }); }); });