(t *testing.T)
| 821 | } |
| 822 | |
| 823 | func TestGetTransactionByRef_Success(t *testing.T) { |
| 824 | db, mock, err := sqlmock.New() |
| 825 | assert.NoError(t, err) |
| 826 | defer func() { _ = db.Close() }() |
| 827 | |
| 828 | ds := Datasource{Conn: db} |
| 829 | ctx := context.Background() |
| 830 | |
| 831 | metaData := map[string]interface{}{"key": "value"} |
| 832 | metaDataJSON, _ := json.Marshal(metaData) |
| 833 | |
| 834 | query := ` |
| 835 | SELECT transaction_id, source, reference, amount, precise_amount, currency, destination, description, status, created_at, meta_data, parent_transaction |
| 836 | FROM ledgerforge.transactions |
| 837 | WHERE reference = $1 |
| 838 | ` |
| 839 | |
| 840 | mock.ExpectQuery(regexp.QuoteMeta(query)). |
| 841 | WithArgs("ref_123"). |
| 842 | WillReturnRows(sqlmock.NewRows([]string{ |
| 843 | "transaction_id", "source", "reference", "amount", "precise_amount", "currency", |
| 844 | "destination", "description", "status", "created_at", "meta_data", "parent_transaction", |
| 845 | }).AddRow( |
| 846 | "txn_123", "bln_source", "ref_123", 1000.0, "100000", "USD", |
| 847 | "bln_dest", "Test transaction", "APPLIED", time.Now(), metaDataJSON, "", |
| 848 | )) |
| 849 | |
| 850 | txn, err := ds.GetTransactionByRef(ctx, "ref_123") |
| 851 | assert.NoError(t, err) |
| 852 | assert.Equal(t, "txn_123", txn.TransactionID) |
| 853 | assert.Equal(t, "ref_123", txn.Reference) |
| 854 | assert.Equal(t, "bln_source", txn.Source) |
| 855 | assert.Equal(t, "bln_dest", txn.Destination) |
| 856 | assert.Equal(t, "APPLIED", txn.Status) |
| 857 | assert.Equal(t, "100000", txn.PreciseAmount.String()) |
| 858 | |
| 859 | err = mock.ExpectationsWereMet() |
| 860 | assert.NoError(t, err) |
| 861 | } |
| 862 | |
| 863 | func TestGetTransactionByRef_NotFound(t *testing.T) { |
| 864 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected