(t *testing.T)
| 149 | } |
| 150 | |
| 151 | func 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 | |
| 178 | func TestGetBalanceByID(t *testing.T) { |
| 179 | datasource, mock, err := newTestDataSource() |
nothing calls this directly
no test coverage detected