substr/tests/models/article_test.ts

84 lines
2.3 KiB
TypeScript

import { beforeAll, describe, it } from "@std/testing/bdd";
import { expect } from "@std/expect";
import Article from "../../models/article.ts";
describe("Article", () => {
let article: Article;
let deletedArticle: Article;
beforeAll(() => {
article = new Article(JSON.parse(
Deno.readTextFileSync("tests/fixtures/article-1.json"),
));
deletedArticle = new Article(JSON.parse(
Deno.readTextFileSync("tests/fixtures/article-deleted.json"),
));
});
describe("#identifier", () => {
it("returns the content of the 'd' tag", () => {
expect(article.identifier).toEqual("1726396758485");
});
});
describe("#isDraft", () => {
it("is false when kind is 30023", () => {
expect(article.isDraft).toBe(false);
});
it("is true when kind is 30024", () => {
article.event.kind = 30024;
expect(article.isDraft).toBe(true);
article.event.kind = 30023;
});
});
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("#isDeleted", () => {
it("returns a boolean based on the 'deleted' tag", () => {
expect(article.isDeleted).toEqual(false);
expect(deletedArticle.isDeleted).toEqual(true);
});
});
describe("#naddr", () => {
it("returns a bech32 addressable event ID", () => {
expect(article.naddr).toMatch(
/^naddr1qvzqqqr4gupzq8meqkx80g3yuklzymy0qf/,
);
});
});
describe("#buildContentHtml", () => {
it("returns a rendered HTML version of the 'content'", async () => {
const html = await article.buildContentHtml();
expect(html).toMatch(/<h2 id="the-solution">/);
});
});
});