MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestFetchTransactions_Error

Function TestFetchTransactions_Error

database/balance_test.go:2007–2038  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2005}
2006
2007func 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
2040func TestApplyTransaction_Debit(t *testing.T) {
2041 balanceID := "bln_test123"

Callers

nothing calls this directly

Calls 3

fetchTransactionsFunction · 0.70
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected