fix(marketplace): validate agentListingIds/individualPrices length match in buildAgentPack (18 tests)

This commit is contained in:
saravanakumardb1 2026-03-01 17:04:28 -08:00
parent 573f54888c
commit f97f7a0adb
2 changed files with 19 additions and 0 deletions

View File

@ -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',

View File

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