diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-21 11:44:07 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-21 11:44:07 +0800 |
| commit | 205e2a592bf781f08fe23f3577cdfe74ff9a076a (patch) | |
| tree | 05aad6f87ca8f6c78fbc2d4c4d0d89356439936a /tests/FundLab.Domain.Tests/DomainTests.fs | |
| parent | b8811922f4e167d50efb8817da35a12d8a9d653b (diff) | |
| download | fund-lab-205e2a592bf781f08fe23f3577cdfe74ff9a076a.tar.gz | |
Add additional capital deposit flow (3d-4)
Deposits credit a fund's available cash directly: Domain gains
CapitalPolicy (positive, two-decimal, overflow-checked amounts plus a
settle function that never touches units, NAV or realized P&L).
Persistence records deposits in fund_capital_deposits with a
fund_capital_idempotencies table, crediting cash and the deposit row
atomically under the same replay/conflict semantics as orders. The
API exposes POST /funds/{id}/capital/deposit and GET
/funds/{id}/capital/deposits behind the bearer token and idempotency
keys. The frontend adds an '追加资金' entry on the fund cash card with
in-place balance refresh, and repeats of the same amount reuse the
idempotency key so double submits credit cash exactly once. Browser
QA extends the J-series (J12-J18): invalid-amount rejection without
POST, single credited deposit with a 32-hex key, instant balance
refresh, unchanged units/cost proving no realized-income impact, and
same-key replay crediting only once.
Diffstat (limited to 'tests/FundLab.Domain.Tests/DomainTests.fs')
| -rw-r--r-- | tests/FundLab.Domain.Tests/DomainTests.fs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/FundLab.Domain.Tests/DomainTests.fs b/tests/FundLab.Domain.Tests/DomainTests.fs index 6a9fc66..46516d5 100644 --- a/tests/FundLab.Domain.Tests/DomainTests.fs +++ b/tests/FundLab.Domain.Tests/DomainTests.fs @@ -539,3 +539,24 @@ module RedemptionPolicyTests = Assert.Equal(Error "redemption fee exceeds redemption value", RedemptionPolicy.compute 1.00000000m 2.5m 3.00m 100.00m 40.00000000m) Assert.Equal(Error "redemption proceeds rounds to zero", RedemptionPolicy.compute 0.00000001m 1500000m 0.01m 100.00m 40.00000000m) Assert.Equal(Error "redemption cash rounds to zero", RedemptionPolicy.compute 0.00000001m 2m 0.00m 100.00m 40.00000000m) + +module CapitalPolicyTests = + + open Xunit + open FundLab.Domain + + [<Fact>] + let ``deposit validation rejects non positive or imprecise amounts`` () = + Assert.Equal(Error "deposit amount must be positive", CapitalPolicy.validateDeposit 0m) + Assert.Equal(Error "deposit amount must be positive", CapitalPolicy.validateDeposit -100.00m) + Assert.Equal(Error "deposit amount exceeds cash precision", CapitalPolicy.validateDeposit 100.005m) + Assert.Equal(Ok(), CapitalPolicy.validateDeposit 500.00m) + + [<Fact>] + let ``settlement adds to available cash without touching units or nav`` () = + Assert.Equal(Ok 5398.51m, CapitalPolicy.settle 4898.51m 500.00m) + Assert.Equal(Ok 10000.00m, CapitalPolicy.settle 9000.00m 1000.00m) + + let overflow = CapitalPolicy.settle CapitalPolicy.cashMaximum 0.01m + + Assert.Equal(Error "available cash exceeds database precision", overflow) |
