(t *testing.T)
| 118 | } |
| 119 | |
| 120 | func TestRecordTransaction(t *testing.T) { |
| 121 | cnf := &config.Configuration{ |
| 122 | Redis: config.RedisConfig{ |
| 123 | Dns: "localhost:6379", |
| 124 | }, |
| 125 | Queue: config.QueueConfig{ |
| 126 | WebhookQueue: "webhook_queue", |
| 127 | TransactionQueue: "transaction_queue", |
| 128 | IndexQueue: "index_queue", |
| 129 | NumberOfQueues: 1, |
| 130 | }, |
| 131 | Server: config.ServerConfig{SecretKey: "some-secret"}, |
| 132 | AccountNumberGeneration: config.AccountNumberGenerationConfig{ |
| 133 | HttpService: config.AccountGenerationHttpService{ |
| 134 | Url: "http://example.com/generateAccount", |
| 135 | }, |
| 136 | }, |
| 137 | } |
| 138 | |
| 139 | config.ConfigStore.Store(cnf) |
| 140 | datasource, mock, err := newTestDataSource() |
| 141 | assert.NoError(t, err) |
| 142 | |
| 143 | // Important: Set ExpectationsWereMet to ensure execution occurs in order of appearance |
| 144 | mock.MatchExpectationsInOrder(false) |
| 145 | |
| 146 | d, err := NewLedgerForge(datasource) |
| 147 | assert.NoError(t, err) |
| 148 | |
| 149 | // Use fixed UUIDs for better predictability |
| 150 | source := "source-balance-id-123" |
| 151 | destination := "destination-balance-id-456" |
| 152 | reference := "transaction-reference-789" |
| 153 | |
| 154 | txn := &model.Transaction{ |
| 155 | Reference: reference, |
| 156 | Source: source, |
| 157 | Destination: destination, |
| 158 | Rate: 1, |
| 159 | Amount: 10, |
| 160 | AllowOverdraft: false, |
| 161 | Precision: 100, |
| 162 | Currency: "NGN", |
| 163 | } |
| 164 | |
| 165 | // First, check if transaction exists |
| 166 | mock.ExpectQuery(regexp.QuoteMeta(` |
| 167 | SELECT EXISTS(SELECT 1 FROM ledgerforge.transactions WHERE reference = $1) |
| 168 | `)).WithArgs(txn.Reference).WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(false)) |
| 169 | |
| 170 | // Set up source balance response |
| 171 | sourceBalanceRows := sqlmock.NewRows([]string{"balance_id", "indicator", "currency", "currency_multiplier", "ledger_id", "balance", "credit_balance", "debit_balance", "inflight_balance", "inflight_credit_balance", "inflight_debit_balance", "created_at", "version", "track_fund_lineage", "allocation_strategy", "identity_id"}). |
| 172 | AddRow(source, "NGN", "", 1, "ledger-id-source", int64(10000), int64(10000), 0, 0, 0, 0, time.Now(), 0, false, "FIFO", "") |
| 173 | |
| 174 | // Set up destination balance response |
| 175 | destinationBalanceRows := sqlmock.NewRows([]string{"balance_id", "indicator", "currency", "currency_multiplier", "ledger_id", "balance", "credit_balance", "debit_balance", "inflight_balance", "inflight_credit_balance", "inflight_debit_balance", "created_at", "version", "track_fund_lineage", "allocation_strategy", "identity_id"}). |
| 176 | AddRow(destination, "", "NGN", 1, "ledger-id-destination", 0, 0, 0, 0, 0, 0, time.Now(), 0, false, "FIFO", "") |
| 177 |
nothing calls this directly
no test coverage detected