summaryrefslogtreecommitdiff
path: root/tests/helpers.test.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers.test.mjs')
-rw-r--r--tests/helpers.test.mjs113
1 files changed, 0 insertions, 113 deletions
diff --git a/tests/helpers.test.mjs b/tests/helpers.test.mjs
deleted file mode 100644
index 38742d8..0000000
--- a/tests/helpers.test.mjs
+++ /dev/null
@@ -1,113 +0,0 @@
-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);
- });
-});