(t *testing.T)
| 1220 | } |
| 1221 | |
| 1222 | func TestGetMonitorByID_Success(t *testing.T) { |
| 1223 | db, mock, err := sqlmock.New() |
| 1224 | assert.NoError(t, err) |
| 1225 | defer func() { _ = db.Close() }() |
| 1226 | |
| 1227 | ds := Datasource{Conn: db} |
| 1228 | |
| 1229 | query := ` |
| 1230 | SELECT monitor_id, balance_id, field, operator, value, precision, precise_value, description, call_back_url, created_at |
| 1231 | FROM ledgerforge.balance_monitors WHERE monitor_id = $1 |
| 1232 | ` |
| 1233 | |
| 1234 | mock.ExpectQuery(regexp.QuoteMeta(query)). |
| 1235 | WithArgs("mon_123"). |
| 1236 | WillReturnRows(sqlmock.NewRows([]string{ |
| 1237 | "monitor_id", "balance_id", "field", "operator", "value", "precision", "precise_value", "description", "call_back_url", "created_at", |
| 1238 | }).AddRow( |
| 1239 | "mon_123", "bln_123", "balance", "<", 1000.0, 100, int64(100000), "Low balance alert", "https://example.com/webhook", time.Now(), |
| 1240 | )) |
| 1241 | |
| 1242 | monitor, err := ds.GetMonitorByID("mon_123") |
| 1243 | assert.NoError(t, err) |
| 1244 | assert.NotNil(t, monitor) |
| 1245 | assert.Equal(t, "mon_123", monitor.MonitorID) |
| 1246 | assert.Equal(t, "bln_123", monitor.BalanceID) |
| 1247 | assert.Equal(t, "balance", monitor.Condition.Field) |
| 1248 | assert.Equal(t, "<", monitor.Condition.Operator) |
| 1249 | assert.Equal(t, float64(1000), monitor.Condition.Value) |
| 1250 | |
| 1251 | err = mock.ExpectationsWereMet() |
| 1252 | assert.NoError(t, err) |
| 1253 | } |
| 1254 | |
| 1255 | func TestGetMonitorByID_NotFound(t *testing.T) { |
| 1256 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected