(t *testing.T)
| 1427 | } |
| 1428 | |
| 1429 | func TestUpdateMonitor_NotFound(t *testing.T) { |
| 1430 | db, mock, err := sqlmock.New() |
| 1431 | assert.NoError(t, err) |
| 1432 | defer func() { _ = db.Close() }() |
| 1433 | |
| 1434 | ds := Datasource{Conn: db} |
| 1435 | |
| 1436 | monitor := &model.BalanceMonitor{ |
| 1437 | MonitorID: "mon_nonexistent", |
| 1438 | BalanceID: "bln_123", |
| 1439 | Description: "Updated alert", |
| 1440 | Condition: model.AlertCondition{ |
| 1441 | Field: "balance", |
| 1442 | Operator: "<=", |
| 1443 | Value: 2000, |
| 1444 | }, |
| 1445 | } |
| 1446 | |
| 1447 | query := ` |
| 1448 | UPDATE ledgerforge.balance_monitors |
| 1449 | SET balance_id = $2, field = $3, operator = $4, value = $5, description = $6, call_back_url = $7 |
| 1450 | WHERE monitor_id = $1 |
| 1451 | ` |
| 1452 | |
| 1453 | mock.ExpectExec(regexp.QuoteMeta(query)). |
| 1454 | WithArgs(monitor.MonitorID, monitor.BalanceID, monitor.Condition.Field, monitor.Condition.Operator, monitor.Condition.Value, monitor.Description, monitor.CallBackURL). |
| 1455 | WillReturnResult(sqlmock.NewResult(0, 0)) |
| 1456 | |
| 1457 | err = ds.UpdateMonitor(monitor) |
| 1458 | assert.Error(t, err) |
| 1459 | apiErr, ok := err.(apierror.APIError) |
| 1460 | assert.True(t, ok) |
| 1461 | assert.Equal(t, apierror.ErrNotFound, apiErr.Code) |
| 1462 | |
| 1463 | err = mock.ExpectationsWereMet() |
| 1464 | assert.NoError(t, err) |
| 1465 | } |
| 1466 | |
| 1467 | func TestDeleteMonitor_Success(t *testing.T) { |
| 1468 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected