Skip to content

Commit 7d6dce5

Browse files
fix: update note persister tests to use frontmatter-batch operations (#2804)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: yujonglee <[email protected]>
1 parent d5fdd78 commit 7d6dce5

File tree

1 file changed

+73
-25
lines changed

1 file changed

+73
-25
lines changed

apps/desktop/src/store/tinybase/persister/note/persister.test.ts

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,32 @@ vi.mock("@hypr/plugin-path2", () => ({
1111
},
1212
}));
1313

14+
vi.mock("@tauri-apps/api/path", () => ({
15+
sep: vi.fn().mockReturnValue("/"),
16+
}));
17+
1418
vi.mock("@tauri-apps/plugin-fs", () => ({
1519
exists: vi.fn().mockResolvedValue(true),
1620
mkdir: vi.fn().mockResolvedValue(undefined),
1721
}));
1822

19-
vi.mock("@hypr/plugin-export", () => ({
23+
vi.mock("@hypr/plugin-frontmatter", () => ({
2024
commands: {
21-
exportTiptapJsonToMdBatch: vi
22-
.fn()
23-
.mockResolvedValue({ status: "ok", data: null }),
25+
serializeBatch: vi.fn().mockResolvedValue({ status: "ok", data: null }),
2426
},
2527
}));
2628

29+
vi.mock("@hypr/tiptap/shared", () => ({
30+
isValidTiptapContent: vi.fn((content: unknown) => {
31+
if (!content || typeof content !== "object") {
32+
return false;
33+
}
34+
const obj = content as Record<string, unknown>;
35+
return obj.type === "doc" && Array.isArray(obj.content);
36+
}),
37+
json2md: vi.fn().mockReturnValue("mock markdown content"),
38+
}));
39+
2740
function createTestStore() {
2841
return createMergeableStore()
2942
.setTablesSchema(SCHEMA.table)
@@ -56,7 +69,8 @@ describe("createNotePersister", () => {
5669

5770
describe("save", () => {
5871
test("exports enhanced_note to markdown file", async () => {
59-
const { commands } = await import("@hypr/plugin-export");
72+
const { commands: frontmatterCommands } =
73+
await import("@hypr/plugin-frontmatter");
6074

6175
const noteId = "note-1";
6276
store.setRow("enhanced_notes", noteId, {
@@ -79,17 +93,28 @@ describe("createNotePersister", () => {
7993

8094
await persister.save();
8195

82-
expect(commands.exportTiptapJsonToMdBatch).toHaveBeenCalledTimes(1);
83-
expect(commands.exportTiptapJsonToMdBatch).toHaveBeenCalledWith([
96+
expect(frontmatterCommands.serializeBatch).toHaveBeenCalledTimes(1);
97+
expect(frontmatterCommands.serializeBatch).toHaveBeenCalledWith([
8498
[
85-
{ type: "doc", content: [{ type: "paragraph" }] },
99+
{
100+
frontmatter: {
101+
id: noteId,
102+
session_id: "session-1",
103+
type: "enhanced_note",
104+
template_id: "template-1",
105+
position: 0,
106+
title: undefined,
107+
},
108+
content: "mock markdown content",
109+
},
86110
"/mock/data/dir/hyprnote/sessions/session-1/My Template.md",
87111
],
88112
]);
89113
});
90114

91115
test("uses _summary.md when no template_id", async () => {
92-
const { commands } = await import("@hypr/plugin-export");
116+
const { commands: frontmatterCommands } =
117+
await import("@hypr/plugin-frontmatter");
93118

94119
store.setRow("enhanced_notes", "note-1", {
95120
user_id: "user-1",
@@ -103,16 +128,27 @@ describe("createNotePersister", () => {
103128

104129
await persister.save();
105130

106-
expect(commands.exportTiptapJsonToMdBatch).toHaveBeenCalledWith([
131+
expect(frontmatterCommands.serializeBatch).toHaveBeenCalledWith([
107132
[
108-
{ type: "doc", content: [{ type: "paragraph" }] },
133+
{
134+
frontmatter: {
135+
id: "note-1",
136+
session_id: "session-1",
137+
type: "enhanced_note",
138+
template_id: undefined,
139+
position: 0,
140+
title: undefined,
141+
},
142+
content: "mock markdown content",
143+
},
109144
"/mock/data/dir/hyprnote/sessions/session-1/_summary.md",
110145
],
111146
]);
112147
});
113148

114149
test("sanitizes template title for filename", async () => {
115-
const { commands } = await import("@hypr/plugin-export");
150+
const { commands: frontmatterCommands } =
151+
await import("@hypr/plugin-frontmatter");
116152

117153
store.setRow("enhanced_notes", "note-1", {
118154
user_id: "user-1",
@@ -134,7 +170,7 @@ describe("createNotePersister", () => {
134170

135171
await persister.save();
136172

137-
expect(commands.exportTiptapJsonToMdBatch).toHaveBeenCalledWith([
173+
expect(frontmatterCommands.serializeBatch).toHaveBeenCalledWith([
138174
[
139175
expect.any(Object),
140176
"/mock/data/dir/hyprnote/sessions/session-1/My_________Template.md",
@@ -143,7 +179,8 @@ describe("createNotePersister", () => {
143179
});
144180

145181
test("falls back to template_id when template title is not found", async () => {
146-
const { commands } = await import("@hypr/plugin-export");
182+
const { commands: frontmatterCommands } =
183+
await import("@hypr/plugin-frontmatter");
147184

148185
store.setRow("enhanced_notes", "note-1", {
149186
user_id: "user-1",
@@ -158,7 +195,7 @@ describe("createNotePersister", () => {
158195

159196
await persister.save();
160197

161-
expect(commands.exportTiptapJsonToMdBatch).toHaveBeenCalledWith([
198+
expect(frontmatterCommands.serializeBatch).toHaveBeenCalledWith([
162199
[
163200
expect.any(Object),
164201
"/mock/data/dir/hyprnote/sessions/session-1/unknown-template-id.md",
@@ -167,7 +204,8 @@ describe("createNotePersister", () => {
167204
});
168205

169206
test("handles multiple enhanced_notes", async () => {
170-
const { commands } = await import("@hypr/plugin-export");
207+
const { commands: frontmatterCommands } =
208+
await import("@hypr/plugin-frontmatter");
171209

172210
store.setRow("enhanced_notes", "note-1", {
173211
user_id: "user-1",
@@ -196,14 +234,15 @@ describe("createNotePersister", () => {
196234

197235
await persister.save();
198236

199-
expect(commands.exportTiptapJsonToMdBatch).toHaveBeenCalledTimes(1);
200-
const callArgs = vi.mocked(commands.exportTiptapJsonToMdBatch).mock
237+
expect(frontmatterCommands.serializeBatch).toHaveBeenCalledTimes(1);
238+
const callArgs = vi.mocked(frontmatterCommands.serializeBatch).mock
201239
.calls[0][0];
202240
expect(callArgs).toHaveLength(2);
203241
});
204242

205243
test("exports raw_md for sessions", async () => {
206-
const { commands } = await import("@hypr/plugin-export");
244+
const { commands: frontmatterCommands } =
245+
await import("@hypr/plugin-frontmatter");
207246

208247
store.setRow("sessions", "session-1", {
209248
user_id: "user-1",
@@ -216,16 +255,24 @@ describe("createNotePersister", () => {
216255

217256
await persister.save();
218257

219-
expect(commands.exportTiptapJsonToMdBatch).toHaveBeenCalledWith([
258+
expect(frontmatterCommands.serializeBatch).toHaveBeenCalledWith([
220259
[
221-
{ type: "doc", content: [{ type: "paragraph" }] },
260+
{
261+
frontmatter: {
262+
id: "session-1",
263+
session_id: "session-1",
264+
type: "memo",
265+
},
266+
content: "mock markdown content",
267+
},
222268
"/mock/data/dir/hyprnote/sessions/session-1/_memo.md",
223269
],
224270
]);
225271
});
226272

227273
test("does not export raw_md when raw_md is empty", async () => {
228-
const { commands } = await import("@hypr/plugin-export");
274+
const { commands: frontmatterCommands } =
275+
await import("@hypr/plugin-frontmatter");
229276

230277
store.setRow("sessions", "session-1", {
231278
user_id: "user-1",
@@ -238,7 +285,7 @@ describe("createNotePersister", () => {
238285

239286
await persister.save();
240287

241-
expect(commands.exportTiptapJsonToMdBatch).not.toHaveBeenCalled();
288+
expect(frontmatterCommands.serializeBatch).not.toHaveBeenCalled();
242289
});
243290

244291
test("creates directory if it does not exist", async () => {
@@ -264,7 +311,8 @@ describe("createNotePersister", () => {
264311
});
265312

266313
test("skips when content is not valid tiptap json", async () => {
267-
const { commands } = await import("@hypr/plugin-export");
314+
const { commands: frontmatterCommands } =
315+
await import("@hypr/plugin-frontmatter");
268316

269317
store.setRow("enhanced_notes", "note-1", {
270318
user_id: "user-1",
@@ -278,7 +326,7 @@ describe("createNotePersister", () => {
278326

279327
await persister.save();
280328

281-
expect(commands.exportTiptapJsonToMdBatch).not.toHaveBeenCalled();
329+
expect(frontmatterCommands.serializeBatch).not.toHaveBeenCalled();
282330
});
283331
});
284332
});

0 commit comments

Comments
 (0)