From 7e1b79315ede49d6e1714964b58442b00e9c71f3 Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Sat, 22 Aug 2026 18:18:44 +0200 Subject: [PATCH] test(shops): cover non-finite and missing-key guards in describeRequirement --- apps/api/src/shops/offer-presentation.spec.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/apps/api/src/shops/offer-presentation.spec.ts b/apps/api/src/shops/offer-presentation.spec.ts index 3d85155..4daafb5 100644 --- a/apps/api/src/shops/offer-presentation.spec.ts +++ b/apps/api/src/shops/offer-presentation.spec.ts @@ -94,6 +94,47 @@ describe('describeRequirement', () => { ), ).toBeNull(); }); + + it('renders no line if the condition has a non-numeric value', () => { + // A requirement with no valid threshold is unactionable -- the player + // has no goal to work toward. Better to hide the gate than to render + // a malformed line. + expect( + describeRequirement( + { + condition: { + type: GameConditionType.REGION_REPUTATION, + key: 'border-guard', + operator: ComparisonOperator.GTE, + value: NaN, + }, + met: false, + actual: 14, + }, + FACTIONS, + ), + ).toBeNull(); + }); + + it('renders no line for a reputation gate with no faction key', () => { + // A gate that names no faction is malformed. The player cannot act on a + // requirement that never says which faction. Better to show nothing than + // broken content. + expect( + describeRequirement( + { + condition: { + type: GameConditionType.REGION_REPUTATION, + operator: ComparisonOperator.GTE, + value: 25, + } as any, + met: false, + actual: 14, + }, + FACTIONS, + ), + ).toBeNull(); + }); }); describe('describeItemEffect', () => {