(t *testing.T)
| 112 | } |
| 113 | |
| 114 | func TestRecordTransaction_Failure(t *testing.T) { |
| 115 | db, mock, err := sqlmock.New() |
| 116 | assert.NoError(t, err) |
| 117 | defer func() { _ = db.Close() }() |
| 118 | |
| 119 | tracer := otel.Tracer("transaction.database") |
| 120 | ctx, span := tracer.Start(context.Background(), "TestRecordTransactionFailure") |
| 121 | defer span.End() |
| 122 | |
| 123 | ds := Datasource{Conn: db} |
| 124 | |
| 125 | transaction := &model.Transaction{ |
| 126 | TransactionID: "txn123", |
| 127 | Source: "src1", |
| 128 | Reference: "ref123", |
| 129 | Amount: 1000, |
| 130 | Currency: "USD", |
| 131 | Destination: "dest1", |
| 132 | Description: "Test Transaction", |
| 133 | Status: "PENDING", |
| 134 | CreatedAt: time.Now(), |
| 135 | MetaData: map[string]interface{}{"key": "value"}, |
| 136 | ScheduledFor: time.Now(), |
| 137 | Hash: "hash123", |
| 138 | PreciseAmount: model.Int64ToBigInt(1000), |
| 139 | Precision: 2, |
| 140 | Rate: 1, |
| 141 | ParentTransaction: "parent123", |
| 142 | EffectiveDate: nil, |
| 143 | } |
| 144 | |
| 145 | metaDataJSON, err := json.Marshal(transaction.MetaData) |
| 146 | assert.NoError(t, err) |
| 147 | |
| 148 | mock.ExpectExec("INSERT INTO ledgerforge.transactions"). |
| 149 | WithArgs(transaction.TransactionID, transaction.ParentTransaction, transaction.Source, transaction.Reference, transaction.Amount, transaction.PreciseAmount.String(), transaction.Precision, transaction.Rate, transaction.Currency, transaction.Destination, transaction.Description, transaction.Status, transaction.CreatedAt, metaDataJSON, transaction.ScheduledFor, transaction.Hash, transaction.EffectiveDate). |
| 150 | WillReturnError(errors.New("db error")) |
| 151 | |
| 152 | _, err = ds.RecordTransaction(ctx, transaction) |
| 153 | assert.Error(t, err) |
| 154 | assert.IsType(t, apierror.APIError{}, err) |
| 155 | } |
| 156 | |
| 157 | func TestGetTransaction_Success(t *testing.T) { |
| 158 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected