(t *testing.T)
| 1117 | } |
| 1118 | |
| 1119 | func TestCreateMonitor_Success(t *testing.T) { |
| 1120 | db, mock, err := sqlmock.New() |
| 1121 | assert.NoError(t, err) |
| 1122 | defer func() { _ = db.Close() }() |
| 1123 | |
| 1124 | ds := Datasource{Conn: db} |
| 1125 | |
| 1126 | monitor := model.BalanceMonitor{ |
| 1127 | BalanceID: "bln_123", |
| 1128 | Description: "Low balance alert", |
| 1129 | CallBackURL: "https://example.com/webhook", |
| 1130 | Condition: model.AlertCondition{ |
| 1131 | Field: "balance", |
| 1132 | Operator: "<", |
| 1133 | Value: 1000, |
| 1134 | Precision: 100, |
| 1135 | PreciseValue: big.NewInt(100000), |
| 1136 | }, |
| 1137 | } |
| 1138 | |
| 1139 | mock.ExpectExec(regexp.QuoteMeta(` |
| 1140 | INSERT INTO ledgerforge.balance_monitors (monitor_id, balance_id, field, operator, value, precision, precise_value, description, call_back_url, created_at) |
| 1141 | VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) |
| 1142 | `)). |
| 1143 | WithArgs(sqlmock.AnyArg(), monitor.BalanceID, monitor.Condition.Field, monitor.Condition.Operator, monitor.Condition.Value, monitor.Condition.Precision, monitor.Condition.PreciseValue.String(), monitor.Description, monitor.CallBackURL, sqlmock.AnyArg()). |
| 1144 | WillReturnResult(sqlmock.NewResult(1, 1)) |
| 1145 | |
| 1146 | createdMonitor, err := ds.CreateMonitor(monitor) |
| 1147 | assert.NoError(t, err) |
| 1148 | assert.NotEmpty(t, createdMonitor.MonitorID) |
| 1149 | assert.True(t, len(createdMonitor.MonitorID) > 0) |
| 1150 | assert.Equal(t, monitor.BalanceID, createdMonitor.BalanceID) |
| 1151 | |
| 1152 | err = mock.ExpectationsWereMet() |
| 1153 | assert.NoError(t, err) |
| 1154 | } |
| 1155 | |
| 1156 | func TestCreateMonitor_UniqueViolation(t *testing.T) { |
| 1157 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected