WIP
This commit is contained in:
parent
0471e05ef3
commit
87792c5089
19
models/article.ts
Normal file
19
models/article.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { NEvent } from "../nostr.ts";
|
||||
import { render as renderMarkdown } from "@deno/gfm";
|
||||
|
||||
export default class Article {
|
||||
private event: NEvent;
|
||||
|
||||
constructor(event: NEvent) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
get identifier(): string | null {
|
||||
const tag = this.event.tags.find((t) => t[0] === "d");
|
||||
return tag ? tag[1] : null;
|
||||
}
|
||||
|
||||
get html(): string {
|
||||
return renderMarkdown(this.event.content);
|
||||
}
|
||||
}
|
1
tests/fixtures/article-1.json
vendored
Normal file
1
tests/fixtures/article-1.json
vendored
Normal file
File diff suppressed because one or more lines are too long
25
tests/models/article_test.ts
Normal file
25
tests/models/article_test.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
it,
|
||||
} from "@std/testing/bdd";
|
||||
import { expect } from "@std/expect";
|
||||
import { NEvent } from "../../nostr.ts";
|
||||
import Article from "../../models/article.ts";
|
||||
|
||||
describe("User", () => {
|
||||
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");
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user