fix(rectification): resolve missing birth timezone offsets
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
import { createHash } from "node:crypto";
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
import { resolveMissingBirthTimezoneOffset } from "../../birth-profile-timezone.ts";
|
||||
import { normalizePersistedBirthDate } from "../../birth-time-intake-model.ts";
|
||||
import {
|
||||
resolveActiveSkillPackage,
|
||||
@@ -180,7 +181,13 @@ export async function loadV9RectificationProfile(
|
||||
.single();
|
||||
if (error || !data) throw new RectificationCaseServiceError("profile_unavailable");
|
||||
|
||||
const row = data as Record<string, unknown>;
|
||||
let resolvedData: unknown;
|
||||
try {
|
||||
resolvedData = await resolveMissingBirthTimezoneOffset(data);
|
||||
} catch {
|
||||
throw new RectificationCaseServiceError("profile_unavailable");
|
||||
}
|
||||
const row = resolvedData as Record<string, unknown>;
|
||||
const birthDate = normalizePersistedBirthDate(row.birth_date);
|
||||
const latitude = numberOrNull(row.latitude);
|
||||
const longitude = numberOrNull(row.longitude);
|
||||
|
||||
@@ -168,6 +168,68 @@ test("period-only profiles open with their selected server-owned range", async (
|
||||
}
|
||||
});
|
||||
|
||||
test("period-only profiles with an IANA timezone can open when the cached offset is missing", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
const capturedArgs: { value: Record<string, unknown> | null } = { value: null };
|
||||
let timezoneLookupCalled = false;
|
||||
globalThis.fetch = async (input, init) => {
|
||||
timezoneLookupCalled = true;
|
||||
assert.equal(String(input), "http://127.0.0.1:5200/api/location/timezone");
|
||||
assert.deepEqual(JSON.parse(String(init?.body)), {
|
||||
latitude: 36.420487,
|
||||
longitude: 114.209936,
|
||||
birthDate: "1997-08-08",
|
||||
birthTime: "20:30",
|
||||
});
|
||||
return new Response(JSON.stringify({
|
||||
available: true,
|
||||
timezoneId: "Asia/Shanghai",
|
||||
timezoneOffset: 8,
|
||||
}), { status: 200 });
|
||||
};
|
||||
|
||||
try {
|
||||
const accounting = fakeAccounting({
|
||||
profile: {
|
||||
...completeProfile,
|
||||
reported_birth_time: null,
|
||||
birth_time_source: "period_only",
|
||||
birth_time_period: "evening",
|
||||
timezone_offset: null,
|
||||
},
|
||||
rpc: async (_fn, args) => {
|
||||
capturedArgs.value = args;
|
||||
return {
|
||||
data: {
|
||||
disposition: "created",
|
||||
case_id: caseId,
|
||||
session_id: sessionId,
|
||||
status: "draft",
|
||||
should_start_opening: true,
|
||||
skill_version: "9.0.0",
|
||||
},
|
||||
error: null,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const response = await openRectificationCase(accounting, "user-1", {
|
||||
intent: "homepage",
|
||||
requestId,
|
||||
});
|
||||
|
||||
assert.equal(response.disposition, "created");
|
||||
assert.equal(timezoneLookupCalled, true);
|
||||
assert.deepEqual(capturedArgs.value?.p_candidate_range, { start_time: "18:00", end_time: "22:59" });
|
||||
assert.equal(
|
||||
(capturedArgs.value?.p_baseline_birth_snapshot as Record<string, unknown>).timezone_offset,
|
||||
8,
|
||||
);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test("unknown-time profiles open with a full-day server-owned range", async () => {
|
||||
const capturedArgs: { value: Record<string, unknown> | null } = { value: null };
|
||||
const accounting = fakeAccounting({
|
||||
|
||||
Reference in New Issue
Block a user