(t *testing.T)
| 189 | } |
| 190 | |
| 191 | func TestCreateBalanceMonitor(t *testing.T) { |
| 192 | router, b, err := setupRouter(t) |
| 193 | if err != nil { |
| 194 | t.Fatalf("Failed to setup router: %v", err) |
| 195 | } |
| 196 | |
| 197 | newLedger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()}) |
| 198 | if err != nil { |
| 199 | t.Fatalf("Failed to create ledger: %v", err) |
| 200 | } |
| 201 | |
| 202 | newBalance, err := b.CreateBalance(context.Background(), model.Balance{ |
| 203 | LedgerID: newLedger.LedgerID, |
| 204 | Currency: gofakeit.CurrencyShort(), |
| 205 | }) |
| 206 | if err != nil { |
| 207 | t.Fatalf("Failed to create balance: %v", err) |
| 208 | } |
| 209 | |
| 210 | tests := []struct { |
| 211 | name string |
| 212 | payload model2.CreateBalanceMonitor |
| 213 | expectedCode int |
| 214 | }{ |
| 215 | { |
| 216 | name: "Valid Balance Monitor", |
| 217 | payload: model2.CreateBalanceMonitor{ |
| 218 | BalanceId: newBalance.BalanceID, |
| 219 | Condition: model2.MonitorCondition{ |
| 220 | Field: "balance", |
| 221 | Operator: ">", |
| 222 | Value: 1000, |
| 223 | Precision: 100, |
| 224 | }, |
| 225 | }, |
| 226 | expectedCode: http.StatusCreated, |
| 227 | }, |
| 228 | { |
| 229 | name: "Missing Balance ID", |
| 230 | payload: model2.CreateBalanceMonitor{ |
| 231 | Condition: model2.MonitorCondition{ |
| 232 | Field: "balance", |
| 233 | Operator: ">", |
| 234 | Value: 1000, |
| 235 | Precision: 100, |
| 236 | }, |
| 237 | }, |
| 238 | expectedCode: http.StatusBadRequest, |
| 239 | }, |
| 240 | } |
| 241 | |
| 242 | for _, tt := range tests { |
| 243 | t.Run(tt.name, func(t *testing.T) { |
| 244 | payloadBytes, _ := request.ToJsonReq(&tt.payload) |
| 245 | var response model.BalanceMonitor |
| 246 | testRequest := TestRequest{ |
| 247 | Payload: payloadBytes, |
| 248 | Response: &response, |
nothing calls this directly
no test coverage detected