[tests] Sharing: only an explicit assignment shares a payment; a shared budget is never the default
This commit is contained in:
@@ -108,3 +108,35 @@ fn sharing_into_a_budget_the_log_does_not_have_is_rejected() {
|
||||
let s2 = State::replay(&[ev("g2", shared_payment(&s, "p1", "b-trip").unwrap())]);
|
||||
assert_eq!(s2.rejected.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_an_explicit_assignment_shares_a_payment_never_the_default_budget() {
|
||||
// A person whose only budget is a shared one: their unassigned payments fall to it as the default, but
|
||||
// that never makes them shared.
|
||||
let log = vec![
|
||||
ev("e1", EventBody::BudgetCreated { budget: "b-trip".into(), name: "Trip".into(), limit: Haler(500_000) }),
|
||||
ev("e2", EventBody::PaymentCaptured { payment: "p1".into(), amount: Haler(-5_000), date: d("2026-11-02"), merchant: "Kavarna".into(), card: None }),
|
||||
];
|
||||
let s = State::replay(&log);
|
||||
assert_eq!(s.effective_payment("p1").unwrap().budget.as_deref(), Some("b-trip"), "the default budget");
|
||||
assert!(shared_payment(&s, "p1", "b-trip").is_none(), "not assigned, so not shared");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shared_budget_in_the_personal_log_is_never_the_default() {
|
||||
let log = vec![
|
||||
ev("e1", EventBody::BudgetShared { budget: "b-trip".into(), name: "Trip".into(), limit: Haler(500_000) }),
|
||||
ev("e2", EventBody::PaymentCaptured { payment: "p1".into(), amount: Haler(-5_000), date: d("2026-11-02"), merchant: "Kavarna".into(), card: None }),
|
||||
ev("e3", EventBody::BudgetCreated { budget: "b-home".into(), name: "Home".into(), limit: Haler(1_000_000) }),
|
||||
ev("e4", EventBody::PaymentAssigned { payment: "p1".into(), budget: "b-trip".into() }),
|
||||
];
|
||||
let s = State::replay(&log);
|
||||
assert!(s.rejected.is_empty(), "{:?}", s.rejected);
|
||||
assert_eq!(s.default_budget.as_deref(), Some("b-home"));
|
||||
assert_eq!(s.budgets["b-trip"].name, "Trip");
|
||||
assert!(shared_payment(&s, "p1", "b-trip").is_some(), "assigned explicitly");
|
||||
let dup = ev("e5", EventBody::BudgetShared { budget: "b-trip".into(), name: "Trip".into(), limit: Haler(1) });
|
||||
let mut log2 = log.clone();
|
||||
log2.push(dup);
|
||||
assert_eq!(State::replay(&log2).rejected.len(), 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user