summaryrefslogtreecommitdiff
path: root/tests/FundLab.Api.Tests/DividendTests.fs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/FundLab.Api.Tests/DividendTests.fs')
-rw-r--r--tests/FundLab.Api.Tests/DividendTests.fs52
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)