(t *testing.T)
| 691 | } |
| 692 | |
| 693 | func TestVoidInflightTransaction_Negative(t *testing.T) { |
| 694 | datasource, mock, err := newTestDataSource() |
| 695 | assert.NoError(t, err) |
| 696 | |
| 697 | d, err := NewLedgerForge(datasource) |
| 698 | assert.NoError(t, err) |
| 699 | |
| 700 | source := gofakeit.UUID() |
| 701 | destination := gofakeit.UUID() |
| 702 | metaDataJSON, _ := json.Marshal(map[string]interface{}{"key": "value"}) |
| 703 | t.Run("Transaction not in INFLIGHT status", func(t *testing.T) { |
| 704 | transactionID := gofakeit.UUID() |
| 705 | |
| 706 | mock.ExpectQuery(regexp.QuoteMeta(`SELECT transaction_id, source, reference, amount, precise_amount, precision, currency, destination, description, status, created_at, meta_data, parent_transaction, hash FROM ledgerforge.transactions WHERE transaction_id = $1`)). |
| 707 | WithArgs(transactionID). |
| 708 | WillReturnRows(sqlmock.NewRows([]string{"transaction_id", "source", "reference", "amount", "precise_amount", "precision", "currency", "destination", "description", "status", "created_at", "meta_data", "parent_transaction", "hash"}). |
| 709 | AddRow(transactionID, source, gofakeit.UUID(), 100.0, 10000, 100, "USD", destination, gofakeit.UUID(), "APPLIED", time.Now(), metaDataJSON, "", "")) |
| 710 | |
| 711 | _, err := d.VoidInflightTransaction(context.Background(), transactionID) |
| 712 | assert.Error(t, err) |
| 713 | assert.Contains(t, err.Error(), "transaction is not in inflight status") |
| 714 | }) |
| 715 | |
| 716 | t.Run("Transaction already voided", func(t *testing.T) { |
| 717 | transactionID := gofakeit.UUID() |
| 718 | |
| 719 | mock.ExpectQuery(regexp.QuoteMeta(`SELECT transaction_id, source, reference, amount, precise_amount, precision, currency, destination, description, status, created_at, meta_data, parent_transaction, hash FROM ledgerforge.transactions WHERE transaction_id = $1`)). |
| 720 | WithArgs(transactionID). |
| 721 | WillReturnRows(sqlmock.NewRows([]string{"transaction_id", "source", "reference", "amount", "precise_amount", "precision", "currency", "destination", "description", "status", "created_at", "meta_data", "parent_transaction", "hash"}). |
| 722 | AddRow(transactionID, source, gofakeit.UUID(), 100.0, 10000, 100, "USD", destination, gofakeit.UUID(), "INFLIGHT", time.Now(), metaDataJSON, "", "")) |
| 723 | |
| 724 | // Mock IsParentTransactionVoid |
| 725 | mock.ExpectQuery(regexp.QuoteMeta(`SELECT EXISTS ( SELECT 1 FROM ledgerforge.transactions WHERE parent_transaction = $1 AND status = 'VOID' )`)). |
| 726 | WithArgs(transactionID). |
| 727 | WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(true)) |
| 728 | |
| 729 | _, err := d.VoidInflightTransaction(context.Background(), transactionID) |
| 730 | assert.Error(t, err) |
| 731 | assert.Contains(t, err.Error(), "transaction has already been voided") |
| 732 | }) |
| 733 | |
| 734 | // Verify all expectations were met |
| 735 | if err := mock.ExpectationsWereMet(); err != nil { |
| 736 | t.Errorf("there were unfulfilled expectations: %s", err) |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | func TestQueueTransactionFlow(t *testing.T) { |
| 741 | // Skip in short mode as this is a long-running test |
nothing calls this directly
no test coverage detected