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

Function TestInflightTransaction_Commit_API

api/transaction_api_test.go:475–588  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

473}
474
475func 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)

Callers

nothing calls this directly

Calls 11

FetchFunction · 0.92
ToJsonReqFunction · 0.92
NewDataSourceFunction · 0.92
ApplyPrecisionFunction · 0.92
setupRouterFunction · 0.85
StartTestAsynqWorkerFunction · 0.85
SetUpTestRequestFunction · 0.85
pollForTransactionStatusFunction · 0.70
CreateLedgerMethod · 0.65
CreateBalanceMethod · 0.65
GetBalanceByIDMethod · 0.65

Tested by

no test coverage detected