learn and share notes on atproto (wip) 馃
malfestio.stormlightlabs.org/
readability
solid
axum
atproto
srs
1import { describe, expect, it } from "vitest";
2import { asCard, asDeck, asNote, type Persona, type SearchResult, type UserPreferences } from "../model";
3
4describe("Type Guards", () => {
5 const deckResult: SearchResult = {
6 item_type: "deck",
7 item_id: "deck1",
8 creator_did: "did:test",
9 data: {
10 id: "deck1",
11 owner_did: "did:test",
12 title: "Test Deck",
13 description: "Description",
14 tags: [],
15 visibility: { type: "Public" },
16 },
17 rank: 1,
18 };
19
20 const cardResult: SearchResult = {
21 item_type: "card",
22 item_id: "card1",
23 creator_did: "did:test",
24 data: { front: "Front", back: "Back", deck_id: "deck1" },
25 rank: 1,
26 };
27
28 const noteResult: SearchResult = {
29 item_type: "note",
30 item_id: "note1",
31 creator_did: "did:test",
32 data: { id: "note1", title: "Test Note", owner_did: "did:test" },
33 rank: 1,
34 };
35
36 it("asDeck correctly identifies decks", () => {
37 expect(asDeck(deckResult)).toBe(deckResult);
38 expect(asDeck(cardResult)).toBeUndefined();
39 expect(asDeck(noteResult)).toBeUndefined();
40 });
41
42 it("asCard correctly identifies cards", () => {
43 expect(asCard(cardResult)).toBe(cardResult);
44 expect(asCard(deckResult)).toBeUndefined();
45 expect(asCard(noteResult)).toBeUndefined();
46 });
47
48 it("asNote correctly identifies notes", () => {
49 expect(asNote(noteResult)).toBe(noteResult);
50 expect(asNote(deckResult)).toBeUndefined();
51 expect(asNote(cardResult)).toBeUndefined();
52 });
53});
54
55describe("Persona Types", () => {
56 it("accepts valid persona values", () => {
57 const learner: Persona = "learner";
58 const creator: Persona = "creator";
59 const curator: Persona = "curator";
60
61 expect(learner).toBe("learner");
62 expect(creator).toBe("creator");
63 expect(curator).toBe("curator");
64 });
65});
66
67describe("UserPreferences Types", () => {
68 it("accepts valid user preferences object", () => {
69 const prefs: UserPreferences = {
70 user_did: "did:plc:test",
71 persona: "learner",
72 onboarding_completed_at: "2024-01-01T00:00:00Z",
73 tutorial_deck_completed: false,
74 density_mode: "comfortable",
75 };
76
77 expect(prefs.user_did).toBe("did:plc:test");
78 expect(prefs.persona).toBe("learner");
79 expect(prefs.onboarding_completed_at).toBe("2024-01-01T00:00:00Z");
80 expect(prefs.tutorial_deck_completed).toBe(false);
81 });
82
83 it("accepts null values for optional fields", () => {
84 const prefs: UserPreferences = {
85 user_did: "did:plc:test",
86 persona: null,
87 onboarding_completed_at: null,
88 tutorial_deck_completed: false,
89 density_mode: null,
90 };
91
92 expect(prefs.persona).toBeNull();
93 expect(prefs.onboarding_completed_at).toBeNull();
94 });
95});