From 344247939af8ed2514a51dd902c91c35e93ef3f3 Mon Sep 17 00:00:00 2001 From: rudra496 Date: Mon, 17 Aug 2026 15:00:41 +0600 Subject: [PATCH] test(utils): pin validateTeamSplits edge-case contracts The duplicate-declaration build break from #68 is already resolved on main (75fea94, ba7cc7b), but the surrounding behaviour was only partly pinned: the empty-array short-circuit asserted the sum without the valid flag, mixed string/number arrays and the tolerance parameter had no coverage, and an unparseable percentage was untested. Adds four tests: empty array is valid with zero sum, mixed percentage types sum correctly, a wide tolerance accepts sums it would otherwise reject, and NaN-producing input stays invalid. --- src/lib/utils.test.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/lib/utils.test.ts b/src/lib/utils.test.ts index 25ffde7..55634c8 100644 --- a/src/lib/utils.test.ts +++ b/src/lib/utils.test.ts @@ -284,10 +284,35 @@ describe("validateTeamSplits", () => { expect(result.sum).toBe(100); }); - it("handles an empty array", () => { + it("treats an empty array as valid with a zero sum", () => { const result = validateTeamSplits([]); - // Empty splits don't sum to 100, so valid=false is correct behavior + expect(result.valid).toBe(true); expect(result.sum).toBe(0); + expect(result.message).toBeUndefined(); + }); + + it("handles mixed string and number percentages in one array", () => { + const result = validateTeamSplits([ + { percentage: "45.5" }, + { percentage: 30 }, + { percentage: "24.5" }, + ]); + expect(result.valid).toBe(true); + expect(result.sum).toBe(100); + }); + + it("honors a custom tolerance", () => { + const wide = [{ percentage: 60 }, { percentage: 43 }]; + expect(validateTeamSplits(wide).valid).toBe(false); + expect(validateTeamSplits(wide, 5).valid).toBe(true); + }); + + it("returns a non-finite-safe result for unparseable strings", () => { + const result = validateTeamSplits([ + { percentage: "abc" }, + { percentage: 100 }, + ]); + expect(result.valid).toBe(false); }); it("degrades a non-numeric percentage string to 0 instead of producing NaN (#198)", () => {