(t *testing.T)
| 45 | } |
| 46 | |
| 47 | func TestGetAccountByID_Success(t *testing.T) { |
| 48 | db, mock, err := sqlmock.New() |
| 49 | assert.NoError(t, err) |
| 50 | defer func() { _ = db.Close() }() |
| 51 | |
| 52 | ds := Datasource{Conn: db} |
| 53 | |
| 54 | metaData := map[string]interface{}{ |
| 55 | "key": "value", |
| 56 | } |
| 57 | metaDataJSON, err := json.Marshal(metaData) |
| 58 | assert.NoError(t, err) |
| 59 | |
| 60 | // Begin transaction expectation |
| 61 | mock.ExpectBegin() |
| 62 | |
| 63 | // Mock the query result for account retrieval |
| 64 | row := sqlmock.NewRows([]string{"account_id", "name", "number", "bank_name", "currency", "ledger_id", "identity_id", "balance_id", "created_at", "meta_data"}). |
| 65 | AddRow("acc1", "Test Account", "1234567890", "Test Bank", "USD", "ldg1", "idt1", "bal1", time.Now(), metaDataJSON) |
| 66 | |
| 67 | mock.ExpectQuery("SELECT a.account_id, a.name, a.number, a.bank_name"). |
| 68 | WithArgs("acc1"). |
| 69 | WillReturnRows(row) |
| 70 | |
| 71 | // Commit transaction expectation |
| 72 | mock.ExpectCommit() |
| 73 | |
| 74 | account, err := ds.GetAccountByID("acc1", []string{}) |
| 75 | assert.NoError(t, err) |
| 76 | assert.Equal(t, "acc1", account.AccountID) |
| 77 | assert.Equal(t, "Test Account", account.Name) |
| 78 | |
| 79 | // Check if all expectations were met |
| 80 | err = mock.ExpectationsWereMet() |
| 81 | assert.NoError(t, err) |
| 82 | } |
| 83 | |
| 84 | func TestGetAllAccounts_Success(t *testing.T) { |
| 85 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected