(t *testing.T)
| 473 | } |
| 474 | |
| 475 | func TestInflightTransaction_Commit_API(t *testing.T) { |
| 476 | router, b, err := setupRouter(t) |
| 477 | if err != nil { |
| 478 | t.Fatalf("Failed to setup router: %v", err) |
| 479 | } |
| 480 | |
| 481 | cnf, err := config.Fetch() |
| 482 | if err != nil { |
| 483 | t.Fatalf("Failed to fetch config: %v", err) |
| 484 | } |
| 485 | |
| 486 | // Determine the actual queue name the worker should listen to |
| 487 | // Assuming NumberOfQueues is 1 (default), the queue index will be 1. |
| 488 | actualTransactionQueueName := fmt.Sprintf("%s_%d", cnf.Queue.TransactionQueue, 1) |
| 489 | cleanupWorker := StartTestAsynqWorker(t, cnf, b, actualTransactionQueueName) |
| 490 | defer cleanupWorker() |
| 491 | |
| 492 | ctx := context.Background() |
| 493 | ledger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()}) |
| 494 | assert.NoError(t, err) |
| 495 | |
| 496 | sourceBalance, err := b.CreateBalance(ctx, model.Balance{LedgerID: ledger.LedgerID, Currency: "USD"}) |
| 497 | assert.NoError(t, err) |
| 498 | destBalance, err := b.CreateBalance(ctx, model.Balance{LedgerID: ledger.LedgerID, Currency: "USD"}) |
| 499 | assert.NoError(t, err) |
| 500 | |
| 501 | // 1. Create Inflight Transaction |
| 502 | inflightPayload := model2.RecordTransaction{ |
| 503 | Amount: 100.50, |
| 504 | Precision: 100, |
| 505 | Reference: "inflight_commit_" + gofakeit.UUID(), |
| 506 | Description: "Inflight for API commit test", |
| 507 | Currency: "USD", |
| 508 | Source: sourceBalance.BalanceID, |
| 509 | Destination: destBalance.BalanceID, |
| 510 | AllowOverDraft: true, |
| 511 | Inflight: true, |
| 512 | SkipQueue: false, |
| 513 | } |
| 514 | payloadBytes, _ := request.ToJsonReq(&inflightPayload) |
| 515 | var inflightTxResponse model.Transaction |
| 516 | |
| 517 | testReqInflight := TestRequest{ |
| 518 | Payload: payloadBytes, |
| 519 | Response: &inflightTxResponse, |
| 520 | Method: "POST", |
| 521 | Route: "/transactions", |
| 522 | Auth: "", |
| 523 | Router: router, |
| 524 | } |
| 525 | |
| 526 | respInflight, errInflight := SetUpTestRequest(testReqInflight) |
| 527 | assert.NoError(t, errInflight) |
| 528 | assert.Equal(t, http.StatusCreated, respInflight.Code) |
| 529 | assert.Equal(t, "QUEUED", inflightTxResponse.Status) |
| 530 | assert.True(t, inflightTxResponse.Inflight) |
| 531 | |
| 532 | ds, err := database.NewDataSource(cnf) |
nothing calls this directly
no test coverage detected