MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestCreateMonitor

Function TestCreateMonitor

balance_test.go:339–361  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

337}
338
339func 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
363func TestGetMonitorByID(t *testing.T) {
364 datasource, mock, err := newTestDataSource()

Callers

nothing calls this directly

Calls 3

CreateMonitorMethod · 0.95
newTestDataSourceFunction · 0.85
NewLedgerForgeFunction · 0.85

Tested by

no test coverage detected