(t *testing.T)
| 1391 | } |
| 1392 | |
| 1393 | func TestUpdateMonitor_Success(t *testing.T) { |
| 1394 | db, mock, err := sqlmock.New() |
| 1395 | assert.NoError(t, err) |
| 1396 | defer func() { _ = db.Close() }() |
| 1397 | |
| 1398 | ds := Datasource{Conn: db} |
| 1399 | |
| 1400 | monitor := &model.BalanceMonitor{ |
| 1401 | MonitorID: "mon_123", |
| 1402 | BalanceID: "bln_123", |
| 1403 | Description: "Updated alert", |
| 1404 | CallBackURL: "https://example.com/updated", |
| 1405 | Condition: model.AlertCondition{ |
| 1406 | Field: "balance", |
| 1407 | Operator: "<=", |
| 1408 | Value: 2000, |
| 1409 | }, |
| 1410 | } |
| 1411 | |
| 1412 | query := ` |
| 1413 | UPDATE ledgerforge.balance_monitors |
| 1414 | SET balance_id = $2, field = $3, operator = $4, value = $5, description = $6, call_back_url = $7 |
| 1415 | WHERE monitor_id = $1 |
| 1416 | ` |
| 1417 | |
| 1418 | mock.ExpectExec(regexp.QuoteMeta(query)). |
| 1419 | WithArgs(monitor.MonitorID, monitor.BalanceID, monitor.Condition.Field, monitor.Condition.Operator, monitor.Condition.Value, monitor.Description, monitor.CallBackURL). |
| 1420 | WillReturnResult(sqlmock.NewResult(0, 1)) |
| 1421 | |
| 1422 | err = ds.UpdateMonitor(monitor) |
| 1423 | assert.NoError(t, err) |
| 1424 | |
| 1425 | err = mock.ExpectationsWereMet() |
| 1426 | assert.NoError(t, err) |
| 1427 | } |
| 1428 | |
| 1429 | func TestUpdateMonitor_NotFound(t *testing.T) { |
| 1430 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected