(t *testing.T)
| 588 | } |
| 589 | |
| 590 | func TestInflightTransaction_Void_API(t *testing.T) { |
| 591 | router, b, err := setupRouter(t) |
| 592 | if err != nil { |
| 593 | t.Fatalf("Failed to setup router: %v", err) |
| 594 | } |
| 595 | |
| 596 | ctx := context.Background() |
| 597 | ledger, err := b.CreateLedger(model.Ledger{Name: gofakeit.Name()}) |
| 598 | assert.NoError(t, err) |
| 599 | |
| 600 | sourceBalance, err := b.CreateBalance(ctx, model.Balance{LedgerID: ledger.LedgerID, Currency: "EUR"}) |
| 601 | assert.NoError(t, err) |
| 602 | destBalance, err := b.CreateBalance(ctx, model.Balance{LedgerID: ledger.LedgerID, Currency: "EUR"}) |
| 603 | assert.NoError(t, err) |
| 604 | |
| 605 | // 1. Create Inflight Transaction |
| 606 | inflightPayload := model2.RecordTransaction{ |
| 607 | Amount: 250.75, |
| 608 | Precision: 100, |
| 609 | Reference: "inflight_void_" + gofakeit.UUID(), |
| 610 | Description: "Inflight for API void test", |
| 611 | Currency: "EUR", |
| 612 | Source: sourceBalance.BalanceID, |
| 613 | Destination: destBalance.BalanceID, |
| 614 | AllowOverDraft: true, |
| 615 | Inflight: true, |
| 616 | SkipQueue: true, // To process it synchronously as inflight |
| 617 | } |
| 618 | payloadBytes, _ := request.ToJsonReq(&inflightPayload) |
| 619 | var inflightTxResponse model.Transaction |
| 620 | |
| 621 | testReqInflight := TestRequest{ |
| 622 | Payload: payloadBytes, |
| 623 | Response: &inflightTxResponse, |
| 624 | Method: "POST", |
| 625 | Route: "/transactions", |
| 626 | Auth: "", |
| 627 | Router: router, |
| 628 | } |
| 629 | |
| 630 | respInflight, errInflight := SetUpTestRequest(testReqInflight) |
| 631 | assert.NoError(t, errInflight) |
| 632 | assert.Equal(t, http.StatusCreated, respInflight.Code) |
| 633 | assert.Equal(t, "INFLIGHT", inflightTxResponse.Status) |
| 634 | assert.True(t, inflightTxResponse.Inflight) |
| 635 | |
| 636 | // 2. Verify Initial Balances (Inflight) |
| 637 | sbAfterInflight, _ := b.GetBalanceByID(ctx, sourceBalance.BalanceID, nil, false) |
| 638 | dbAfterInflight, _ := b.GetBalanceByID(ctx, destBalance.BalanceID, nil, false) |
| 639 | |
| 640 | expectedInflightDebit := model.ApplyPrecision(&model.Transaction{Amount: inflightPayload.Amount, Precision: inflightPayload.Precision}) |
| 641 | expectedInflightCredit := model.ApplyPrecision(&model.Transaction{Amount: inflightPayload.Amount, Precision: inflightPayload.Precision}) |
| 642 | |
| 643 | assert.Equal(t, int64(0), sbAfterInflight.Balance.Int64(), "Source balance should be 0 before void") |
| 644 | assert.Equal(t, expectedInflightDebit.Neg(expectedInflightDebit).String(), sbAfterInflight.InflightBalance.String(), "Source inflight balance incorrect") |
| 645 | assert.Equal(t, int64(0), dbAfterInflight.Balance.Int64(), "Destination balance should be 0 before void") |
| 646 | assert.Equal(t, expectedInflightCredit.String(), dbAfterInflight.InflightBalance.String(), "Destination inflight balance incorrect") |
| 647 |
nothing calls this directly
no test coverage detected