From 6ab3bc87ff1e0a1fafed51e6b0d4ede000a923ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Mon, 27 Jul 2026 13:51:09 +0200 Subject: [PATCH] test(analytics): pin the effective-range resolver's sex-split defaults The resolver reads the profile's sex for the body-fat and pulse bands, and nothing asserted it. A resolver that stopped reading the field, or read it and defaulted to one side, passed the whole suite. Pin both recorded sides and the neutral band that OTHER and an unanswered profile share. --- .../__tests__/effective-range.test.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib/analytics/__tests__/effective-range.test.ts b/src/lib/analytics/__tests__/effective-range.test.ts index 8e6e756fe..4ce9905a8 100644 --- a/src/lib/analytics/__tests__/effective-range.test.ts +++ b/src/lib/analytics/__tests__/effective-range.test.ts @@ -90,6 +90,29 @@ describe("getEffectiveRange", () => { }); }); +// The resolver narrows the stored three-value sex to the two a sex-split +// reference table has rows for, and OTHER / "no answer" must land on the +// neutral band rather than on either side. Nothing pinned that before, so a +// resolver that quietly stopped reading the profile's sex — or read it and +// picked a default side — went unnoticed. +describe("sex-split defaults", () => { + const withGender = (gender: string | null) => + getEffectiveRange("BODY_FAT", { ...baseProfile, gender }, null).range!; + + it("gives each recorded side its own body-fat band", () => { + expect(withGender("MALE").greenMin).toBe(14); + expect(withGender("MALE").greenMax).toBe(24); + expect(withGender("FEMALE").greenMin).toBe(21); + expect(withGender("FEMALE").greenMax).toBe(31); + }); + + it("gives OTHER and an unanswered profile the same neutral band", () => { + const neutral = { greenMin: 17, greenMax: 27 }; + expect(withGender("OTHER")).toMatchObject(neutral); + expect(withGender(null)).toMatchObject(neutral); + }); +}); + describe("getAllEffectiveRanges", () => { it("returns an entry for every metric", () => { const ranges = getAllEffectiveRanges(baseProfile, null);