1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import {
formatNoteText,
isAppleAuthUrl,
looksLoggedOut,
resolveConfigPaths,
parseCreateArgv,
requireCreateContent,
isConventionalCommitSubject,
} from "../scripts/lib/note-helpers.mjs";
describe("formatNoteText", () => {
it("joins title and body with a blank line", () => {
assert.equal(formatNoteText("Hi", "body"), "Hi\n\nbody");
});
it("title only", () => {
assert.equal(formatNoteText("Hi", ""), "Hi");
});
it("body only", () => {
assert.equal(formatNoteText("", "body"), "body");
});
it("ignores nullish", () => {
assert.equal(formatNoteText(null, "x"), "x");
});
});
describe("isAppleAuthUrl / looksLoggedOut", () => {
it("detects idmsa / appleid URLs", () => {
assert.equal(isAppleAuthUrl("https://idmsa.apple.com/appleauth/auth"), true);
assert.equal(isAppleAuthUrl("https://appleid.apple.com/"), true);
assert.equal(isAppleAuthUrl("https://www.icloud.com/notes/"), false);
});
it("detects sign-in page signals", () => {
assert.equal(
looksLoggedOut({ bodyText: "Sign in to iCloud to continue" }),
true,
);
assert.equal(looksLoggedOut({ hasPasswordField: true }), true);
assert.equal(
looksLoggedOut({ hasSignInControl: true, hasNotesApp: false }),
true,
);
assert.equal(
looksLoggedOut({ hasSignInControl: true, hasNotesApp: true }),
false,
);
assert.equal(looksLoggedOut({ url: "https://www.icloud.com/notes/" }), false);
});
});
describe("resolveConfigPaths", () => {
it("uses ICLOUD_NOTES_CONFIG when set", () => {
const p = resolveConfigPaths({ ICLOUD_NOTES_CONFIG: "/tmp/icloud-test" });
assert.equal(p.configDir, "/tmp/icloud-test");
assert.equal(p.statePath, "/tmp/icloud-test/storage-state.json");
assert.equal(p.profileDir, "/tmp/icloud-test/browser-profile");
});
it("defaults under homedir/.config/icloud-notes", () => {
const p = resolveConfigPaths({}, "/home/me");
assert.equal(p.configDir, "/home/me/.config/icloud-notes");
});
});
describe("parseCreateArgv / requireCreateContent", () => {
it("parses flags", () => {
const a = parseCreateArgv(["--title", "T", "--body", "B"]);
assert.equal(a.title, "T");
assert.equal(a.body, "B");
});
it("positional title", () => {
const a = parseCreateArgv(["MyTitle"]);
assert.equal(a.title, "MyTitle");
});
it("body-file flag", () => {
const a = parseCreateArgv(["--title", "T", "--body-file", "/tmp/x"]);
assert.equal(a.bodyFile, "/tmp/x");
});
it("rejects unknown options", () => {
assert.throws(() => parseCreateArgv(["--headed"]), /Unknown option/);
});
it("requireCreateContent throws when empty", () => {
assert.throws(() => requireCreateContent("", ""), /Provide --title/);
});
it("requireCreateContent trims body trailing whitespace", () => {
const r = requireCreateContent("T", "hi\n\n");
assert.equal(r.body, "hi");
});
});
describe("isConventionalCommitSubject", () => {
it("accepts Conventional Commits subjects", () => {
assert.equal(
isConventionalCommitSubject(
"feat: add icloud.com/notes helper and agent skill",
),
true,
);
assert.equal(
isConventionalCommitSubject(
"fix: run create/status headless without a visible browser",
),
true,
);
assert.equal(isConventionalCommitSubject("feat(notes): add dry-run"), true);
assert.equal(isConventionalCommitSubject("feat!: breaking"), true);
});
it("rejects non-conventional subjects", () => {
assert.equal(isConventionalCommitSubject("Added tests"), false);
assert.equal(isConventionalCommitSubject("feat add stuff"), false);
assert.equal(isConventionalCommitSubject("FIX: caps type"), false);
});
});
|