A 401 for the current person was stored, then hidden because the subject stamp only happened on success. Session, report, and birth contracts now follow the subject query and the shared birth lookup. Admin reset fixtures can no longer insert a retired self mirror.
100 lines
3.7 KiB
TypeScript
100 lines
3.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { readFileSync } from "node:fs";
|
|
import {
|
|
ACCOUNT_BIRTH_SELECT,
|
|
globalBirthProfileFromAccountRow,
|
|
globalBirthProfileFromStoredChart,
|
|
} from "../src/lib/server-owned-birth-profile.ts";
|
|
|
|
test("accepted account rows use the server active minute, not a reported leftover", () => {
|
|
const profile = globalBirthProfileFromAccountRow({
|
|
name: "测试",
|
|
birth_date: "1990-06-15",
|
|
reported_birth_time: "08:00:00",
|
|
active_birth_time: "09:15:00",
|
|
birth_time_status: "accepted",
|
|
country_code: "CN",
|
|
province_code: "310000",
|
|
city_code: "310100",
|
|
latitude: 31.2,
|
|
longitude: 121.5,
|
|
timezone_offset: 8,
|
|
timezone_id: "Asia/Shanghai",
|
|
});
|
|
|
|
assert.equal(profile.date, "1990-06-15");
|
|
assert.equal(profile.time, "09:15");
|
|
assert.equal(profile.timezoneId, "Asia/Shanghai");
|
|
assert.equal(profile.birthTimeStatus, "accepted");
|
|
});
|
|
|
|
test("reported rows keep the declared clock until an active minute exists", () => {
|
|
const profile = globalBirthProfileFromAccountRow({
|
|
birth_date: new Date("1991-01-02T00:00:00.000Z"),
|
|
reported_birth_time: "07:40",
|
|
active_birth_time: null,
|
|
birth_time_status: "reported",
|
|
});
|
|
|
|
assert.equal(profile.date, "1991-01-02");
|
|
assert.equal(profile.time, "07:40");
|
|
});
|
|
|
|
test("stored other-chart JSON keeps the library camelCase shape", () => {
|
|
const profile = globalBirthProfileFromStoredChart({
|
|
name: "对方",
|
|
date: "1988-03-04",
|
|
time: "18:20",
|
|
reportedTime: "18:20",
|
|
countryCode: "CN",
|
|
provinceCode: "110000",
|
|
cityCode: "110100",
|
|
latitude: 39.9,
|
|
longitude: 116.4,
|
|
timezoneOffset: 8,
|
|
timezoneId: "Asia/Shanghai",
|
|
});
|
|
|
|
assert.deepEqual(profile, {
|
|
name: "对方",
|
|
date: "1988-03-04",
|
|
time: "18:20",
|
|
countryCode: "CN",
|
|
provinceCode: "110000",
|
|
cityCode: "110100",
|
|
districtCode: undefined,
|
|
latitude: 39.9,
|
|
longitude: 116.4,
|
|
timezoneOffset: 8,
|
|
timezoneId: "Asia/Shanghai",
|
|
ayanamsa: "raman",
|
|
birthTimeStatus: undefined,
|
|
});
|
|
});
|
|
|
|
test("a stored chart without a clock cannot be used for synastry", () => {
|
|
assert.equal(globalBirthProfileFromStoredChart({ date: "1990-01-01", name: "对方" }), null);
|
|
assert.equal(globalBirthProfileFromStoredChart(null), null);
|
|
});
|
|
|
|
test("daily and synastry routes share a literal account-birth select string", () => {
|
|
const daily = readFileSync(new URL("../src/app/api/daily-starlanguage/route.ts", import.meta.url), "utf8");
|
|
const synastry = readFileSync(new URL("../src/app/api/synastry/route.ts", import.meta.url), "utf8");
|
|
assert.equal(
|
|
ACCOUNT_BIRTH_SELECT,
|
|
"name,birth_date,active_birth_date,active_birth_timezone_offset,active_birth_provenance,reported_birth_time,active_birth_time,birth_time,birth_time_status,birth_time_source,country_code,province_code,city_code,district_code,latitude,longitude,timezone_offset,timezone_id,ayanamsa,birth_place_label,uncertainty_before_minutes,uncertainty_after_minutes,declared_window_start,declared_window_end",
|
|
);
|
|
// 原值: the daily route selected ACCOUNT_BIRTH_SELECT inline.
|
|
// 新值: subject-birth.ts selects it; the daily route calls loadSubjectBirth.
|
|
// 原因: birth lookup is no longer copied into each route.
|
|
const subjectBirth = readFileSync(new URL("../src/lib/subject-birth.ts", import.meta.url), "utf8");
|
|
assert.match(subjectBirth, /select\(ACCOUNT_BIRTH_SELECT\)/);
|
|
assert.match(daily, /loadSubjectBirth/);
|
|
assert.match(synastry, /loadSubjectBirth/);
|
|
assert.doesNotMatch(daily, /accountBirthColumns/);
|
|
assert.doesNotMatch(synastry, /accountBirthColumns/);
|
|
assert.doesNotMatch(daily, /\.join\(",\"\)/);
|
|
assert.doesNotMatch(synastry, /\.join\(",\"\)/);
|
|
});
|