mirror of
https://github.com/whekin/household-bot.git
synced 2026-04-01 09:24:03 +00:00
Stabilize purchase functionality: fix ID prefix, uniqueness, and split participant inclusion
This commit is contained in:
@@ -61,6 +61,7 @@ class FinanceRepositoryStub implements FinanceRepository {
|
||||
replacedSnapshot: SettlementSnapshotRecord | null = null
|
||||
cycleExchangeRates = new Map<string, FinanceCycleExchangeRateRecord>()
|
||||
lastUpdatedPurchaseInput: Parameters<FinanceRepository['updateParsedPurchase']>[0] | null = null
|
||||
lastAddedPurchaseInput: Parameters<FinanceRepository['addParsedPurchase']>[0] | null = null
|
||||
|
||||
async getMemberByTelegramUserId(): Promise<FinanceMemberRecord | null> {
|
||||
return this.member
|
||||
@@ -131,6 +132,24 @@ class FinanceRepositoryStub implements FinanceRepository {
|
||||
this.lastUtilityBill = input
|
||||
}
|
||||
|
||||
async addParsedPurchase(input: Parameters<FinanceRepository['addParsedPurchase']>[0]) {
|
||||
this.lastAddedPurchaseInput = input
|
||||
return {
|
||||
id: 'purchase-1',
|
||||
payerMemberId: input.payerMemberId,
|
||||
amountMinor: input.amountMinor,
|
||||
currency: input.currency,
|
||||
description: input.description,
|
||||
occurredAt: input.occurredAt,
|
||||
splitMode: input.splitMode ?? 'equal',
|
||||
participants: (input.participants ?? []).map((p) => ({
|
||||
memberId: p.memberId,
|
||||
included: p.included ?? true,
|
||||
shareAmountMinor: p.shareAmountMinor
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
async updateUtilityBill() {
|
||||
return null
|
||||
}
|
||||
@@ -655,10 +674,12 @@ describe('createFinanceCommandService', () => {
|
||||
participants: [
|
||||
{
|
||||
memberId: 'alice',
|
||||
included: true,
|
||||
shareAmountMinor: 2000n
|
||||
},
|
||||
{
|
||||
memberId: 'bob',
|
||||
included: true,
|
||||
shareAmountMinor: 1000n
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user