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

Function TestFetchTransactions_Success

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

Source from the content-addressed store, hash-verified

1973}
1974
1975func TestFetchTransactions_Success(t *testing.T) {
1976 db, mock, err := sqlmock.New()
1977 assert.NoError(t, err)
1978 defer func() { _ = db.Close() }()
1979
1980 ctx := context.Background()
1981 balanceID := "bln_test123"
1982 startTime := time.Now().Add(-24 * time.Hour)
1983 targetTime := time.Now()
1984
1985 mock.ExpectBegin()
1986 tx, err := db.Begin()
1987 assert.NoError(t, err)
1988
1989 mock.ExpectQuery(regexp.QuoteMeta(`SELECT precise_amount, source, destination, created_at,
1990 COALESCE(effective_date, created_at) as effective_date
1991 FROM ledgerforge.transactions
1992 WHERE (source = $1 OR destination = $1)
1993 AND COALESCE(effective_date, created_at) > $2
1994 AND COALESCE(effective_date, created_at) <= $3
1995 AND status = 'APPLIED'
1996 ORDER BY COALESCE(effective_date, created_at) ASC`)).
1997 WithArgs(balanceID, startTime, targetTime).
1998 WillReturnRows(sqlmock.NewRows([]string{"precise_amount", "source", "destination", "created_at", "effective_date"}).
1999 AddRow("1000", balanceID, "dest123", time.Now(), time.Now()))
2000
2001 rows, err := fetchTransactions(ctx, tx, balanceID, startTime, targetTime)
2002 assert.NoError(t, err)
2003 assert.NotNil(t, rows)
2004 _ = rows.Close()
2005}
2006
2007func TestFetchTransactions_Error(t *testing.T) {
2008 db, mock, err := sqlmock.New()

Callers

nothing calls this directly

Calls 2

fetchTransactionsFunction · 0.70
CloseMethod · 0.45

Tested by

no test coverage detected