MVP
This commit is contained in:
19
tests/dates_test.ts
Normal file
19
tests/dates_test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, it } from "@std/testing/bdd";
|
||||
import { expect } from "@std/expect";
|
||||
import { localizeDate } from "../dates.ts";
|
||||
|
||||
describe("Dates", () => {
|
||||
describe("#localizeDate", () => {
|
||||
it("returns a human-readable date for timestamp", () => {
|
||||
const date = localizeDate(1726402055);
|
||||
expect(date).toEqual("September 15, 2024");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#isoDate", () => {
|
||||
it("returns an ISO 8601 date for the timestamp", () => {
|
||||
const date = localizeDate(1726402055);
|
||||
expect(date).toEqual("September 15, 2024");
|
||||
});
|
||||
});
|
||||
});
|
||||
30
tests/fixtures/article-1.json
vendored
30
tests/fixtures/article-1.json
vendored
File diff suppressed because one or more lines are too long
9
tests/fixtures/profile-1.json
vendored
Normal file
9
tests/fixtures/profile-1.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"content": "{\"name\":\"Râu Cao ⚡\",\"nip05\":\"raucao@kosmos.org\",\"about\":\"Traveling full-time since 2010. Working on open-source software daily. Currently integrating Nostr features into Kosmos accounts.\",\"picture\":\"https://storage.kosmos.org/raucao/public/shares/240604-1441-fuerte-256.png\",\"lud16\":\"raucao@kosmos.org\",\"banner\":\"https://storage.kosmos.org/raucao/public/shares/240604-1517-1500x500.jpg\"}",
|
||||
"created_at": 1728814592,
|
||||
"id": "d437964cdd87f4b5bd595f47c2c64f4ba02c849ca215ed56fcb5fd3335ae2720",
|
||||
"kind": 0,
|
||||
"pubkey": "1f79058c77a224e5be226c8f024cacdad4d741855d75ed9f11473ba8eb86e1cb",
|
||||
"sig": "ee067f88344fa8380a16154b7d988087c41d6c87ae720dd52947a38e63232ab6998de37f28e8c7115a0604fc184035af543ad354ed7b616b8ba29974653042cc",
|
||||
"tags": []
|
||||
}
|
||||
@@ -1,19 +1,16 @@
|
||||
import {
|
||||
beforeAll,
|
||||
beforeEach,
|
||||
describe,
|
||||
it,
|
||||
} from "@std/testing/bdd";
|
||||
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("User", () => {
|
||||
describe("Article", () => {
|
||||
let articleEvent: NEvent;
|
||||
let article: Article;
|
||||
|
||||
beforeAll(() => {
|
||||
articleEvent = JSON.parse(Deno.readTextFileSync("tests/fixtures/article-1.json"));
|
||||
articleEvent = JSON.parse(
|
||||
Deno.readTextFileSync("tests/fixtures/article-1.json"),
|
||||
);
|
||||
article = new Article(articleEvent);
|
||||
});
|
||||
|
||||
@@ -22,4 +19,44 @@ describe("User", () => {
|
||||
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",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
43
tests/models/profile_test.ts
Normal file
43
tests/models/profile_test.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { beforeAll, describe, it } from "@std/testing/bdd";
|
||||
import { expect } from "@std/expect";
|
||||
import { NEvent } from "../../nostr.ts";
|
||||
import Profile from "../../models/profile.ts";
|
||||
|
||||
describe("Profile", () => {
|
||||
let profileEvent: NEvent;
|
||||
let profile: Profile;
|
||||
|
||||
beforeAll(() => {
|
||||
profileEvent = JSON.parse(
|
||||
Deno.readTextFileSync("tests/fixtures/profile-1.json"),
|
||||
);
|
||||
profile = new Profile(profileEvent);
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
it("instantiates the username when given", () => {
|
||||
profile = new Profile(profileEvent, "raucao");
|
||||
expect(profile.username).toEqual("raucao");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#updatedAt", () => {
|
||||
it("returns the value of the profile event's 'created_at'", () => {
|
||||
expect(profile.updatedAt).toEqual(1728814592);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#name", () => {
|
||||
it("returns the profile's name when present", () => {
|
||||
expect(profile.name).toEqual("Râu Cao ⚡");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#npub", () => {
|
||||
it("returns the bech32-encoded version of the pubkey", () => {
|
||||
expect(profile.npub).toEqual(
|
||||
"npub1raustrrh5gjwt03zdj8syn9vmt2dwsv9t467m8c3gua636uxu89svgdees",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user