mirror of
https://github.com/whekin/household-bot.git
synced 2026-04-01 02:44:02 +00:00
feat(finance): support weighted rent split
This commit is contained in:
@@ -83,6 +83,25 @@ describe('calculateMonthlySettlement', () => {
|
||||
expect(result.totalDue.amountMinor).toBe(82000n)
|
||||
})
|
||||
|
||||
test('supports weighted rent split by member weights', () => {
|
||||
const input = {
|
||||
...fixtureBase(),
|
||||
utilitySplitMode: 'equal' as const,
|
||||
members: [
|
||||
{ memberId: MemberId.from('a'), active: true, rentWeight: 3 },
|
||||
{ memberId: MemberId.from('b'), active: true, rentWeight: 2 },
|
||||
{ memberId: MemberId.from('c'), active: true, rentWeight: 1 }
|
||||
],
|
||||
purchases: []
|
||||
}
|
||||
|
||||
const result = calculateMonthlySettlement(input)
|
||||
|
||||
expect(result.lines.map((line) => line.rentShare.amountMinor)).toEqual([35000n, 23333n, 11667n])
|
||||
expect(result.lines.map((line) => line.utilityShare.amountMinor)).toEqual([4000n, 4000n, 4000n])
|
||||
expect(result.totalDue.amountMinor).toBe(82000n)
|
||||
})
|
||||
|
||||
test('5-member scenario with two purchases remains deterministic', () => {
|
||||
const input = {
|
||||
...fixtureBase(),
|
||||
@@ -150,4 +169,18 @@ describe('calculateMonthlySettlement', () => {
|
||||
|
||||
expect(() => calculateMonthlySettlement(input)).toThrow(DomainError)
|
||||
})
|
||||
|
||||
test('throws if rent split is selected with invalid rent weights', () => {
|
||||
const input = {
|
||||
...fixtureBase(),
|
||||
utilitySplitMode: 'equal' as const,
|
||||
members: [
|
||||
{ memberId: MemberId.from('a'), active: true, rentWeight: 1 },
|
||||
{ memberId: MemberId.from('b'), active: true, rentWeight: 0 }
|
||||
],
|
||||
purchases: []
|
||||
}
|
||||
|
||||
expect(() => calculateMonthlySettlement(input)).toThrow(DomainError)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user