From 248b50c8fd057c87a852f8306fc4585905880abc Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Tue, 22 Sep 2026 20:42:27 +0800 Subject: Fetch latest fund NAV via ETF endpoint so T-day subscriptions can confirm (3d-38) --- tests/FundLab.Api.Tests/CashReconciliationTests.fs | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/FundLab.Api.Tests') diff --git a/tests/FundLab.Api.Tests/CashReconciliationTests.fs b/tests/FundLab.Api.Tests/CashReconciliationTests.fs index b9b024a..fa14bff 100644 --- a/tests/FundLab.Api.Tests/CashReconciliationTests.fs +++ b/tests/FundLab.Api.Tests/CashReconciliationTests.fs @@ -542,3 +542,47 @@ type CashReconciliationTests(fixture: PostgresFixture) = Assert.Equal(-520.00m, internalTotal) Assert.Equal(3880.00m, externalTotal + internalTotal) Assert.Equal(0.00m, (repository().GetCashReconciliation fundId |> Result.defaultWith failwith).Difference) + + [] + member _.``a subscription confirmed at the 2026-09-22 nav date reconciles to zero``() = + let fundId = createFund 10000.00m + let code = seedInstrument () + let tradeDate = DateOnly(2026, 9, 22) + insertQuoteOnDate code 1.327m tradeDate + + let order = + match + repository().CreateSubscriptionOrder( + fixture.Key "cash-tday-order", + fundId, + { FundCode = code; Amount = 1000.00m; FeeAmount = 0m }, + tradeDate + ) + with + | SubscriptionOrderWriteResult.OrderCreated order -> order + | other -> failwithf "unexpected subscription order result: %A" other + + match + repository().ConfirmSubscriptionOrder( + fixture.Key "cash-tday-confirm", + fundId, + order.Id + ) + with + | SubscriptionConfirmResult.OrderConfirmed confirmed -> + match confirmed.ConfirmedQuote with + | Some quote -> + Assert.Equal(tradeDate, quote.NavDate) + Assert.Equal(1.327m, quote.Nav) + | None -> failwith "confirmed quote evidence missing" + | other -> failwithf "unexpected subscription confirm: %A" other + + let status, body = reconciliation fundId + Assert.Equal(200, status) + Assert.Contains("\"openingCash\":\"10000.00\"", body) + Assert.Contains("\"difference\":\"0.00\"", body) + Assert.Equal(1, eventCount body "subscription") + + // the confirmed subscription is an external outflow that fully explains cash + let subscriptionNet = sourceNet body "subscription" + Assert.True(subscriptionNet < 0m, sprintf "expected subscription outflow, got %M" subscriptionNet) -- cgit v1.2.3