diff --git a/.dockerignore b/.dockerignore index 1e0aac9..d7d6c9c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -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/ diff --git a/package.json b/package.json index e65c3bc..e2414dd 100644 --- a/package.json +++ b/package.json @@ -107,5 +107,8 @@ ], "coverageDirectory": "../coverage", "testEnvironment": "node" + }, + "engines": { + "node": ">=24" } -} +} \ No newline at end of file diff --git a/src/escrow/split-math.util.spec.ts b/src/escrow/split-math.util.spec.ts index aa1da7f..fb7e946 100644 --- a/src/escrow/split-math.util.spec.ts +++ b/src/escrow/split-math.util.spec.ts @@ -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', () => { diff --git a/src/escrow/split-math.util.ts b/src/escrow/split-math.util.ts index c107f94..e11b908 100644 --- a/src/escrow/split-math.util.ts +++ b/src/escrow/split-math.util.ts @@ -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);