(t *testing.T)
| 166 | } |
| 167 | |
| 168 | func TestRecordTransaction(t *testing.T) { |
| 169 | router, b, err := setupRouter(t) |
| 170 | if err != nil { |
| 171 | t.Fatalf("Failed to setup router: %v", err) |
| 172 | } |
| 173 | |
| 174 | // Create ledger and balances for testing |
| 175 | newLedger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()}) |
| 176 | if err != nil { |
| 177 | t.Fatalf("Failed to create ledger: %v", err) |
| 178 | } |
| 179 | |
| 180 | newSourceBalance, err := b.CreateBalance(context.Background(), model.Balance{LedgerID: newLedger.LedgerID, Currency: "NGN"}) |
| 181 | if err != nil { |
| 182 | t.Fatalf("Failed to create source balance: %v", err) |
| 183 | } |
| 184 | |
| 185 | newDestinationBalance, err := b.CreateBalance(context.Background(), model.Balance{LedgerID: newLedger.LedgerID, Currency: "NGN"}) |
| 186 | if err != nil { |
| 187 | t.Fatalf("Failed to create destination balance: %v", err) |
| 188 | } |
| 189 | |
| 190 | tests := []struct { |
| 191 | name string |
| 192 | payload model2.RecordTransaction |
| 193 | expectedCode int |
| 194 | wantErr bool |
| 195 | }{ |
| 196 | { |
| 197 | name: "Valid Transaction", |
| 198 | payload: model2.RecordTransaction{ |
| 199 | Amount: 922337203.6854, |
| 200 | Precision: 10000000000, |
| 201 | Reference: "ref_001adcfgf", |
| 202 | Description: "For fees", |
| 203 | Currency: "NGN", |
| 204 | Source: newSourceBalance.BalanceID, |
| 205 | Destination: newDestinationBalance.BalanceID, |
| 206 | }, |
| 207 | expectedCode: http.StatusCreated, |
| 208 | wantErr: false, |
| 209 | }, |
| 210 | { |
| 211 | name: "Valid Transaction With precision 100", |
| 212 | payload: model2.RecordTransaction{ |
| 213 | Amount: 100.68, |
| 214 | Precision: 100, |
| 215 | Reference: "ref_001adcfgf", |
| 216 | Description: "For fees", |
| 217 | Currency: "NGN", |
| 218 | Source: newSourceBalance.BalanceID, |
| 219 | Destination: newDestinationBalance.BalanceID, |
| 220 | }, |
| 221 | expectedCode: http.StatusCreated, |
| 222 | wantErr: false, |
| 223 | }, |
| 224 | { |
| 225 | name: "Missing Amount", |
nothing calls this directly
no test coverage detected