diff options
| author | Christopher Warner <cwarner@kernelcode.com> | 2026-10-10 18:47:24 -0400 |
|---|---|---|
| committer | Christopher Warner <cwarner@kernelcode.com> | 2026-10-10 18:47:24 -0400 |
| commit | 5c61196f27b9342e5f25414c11df5710f956f406 (patch) | |
| tree | c81f15f54c9baa35f61ce3c71b81f1c1e7b5f590 /legacy/nodejs/tests/helpers.test.mjs | |
| parent | 78862ba855c6e66cac64a86c25dca6149d8fb2fd (diff) | |
| download | iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.tar.gz iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.tar.bz2 iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.tar.xz iphone-notes-5c61196f27b9342e5f25414c11df5710f956f406.zip | |
feat!: rewrite icloud-note CLI in Rust with chromiumoxide
Replace the Node/Playwright driver with a single Rust binary so create/status
stay headless without a visible browser. Move the previous implementation to
legacy/nodejs for reference.
BREAKING CHANGE: the supported CLI is the Rust `icloud-note` binary; the
Node entrypoint is no longer installed by setup.sh.
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'legacy/nodejs/tests/helpers.test.mjs')
| -rw-r--r-- | legacy/nodejs/tests/helpers.test.mjs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/legacy/nodejs/tests/helpers.test.mjs b/legacy/nodejs/tests/helpers.test.mjs new file mode 100644 index 0000000..38742d8 --- /dev/null +++ b/legacy/nodejs/tests/helpers.test.mjs @@ -0,0 +1,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); + }); +}); |
