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();