(t *testing.T)
| 337 | } |
| 338 | |
| 339 | func TestCreateMonitor(t *testing.T) { |
| 340 | datasource, mock, err := newTestDataSource() |
| 341 | if err != nil { |
| 342 | t.Fatalf("Error creating test data source: %s", err) |
| 343 | } |
| 344 | |
| 345 | d, err := NewLedgerForge(datasource) |
| 346 | if err != nil { |
| 347 | t.Fatalf("Error creating LedgerForge instance: %s", err) |
| 348 | } |
| 349 | monitor := model.BalanceMonitor{BalanceID: "test-balance", Description: "Test Monitor", CallBackURL: gofakeit.URL(), Condition: model.AlertCondition{Field: "field", Operator: "operator", Value: 1000, Precision: 100, PreciseValue: big.NewInt(100000)}} |
| 350 | |
| 351 | mock.ExpectExec("INSERT INTO ledgerforge.balance_monitors").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()).WillReturnResult(sqlmock.NewResult(1, 1)) |
| 352 | |
| 353 | result, err := d.CreateMonitor(context.Background(), monitor) |
| 354 | |
| 355 | assert.NoError(t, err) |
| 356 | assert.NotEmpty(t, result.MonitorID) |
| 357 | |
| 358 | if err := mock.ExpectationsWereMet(); err != nil { |
| 359 | t.Errorf("there were unfulfilled expectations: %s", err) |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | func TestGetMonitorByID(t *testing.T) { |
| 364 | datasource, mock, err := newTestDataSource() |
nothing calls this directly
no test coverage detected