A zero-year Chara period is shown as 0 years instead of failing the whole chart. Switching ephemeris dates drops the previous day immediately and can be retried. Missing birth data links to chart settings.
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import test from "node:test";
|
|
|
|
import { CHART_SETTINGS_HREF, parseSettingsQuery, stripSettingsQuery } from "../src/lib/settings-url.ts";
|
|
|
|
test("parses a billing settings query with source, plan and tab", () => {
|
|
const query = parseSettingsQuery("?settings=billing&source=legacy&plan=monthly&tab=orders");
|
|
assert.deepEqual(query, {
|
|
pane: "billing",
|
|
source: "legacy",
|
|
plan: "monthly",
|
|
tab: "orders",
|
|
});
|
|
});
|
|
|
|
test("returns null when the settings pane is absent or not billing", () => {
|
|
assert.equal(parseSettingsQuery(""), null);
|
|
assert.equal(parseSettingsQuery("?c=11111111-1111-4111-8111-111111111111"), null);
|
|
assert.equal(parseSettingsQuery("?settings=profile"), null);
|
|
});
|
|
|
|
test("ignores unknown plan and tab aliases", () => {
|
|
const query = parseSettingsQuery("?settings=billing&plan=weekly&tab=invoices&source=credits");
|
|
assert.deepEqual(query, {
|
|
pane: "billing",
|
|
source: "credits",
|
|
plan: null,
|
|
tab: null,
|
|
});
|
|
});
|
|
|
|
test("parses the chart settings deep link without changing billing", () => {
|
|
assert.deepEqual(parseSettingsQuery("?settings=chart"), {
|
|
pane: "chart",
|
|
source: null,
|
|
plan: null,
|
|
tab: null,
|
|
});
|
|
assert.equal(parseSettingsQuery("?settings=profile"), null);
|
|
assert.equal(CHART_SETTINGS_HREF, "/?settings=chart");
|
|
const page = readFileSync(new URL("../src/app/(app)/page.tsx", import.meta.url), "utf8");
|
|
assert.match(page, /query\.pane === "chart"\) openAccountDialog\("chart-library"\)/);
|
|
assert.match(page, /openAccountDialog\("billing", \{ source: query\.source \?\? undefined, plan: query\.plan \?\? undefined, tab: query\.tab \?\? undefined \}\)/);
|
|
assert.equal(stripSettingsQuery("?settings=chart"), "/");
|
|
});
|
|
|
|
test("strips settings fields and keeps the session query", () => {
|
|
assert.equal(
|
|
stripSettingsQuery("?settings=billing&source=legacy&c=11111111-1111-4111-8111-111111111111"),
|
|
"/?c=11111111-1111-4111-8111-111111111111",
|
|
);
|
|
assert.equal(stripSettingsQuery("?settings=billing&source=legacy&plan=yearly&tab=redeem"), "/");
|
|
});
|