MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestGetBalanceByIndicator_Success

Function TestGetBalanceByIndicator_Success

database/balance_test.go:917–954  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

915}
916
917func TestGetBalanceByIndicator_Success(t *testing.T) {
918 db, mock, err := sqlmock.New()
919 assert.NoError(t, err)
920 defer func() { _ = db.Close() }()
921
922 ds := Datasource{Conn: db}
923
924 query := `
925 SELECT balance_id, indicator, currency, currency_multiplier, ledger_id, balance, credit_balance, debit_balance, inflight_balance, inflight_credit_balance, inflight_debit_balance, created_at, version, track_fund_lineage, COALESCE(allocation_strategy, 'FIFO') as allocation_strategy, COALESCE(identity_id, '') as identity_id
926 FROM ledgerforge.balances
927 WHERE indicator = $1 AND currency = $2
928 `
929
930 mock.ExpectQuery(regexp.QuoteMeta(query)).
931 WithArgs("ACC001", "USD").
932 WillReturnRows(sqlmock.NewRows([]string{
933 "balance_id", "indicator", "currency", "currency_multiplier", "ledger_id",
934 "balance", "credit_balance", "debit_balance",
935 "inflight_balance", "inflight_credit_balance", "inflight_debit_balance",
936 "created_at", "version", "track_fund_lineage", "allocation_strategy", "identity_id",
937 }).AddRow(
938 "bln_123", "ACC001", "USD", 100, "ldg_001",
939 "100000", "60000", "40000",
940 "5000", "3000", "2000",
941 time.Now(), 1, false, "FIFO", "",
942 ))
943
944 balance, err := ds.GetBalanceByIndicator("ACC001", "USD")
945 assert.NoError(t, err)
946 assert.NotNil(t, balance)
947 assert.Equal(t, "bln_123", balance.BalanceID)
948 assert.Equal(t, "ACC001", balance.Indicator)
949 assert.Equal(t, "USD", balance.Currency)
950 assert.Equal(t, "100000", balance.Balance.String())
951
952 err = mock.ExpectationsWereMet()
953 assert.NoError(t, err)
954}
955
956func TestGetBalanceByIndicator_NotFound(t *testing.T) {
957 db, mock, err := sqlmock.New()

Callers

nothing calls this directly

Calls 2

GetBalanceByIndicatorMethod · 0.95
CloseMethod · 0.45

Tested by

no test coverage detected