diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-21 22:08:53 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-21 22:08:53 +0800 |
| commit | 4c60174fc66927db5536bc2fe06574c753140055 (patch) | |
| tree | c18fb8650d097f584cd8e141903cff2ffae0d0fd /tests/FundLab.Api.Tests | |
| parent | 722ec6c19c0c64ea5348c6bc3aefc0061bd96307 (diff) | |
| download | fund-lab-4c60174fc66927db5536bc2fe06574c753140055.tar.gz | |
Add dividend history visibility (3d-9a)
Expose a deterministic source key on booked dividend records and surface a read-only dividend history panel with empty state, backed by API tests and browser QA assertions.
Diffstat (limited to 'tests/FundLab.Api.Tests')
| -rw-r--r-- | tests/FundLab.Api.Tests/DividendTests.fs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/FundLab.Api.Tests/DividendTests.fs b/tests/FundLab.Api.Tests/DividendTests.fs index 7645aff..e13c764 100644 --- a/tests/FundLab.Api.Tests/DividendTests.fs +++ b/tests/FundLab.Api.Tests/DividendTests.fs @@ -2,6 +2,7 @@ namespace FundLab.Api.Tests open System open System.Globalization +open System.Text.Json open Npgsql open Xunit open FundLab.Api @@ -157,6 +158,14 @@ type DividendTests(fixture: PostgresFixture) = ] body + let listDividends (fundId: Guid) = + PersistenceTestHelpers.invoke + (app ()) + "GET" + (sprintf "/api/funds/%O/dividends" fundId) + [ "Authorization", "Bearer test-token" ] + "" + [<Fact>] member _.``cash dividend credits available cash exactly once per scheme``() = let fundId = createFund 10000.00m @@ -248,3 +257,46 @@ type DividendTests(fixture: PostgresFixture) = Assert.Equal(200, listStatus) Assert.Contains("\"instrumentCode\":\"" + codeA + "\"", listResponse) Assert.Contains("\"mode\":\"cash\"", listResponse) + + [<Fact>] + member _.``dividend history exposes booked cash fields and never duplicates on replay``() = + let fundId = createFund 10000.00m + let codeA = confirmedHolding fundId (seedInstrument ()) 250.00m + let navDate = anchDate.ToString("yyyy-MM-dd") + + let firstStatus, _ = postDividend fundId codeA navDate "0.10000000" "cash" + Assert.Equal(200, firstStatus) + + let listStatus, listResponse = listDividends fundId + Assert.Equal(200, listStatus) + + use document = JsonDocument.Parse(listResponse) + let records = document.RootElement + Assert.Equal(1, records.GetArrayLength()) + + let record = records[0] + Assert.Equal(codeA, record.GetProperty("instrumentCode").GetString()) + Assert.Equal("2026-09-21", record.GetProperty("navDate").GetString()) + Assert.Equal("cash", record.GetProperty("mode").GetString()) + Assert.Equal("0.10000000", record.GetProperty("dps").GetString()) + Assert.Equal("10.00", record.GetProperty("grossCash").GetString()) + Assert.Equal("cash_credited", record.GetProperty("status").GetString()) + + let sourceKey = record.GetProperty("sourceKey").GetString() + Assert.Contains("dividend-scheme:", sourceKey) + Assert.Contains(codeA, sourceKey) + Assert.EndsWith(":cash", sourceKey) + + let replayStatus, _ = postDividend fundId codeA navDate "0.10000000" "cash" + Assert.Equal(200, replayStatus) + + let _, afterReplay = listDividends fundId + use afterDocument = JsonDocument.Parse(afterReplay) + Assert.Equal(1, afterDocument.RootElement.GetArrayLength()) + + [<Fact>] + member _.``dividend history is empty for a fund without dividends``() = + let fundId = createFund 10000.00m + let status, body = listDividends fundId + Assert.Equal(200, status) + Assert.Equal("[]", body) |
