(t *testing.T)
| 32 | ) |
| 33 | |
| 34 | func TestCreateBalance(t *testing.T) { |
| 35 | router, b, err := setupRouter(t) |
| 36 | if err != nil { |
| 37 | t.Fatalf("Failed to setup router: %v", err) |
| 38 | } |
| 39 | |
| 40 | // Create a ledger for positive test case |
| 41 | newLedger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()}) |
| 42 | if err != nil { |
| 43 | t.Fatalf("Failed to create ledger: %v", err) |
| 44 | } |
| 45 | |
| 46 | tests := []struct { |
| 47 | name string |
| 48 | payload model2.CreateBalance |
| 49 | expectedCode int |
| 50 | wantErr bool |
| 51 | }{ |
| 52 | { |
| 53 | name: "Valid Balance", |
| 54 | payload: model2.CreateBalance{ |
| 55 | LedgerId: newLedger.LedgerID, |
| 56 | Currency: gofakeit.Currency().Short, |
| 57 | }, |
| 58 | expectedCode: http.StatusCreated, |
| 59 | wantErr: false, |
| 60 | }, |
| 61 | { |
| 62 | name: "Missing Ledger ID", |
| 63 | payload: model2.CreateBalance{ |
| 64 | Currency: gofakeit.Currency().Short, |
| 65 | }, |
| 66 | expectedCode: http.StatusBadRequest, |
| 67 | wantErr: false, |
| 68 | }, |
| 69 | { |
| 70 | name: "Missing Currency", |
| 71 | payload: model2.CreateBalance{ |
| 72 | LedgerId: newLedger.LedgerID, |
| 73 | }, |
| 74 | expectedCode: http.StatusBadRequest, |
| 75 | wantErr: false, |
| 76 | }, |
| 77 | } |
| 78 | |
| 79 | for _, tt := range tests { |
| 80 | t.Run(tt.name, func(t *testing.T) { |
| 81 | payloadBytes, _ := request.ToJsonReq(&tt.payload) |
| 82 | var response model.Balance |
| 83 | testRequest := TestRequest{ |
| 84 | Payload: payloadBytes, |
| 85 | Response: &response, |
| 86 | Method: "POST", |
| 87 | Route: "/balances", |
| 88 | Auth: "", |
| 89 | Router: router, |
| 90 | } |
| 91 |
nothing calls this directly
no test coverage detected