c38f11dbd3
Stop accepting client-supplied birth data on those paths, and cap session writes plus location lookups so a logged-in caller cannot farm compute. Co-authored-by: Cursor <cursoragent@cursor.com>
77 lines
2.2 KiB
TypeScript
77 lines
2.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import {
|
|
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",
|
|
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);
|
|
});
|