Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ Thumbs.db

# Documentation and configs not needed in production container
README.md
nest-cli.json
tsconfig.json
tsconfig.build.json
eslint.config.mjs
.prettierrc
test/
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,8 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"engines": {
"node": ">=24"
}
}
}
7 changes: 7 additions & 0 deletions src/escrow/split-math.util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ describe('apportionBasisPoints', () => {
it('rejects an empty percentage list', () => {
expect(() => apportionBasisPoints([])).toThrow(BadRequestException);
});

it('rejects percentages that do not sum to 100', () => {
expect(() => apportionBasisPoints([20, 30])).toThrow(BadRequestException);
expect(() => apportionBasisPoints([50, 50, 10])).toThrow(
BadRequestException,
);
});
});

describe('splitStroops', () => {
Expand Down
7 changes: 7 additions & 0 deletions src/escrow/split-math.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ export function apportionBasisPoints(percentages: number[]): number[] {
throw new BadRequestException('At least one percentage is required');
}

const total = percentages.reduce((sum, p) => sum + p, 0);
if (Math.abs(total - 100) > 0.01) {
throw new BadRequestException(
`Percentages must sum to 100, got ${total.toFixed(2)}`,
);
}

const bps = percentages.map((p) => Math.round(p * 100));
const delta = TOTAL_BASIS_POINTS - bps.reduce((sum, b) => sum + b, 0);

Expand Down