|
| 1 | +import fsp from "node:fs/promises" |
| 2 | +import os from "node:os" |
| 3 | + |
| 4 | +import type { IpcContext } from "electron-ipc-decorator" |
| 5 | +import path from "pathe" |
| 6 | +import { afterEach, describe, expect, it, vi } from "vitest" |
| 7 | + |
| 8 | +import { IntegrationService } from "./integration" |
| 9 | + |
| 10 | +vi.mock("electron", () => ({ |
| 11 | + ipcMain: { |
| 12 | + handle: vi.fn(), |
| 13 | + }, |
| 14 | + shell: { |
| 15 | + openExternal: vi.fn(), |
| 16 | + }, |
| 17 | +})) |
| 18 | + |
| 19 | +vi.mock("electron-ipc-decorator", () => ({ |
| 20 | + IpcMethod: () => (_target: unknown, _propertyKey: string, descriptor: PropertyDescriptor) => |
| 21 | + descriptor, |
| 22 | + IpcService: class {}, |
| 23 | +})) |
| 24 | + |
| 25 | +vi.mock("~/lib/store", () => ({ |
| 26 | + store: { |
| 27 | + get: vi.fn(), |
| 28 | + set: vi.fn(), |
| 29 | + }, |
| 30 | +})) |
| 31 | + |
| 32 | +vi.mock("~/logger", () => ({ |
| 33 | + logger: { |
| 34 | + debug: vi.fn(), |
| 35 | + error: vi.fn(), |
| 36 | + info: vi.fn(), |
| 37 | + warn: vi.fn(), |
| 38 | + }, |
| 39 | +})) |
| 40 | + |
| 41 | +describe("IntegrationService", () => { |
| 42 | + let vaultPath: string | undefined |
| 43 | + |
| 44 | + afterEach(async () => { |
| 45 | + if (!vaultPath) return |
| 46 | + |
| 47 | + await fsp.rm(vaultPath, { force: true, recursive: true }) |
| 48 | + vaultPath = undefined |
| 49 | + }) |
| 50 | + |
| 51 | + it("saves Obsidian titles with path separators as one markdown file", async () => { |
| 52 | + vaultPath = await fsp.mkdtemp(path.join(os.tmpdir(), "folo-obsidian-")) |
| 53 | + const service = new IntegrationService() |
| 54 | + const context = {} as IpcContext |
| 55 | + |
| 56 | + await expect( |
| 57 | + service.saveToObsidian(context, { |
| 58 | + url: "https://example.com", |
| 59 | + title: "KAWA DESIGN 少女前线2:追放 索米·雪兔献礼 1/6比例手办", |
| 60 | + content: "content", |
| 61 | + author: "Folo", |
| 62 | + publishedAt: "2026-05-14T04:20:44.405Z", |
| 63 | + vaultPath, |
| 64 | + }), |
| 65 | + ).resolves.toEqual({ success: true }) |
| 66 | + |
| 67 | + await expect(fsp.readdir(vaultPath)).resolves.toEqual([ |
| 68 | + "KAWA DESIGN 少女前线2:追放 索米·雪兔献礼 1_6比例手办.md", |
| 69 | + ]) |
| 70 | + await expect( |
| 71 | + fsp.stat(path.join(vaultPath, "KAWA DESIGN 少女前线2:追放 索米·雪兔献礼 1")), |
| 72 | + ).rejects.toThrow() |
| 73 | + }) |
| 74 | +}) |
0 commit comments