(t *testing.T)
| 265 | } |
| 266 | |
| 267 | func TestRecordTransactionWithRate(t *testing.T) { |
| 268 | cnf := &config.Configuration{ |
| 269 | Redis: config.RedisConfig{ |
| 270 | Dns: "localhost:6379", |
| 271 | }, |
| 272 | Queue: config.QueueConfig{ |
| 273 | WebhookQueue: "webhook_queue", |
| 274 | TransactionQueue: "transaction_queue", |
| 275 | NumberOfQueues: 1, |
| 276 | }, |
| 277 | Server: config.ServerConfig{SecretKey: "some-secret"}, |
| 278 | AccountNumberGeneration: config.AccountNumberGenerationConfig{ |
| 279 | HttpService: config.AccountGenerationHttpService{ |
| 280 | Url: "http://example.com/generateAccount", |
| 281 | }, |
| 282 | }, |
| 283 | } |
| 284 | |
| 285 | config.ConfigStore.Store(cnf) |
| 286 | datasource, mock, err := newTestDataSource() |
| 287 | assert.NoError(t, err) |
| 288 | |
| 289 | // Important: Set ExpectationsWereMet to ensure execution occurs in order of appearance |
| 290 | mock.MatchExpectationsInOrder(false) |
| 291 | |
| 292 | d, err := NewLedgerForge(datasource) |
| 293 | assert.NoError(t, err) |
| 294 | |
| 295 | // Use fixed UUIDs for better predictability |
| 296 | source := "source-balance-id-123" |
| 297 | destination := "destination-balance-id-456" |
| 298 | reference := "transaction-reference-789" |
| 299 | |
| 300 | txn := &model.Transaction{ |
| 301 | Reference: reference, |
| 302 | Source: source, |
| 303 | Destination: destination, |
| 304 | Amount: 1000000, |
| 305 | Rate: 1300, |
| 306 | AllowOverdraft: true, |
| 307 | Precision: 100, |
| 308 | Currency: "NGN", |
| 309 | } |
| 310 | |
| 311 | // First, check if transaction exists |
| 312 | mock.ExpectQuery(regexp.QuoteMeta(` |
| 313 | SELECT EXISTS(SELECT 1 FROM ledgerforge.transactions WHERE reference = $1) |
| 314 | `)).WithArgs(txn.Reference).WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(false)) |
| 315 | |
| 316 | // Set up source balance response - Note this is USD |
| 317 | 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"}). |
| 318 | AddRow(source, "", "USD", 1, "ledger-id-source", 0, 0, 0, 0, 0, 0, time.Now(), 0, false, "FIFO", "") |
| 319 | |
| 320 | // Set up destination balance response - This is NGN |
| 321 | 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"}). |
| 322 | AddRow(destination, "", "NGN", 1, "ledger-id-destination", 0, 0, 0, 0, 0, 0, time.Now(), 0, false, "FIFO", "") |
| 323 | |
| 324 | balanceQuery := `SELECT 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, COALESCE\(allocation_strategy, 'FIFO'\) as allocation_strategy, COALESCE\(identity_id, ''\) as identity_id FROM ledgerforge.balances WHERE balance_id = \$1` |
nothing calls this directly
no test coverage detected