fix(marketplace): validate agentListingIds/individualPrices length match in buildAgentPack (18 tests)
This commit is contained in:
parent
573f54888c
commit
f97f7a0adb
@ -129,6 +129,20 @@ describe('buildAgentPack', () => {
|
|||||||
expect(pack.productId).toBe('jarvisjr');
|
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', () => {
|
it('generates unique id', () => {
|
||||||
const a = buildAgentPack({
|
const a = buildAgentPack({
|
||||||
creatorId: 'c1',
|
creatorId: 'c1',
|
||||||
|
|||||||
@ -157,6 +157,11 @@ export function buildAgentPack(input: {
|
|||||||
individualPrices: number[];
|
individualPrices: number[];
|
||||||
discountPercent: number;
|
discountPercent: number;
|
||||||
}): AgentPack {
|
}): 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 individualTotal = input.individualPrices.reduce((a, b) => a + b, 0);
|
||||||
const discounted = individualTotal * (1 - input.discountPercent / 100);
|
const discounted = individualTotal * (1 - input.discountPercent / 100);
|
||||||
const now = new Date().toISOString();
|
const now = new Date().toISOString();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user