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

Function TestCreateBalance

balance_test.go:151–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestCreateBalance(t *testing.T) {
152 datasource, mock, err := newTestDataSource()
153 if err != nil {
154 t.Fatalf("Error creating test data source: %s", err)
155 }
156
157 d, err := NewLedgerForge(datasource)
158 if err != nil {
159 t.Fatalf("Error creating LedgerForge instance: %s", err)
160 }
161 balance := model.Balance{Balance: big.NewInt(100), CreditBalance: big.NewInt(50), DebitBalance: big.NewInt(50), Currency: "USD", LedgerID: "test-id", IdentityID: "test-id"}
162
163 // Convert metadata to JSON for mocking
164 metaDataJSON, _ := json.Marshal(balance.MetaData)
165 mock.ExpectExec("INSERT INTO ledgerforge.balances").
166 WithArgs(sqlmock.AnyArg(), balance.Balance.String(), balance.CreditBalance.String(), balance.DebitBalance.String(), balance.Currency, balance.CurrencyMultiplier, balance.LedgerID, balance.IdentityID, sqlmock.AnyArg(), sqlmock.AnyArg(), metaDataJSON, false, "FIFO").
167 WillReturnResult(sqlmock.NewResult(1, 1))
168
169 result, err := d.CreateBalance(context.Background(), balance)
170 assert.NoError(t, err)
171 assert.NotEmpty(t, result.BalanceID)
172 assert.Contains(t, result.BalanceID, "bln_")
173 if err := mock.ExpectationsWereMet(); err != nil {
174 t.Errorf("there were unfulfilled expectations: %s", err)
175 }
176}
177
178func TestGetBalanceByID(t *testing.T) {
179 datasource, mock, err := newTestDataSource()

Callers

nothing calls this directly

Calls 3

CreateBalanceMethod · 0.95
newTestDataSourceFunction · 0.85
NewLedgerForgeFunction · 0.85

Tested by

no test coverage detected