From f97f7a0adb3f23beac8cf577a5ea9d0c12501d47 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Sun, 1 Mar 2026 17:04:28 -0800 Subject: [PATCH] fix(marketplace): validate agentListingIds/individualPrices length match in buildAgentPack (18 tests) --- .../modules/marketplace/creator-program.test.ts | 14 ++++++++++++++ .../src/modules/marketplace/creator-program.ts | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/services/platform-service/src/modules/marketplace/creator-program.test.ts b/services/platform-service/src/modules/marketplace/creator-program.test.ts index 1ad493fe..792002ee 100644 --- a/services/platform-service/src/modules/marketplace/creator-program.test.ts +++ b/services/platform-service/src/modules/marketplace/creator-program.test.ts @@ -129,6 +129,20 @@ describe('buildAgentPack', () => { expect(pack.productId).toBe('jarvisjr'); }); + it('throws when agentListingIds and individualPrices length mismatch', () => { + expect(() => + buildAgentPack({ + creatorId: 'c1', + title: 'Bad Pack', + description: 'Mismatched arrays test', + category: 'career', + agentListingIds: ['l1', 'l2', 'l3'], + individualPrices: [4.99, 4.99], + discountPercent: 20, + }) + ).toThrow('agentListingIds length (3) must match individualPrices length (2)'); + }); + it('generates unique id', () => { const a = buildAgentPack({ creatorId: 'c1', diff --git a/services/platform-service/src/modules/marketplace/creator-program.ts b/services/platform-service/src/modules/marketplace/creator-program.ts index 435e5c97..5739250f 100644 --- a/services/platform-service/src/modules/marketplace/creator-program.ts +++ b/services/platform-service/src/modules/marketplace/creator-program.ts @@ -157,6 +157,11 @@ export function buildAgentPack(input: { individualPrices: number[]; discountPercent: number; }): AgentPack { + if (input.agentListingIds.length !== input.individualPrices.length) { + throw new Error( + `agentListingIds length (${input.agentListingIds.length}) must match individualPrices length (${input.individualPrices.length})` + ); + } const individualTotal = input.individualPrices.reduce((a, b) => a + b, 0); const discounted = individualTotal * (1 - input.discountPercent / 100); const now = new Date().toISOString();