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

Function TestGetTransactionByRef_NotFound

database/transactions_test.go:863–890  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

861}
862
863func 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
892func TestGetTransactionByRef_QueryError(t *testing.T) {
893 db, mock, err := sqlmock.New()

Callers

nothing calls this directly

Calls 3

GetTransactionByRefMethod · 0.95
CloseMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected