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", 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,reported_birth_time,active_birth_time,birth_time,birth_time_status,country_code,province_code,city_code,district_code,latitude,longitude,timezone_offset,timezone_id", ); assert.match(daily, /select\(ACCOUNT_BIRTH_SELECT\)/); assert.match(synastry, /select\(ACCOUNT_BIRTH_SELECT\)/); assert.doesNotMatch(daily, /accountBirthColumns/); assert.doesNotMatch(synastry, /accountBirthColumns/); assert.doesNotMatch(daily, /\.join\(",\"\)/); assert.doesNotMatch(synastry, /\.join\(",\"\)/); });