substr/tests/models/article_test.ts
2024-10-21 15:43:58 +02:00

63 lines
1.7 KiB
TypeScript

import { beforeAll, describe, it } from "@std/testing/bdd";
import { expect } from "@std/expect";
import { NEvent } from "../../nostr.ts";
import Article from "../../models/article.ts";
describe("Article", () => {
let articleEvent: NEvent;
let article: Article;
beforeAll(() => {
articleEvent = JSON.parse(
Deno.readTextFileSync("tests/fixtures/article-1.json"),
);
article = new Article(articleEvent);
});
describe("#identifier", () => {
it("returns the content of the 'd' tag", () => {
expect(article.identifier).toEqual("1726396758485");
});
});
describe("#title", () => {
it("returns the content of the 'title' tag", () => {
expect(article.title).toMatch(
/How to confirm a stuck Lightning channel closing transaction/,
);
});
});
describe("#summary", () => {
it("returns the content of the 'summary' tag", () => {
expect(article.summary).toEqual("");
});
});
describe("#publishedAt", () => {
it("returns the value of the first 'published_at' tag", () => {
expect(article.publishedAt).toEqual(1726402055);
});
});
describe("#updatedAt", () => {
it("returns the value of the first 'published_at' tag", () => {
expect(article.updatedAt).toEqual(1729462158);
});
});
describe("#html", () => {
it("returns a rendered HTML version of the 'content'", () => {
expect(article.html).toMatch(/<h2 id="the-solution">/);
});
});
describe("#naddr", () => {
it("returns bech32 addressable event ID", () => {
expect(article.naddr).toEqual(
"naddr1qvzqqqr4gupzq8meqkx80g3yuklzymy0qfx2ekk56aqc2ht4ak03z3em4r4cdcwtqqxnzdejxcenjd3hx5urgwp4676hkz",
);
});
});
});