(t *testing.T)
| 68 | } |
| 69 | |
| 70 | func TestRecordTransaction_Success(t *testing.T) { |
| 71 | db, mock, err := sqlmock.New() |
| 72 | assert.NoError(t, err) |
| 73 | defer func() { _ = db.Close() }() |
| 74 | |
| 75 | tracer := otel.Tracer("transaction.database") |
| 76 | ctx, span := tracer.Start(context.Background(), "TestRecordTransaction") |
| 77 | defer span.End() |
| 78 | |
| 79 | ds := Datasource{Conn: db} |
| 80 | |
| 81 | transaction := &model.Transaction{ |
| 82 | TransactionID: "txn123", |
| 83 | Source: "src1", |
| 84 | Reference: "ref123", |
| 85 | Amount: 1000, |
| 86 | AmountString: "1000", |
| 87 | Currency: "USD", |
| 88 | Destination: "dest1", |
| 89 | Description: "Test Transaction", |
| 90 | Status: "PENDING", |
| 91 | CreatedAt: time.Now(), |
| 92 | MetaData: map[string]interface{}{"key": "value"}, |
| 93 | ScheduledFor: time.Now(), |
| 94 | Hash: "hash123", |
| 95 | PreciseAmount: model.Int64ToBigInt(1000), |
| 96 | Precision: 2, |
| 97 | Rate: 1, |
| 98 | ParentTransaction: "parent123", |
| 99 | EffectiveDate: nil, |
| 100 | } |
| 101 | |
| 102 | metaDataJSON, err := json.Marshal(transaction.MetaData) |
| 103 | assert.NoError(t, err) |
| 104 | |
| 105 | mock.ExpectExec("INSERT INTO ledgerforge.transactions"). |
| 106 | WithArgs(transaction.TransactionID, transaction.ParentTransaction, transaction.Source, transaction.Reference, transaction.AmountString, transaction.PreciseAmount.String(), transaction.Precision, transaction.Rate, transaction.Currency, transaction.Destination, transaction.Description, transaction.Status, transaction.CreatedAt, metaDataJSON, transaction.ScheduledFor, transaction.Hash, transaction.EffectiveDate). |
| 107 | WillReturnResult(sqlmock.NewResult(1, 1)) |
| 108 | |
| 109 | result, err := ds.RecordTransaction(ctx, transaction) |
| 110 | assert.NoError(t, err) |
| 111 | assert.Equal(t, transaction, result) |
| 112 | } |
| 113 | |
| 114 | func TestRecordTransaction_Failure(t *testing.T) { |
| 115 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected