(t *testing.T)
| 2005 | } |
| 2006 | |
| 2007 | func TestFetchTransactions_Error(t *testing.T) { |
| 2008 | db, mock, err := sqlmock.New() |
| 2009 | assert.NoError(t, err) |
| 2010 | defer func() { _ = db.Close() }() |
| 2011 | |
| 2012 | ctx := context.Background() |
| 2013 | balanceID := "bln_test123" |
| 2014 | startTime := time.Now().Add(-24 * time.Hour) |
| 2015 | targetTime := time.Now() |
| 2016 | |
| 2017 | mock.ExpectBegin() |
| 2018 | tx, err := db.Begin() |
| 2019 | assert.NoError(t, err) |
| 2020 | |
| 2021 | mock.ExpectQuery(regexp.QuoteMeta(`SELECT precise_amount, source, destination, created_at, |
| 2022 | COALESCE(effective_date, created_at) as effective_date |
| 2023 | FROM ledgerforge.transactions |
| 2024 | WHERE (source = $1 OR destination = $1) |
| 2025 | AND COALESCE(effective_date, created_at) > $2 |
| 2026 | AND COALESCE(effective_date, created_at) <= $3 |
| 2027 | AND status = 'APPLIED' |
| 2028 | ORDER BY COALESCE(effective_date, created_at) ASC`)). |
| 2029 | WithArgs(balanceID, startTime, targetTime). |
| 2030 | WillReturnError(sql.ErrConnDone) |
| 2031 | |
| 2032 | rows, err := fetchTransactions(ctx, tx, balanceID, startTime, targetTime) |
| 2033 | assert.Error(t, err) |
| 2034 | assert.Nil(t, rows) |
| 2035 | apiErr, ok := err.(apierror.APIError) |
| 2036 | assert.True(t, ok) |
| 2037 | assert.Equal(t, apierror.ErrInternalServer, apiErr.Code) |
| 2038 | } |
| 2039 | |
| 2040 | func TestApplyTransaction_Debit(t *testing.T) { |
| 2041 | balanceID := "bln_test123" |
nothing calls this directly
no test coverage detected