(t *testing.T)
| 13 | ) |
| 14 | |
| 15 | func TestCreateAccount_Success(t *testing.T) { |
| 16 | db, mock, err := sqlmock.New() |
| 17 | assert.NoError(t, err) |
| 18 | defer func() { _ = db.Close() }() |
| 19 | |
| 20 | ds := Datasource{Conn: db} |
| 21 | |
| 22 | account := model.Account{ |
| 23 | Name: "Test Account", |
| 24 | Number: "1234567890", |
| 25 | BankName: "Test Bank", |
| 26 | Currency: "USD", |
| 27 | LedgerID: "ldg1", |
| 28 | IdentityID: "idt1", |
| 29 | BalanceID: "bal1", |
| 30 | MetaData: map[string]interface{}{ |
| 31 | "key": "value", |
| 32 | }, |
| 33 | } |
| 34 | |
| 35 | metaDataJSON, err := json.Marshal(account.MetaData) |
| 36 | assert.NoError(t, err) |
| 37 | |
| 38 | mock.ExpectExec("INSERT INTO ledgerforge.accounts"). |
| 39 | WithArgs(sqlmock.AnyArg(), account.Name, account.Number, account.BankName, account.Currency, account.LedgerID, account.IdentityID, account.BalanceID, sqlmock.AnyArg(), metaDataJSON). |
| 40 | WillReturnResult(sqlmock.NewResult(1, 1)) |
| 41 | |
| 42 | createdAccount, err := ds.CreateAccount(account) |
| 43 | assert.NoError(t, err) |
| 44 | assert.NotEmpty(t, createdAccount.AccountID) |
| 45 | } |
| 46 | |
| 47 | func TestGetAccountByID_Success(t *testing.T) { |
| 48 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected