(t *testing.T)
| 861 | } |
| 862 | |
| 863 | func TestGetTransactionByRef_NotFound(t *testing.T) { |
| 864 | db, mock, err := sqlmock.New() |
| 865 | assert.NoError(t, err) |
| 866 | defer func() { _ = db.Close() }() |
| 867 | |
| 868 | ds := Datasource{Conn: db} |
| 869 | ctx := context.Background() |
| 870 | |
| 871 | query := ` |
| 872 | SELECT transaction_id, source, reference, amount, precise_amount, currency, destination, description, status, created_at, meta_data, parent_transaction |
| 873 | FROM ledgerforge.transactions |
| 874 | WHERE reference = $1 |
| 875 | ` |
| 876 | |
| 877 | mock.ExpectQuery(regexp.QuoteMeta(query)). |
| 878 | WithArgs("nonexistent_ref"). |
| 879 | WillReturnError(sql.ErrNoRows) |
| 880 | |
| 881 | txn, err := ds.GetTransactionByRef(ctx, "nonexistent_ref") |
| 882 | assert.Error(t, err) |
| 883 | assert.Equal(t, "", txn.TransactionID) |
| 884 | apiErr, ok := err.(apierror.APIError) |
| 885 | assert.True(t, ok) |
| 886 | assert.Equal(t, apierror.ErrNotFound, apiErr.Code) |
| 887 | |
| 888 | err = mock.ExpectationsWereMet() |
| 889 | assert.NoError(t, err) |
| 890 | } |
| 891 | |
| 892 | func TestGetTransactionByRef_QueryError(t *testing.T) { |
| 893 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected