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

Function TestUpdateBalanceMonitor

api/balance_api_test.go:361–414  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

359}
360
361func TestUpdateBalanceMonitor(t *testing.T) {
362 router, b, err := setupRouter(t)
363 if err != nil {
364 t.Fatalf("Failed to setup router: %v", err)
365 }
366
367 newLedger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()})
368 if err != nil {
369 t.Fatalf("Failed to create ledger: %v", err)
370 }
371
372 newBalance, err := b.CreateBalance(context.Background(), model.Balance{
373 LedgerID: newLedger.LedgerID,
374 Currency: gofakeit.CurrencyShort(),
375 })
376 if err != nil {
377 t.Fatalf("Failed to create balance: %v", err)
378 }
379
380 newMonitor, err := b.CreateMonitor(context.Background(), model.BalanceMonitor{
381 BalanceID: newBalance.BalanceID,
382 Condition: model.AlertCondition{
383 Field: "balance",
384 Operator: ">",
385 Value: 1000,
386 },
387 })
388 if err != nil {
389 t.Fatalf("Failed to create monitor: %v", err)
390 }
391
392 updatedMonitor := model.BalanceMonitor{
393 BalanceID: newBalance.BalanceID,
394 Condition: model.AlertCondition{
395 Field: "balance",
396 Operator: ">",
397 Value: 2000,
398 },
399 }
400 payloadBytes, _ := request.ToJsonReq(&updatedMonitor)
401
402 var response map[string]interface{}
403 testRequest := TestRequest{
404 Payload: payloadBytes,
405 Response: &response,
406 Method: "PUT",
407 Route: fmt.Sprintf("/balance-monitors/%s", newMonitor.MonitorID),
408 Auth: "",
409 Router: router,
410 }
411
412 resp, _ := SetUpTestRequest(testRequest)
413 assert.Equal(t, http.StatusOK, resp.Code)
414}

Callers

nothing calls this directly

Calls 6

ToJsonReqFunction · 0.92
setupRouterFunction · 0.85
SetUpTestRequestFunction · 0.85
CreateLedgerMethod · 0.65
CreateBalanceMethod · 0.65
CreateMonitorMethod · 0.65

Tested by

no test coverage detected