Skip to content

Commit

Permalink
mock filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobbrewer1 committed Feb 25, 2025
1 parent ac45c52 commit e570c65
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,67 @@ func (s *newSQLPatchSuite) TestNewSQLPatch_Success() {
s.Equal([]any{1, "test"}, patch.args)
}

func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_Where() {
type testObj struct {
Id *int `db:"id_tag"`
Name *string `db:"name_tag"`
}

obj := testObj{
Id: ptr(1),
Name: ptr("test"),
}

mf := NewMockFilter(s.T())
mf.On("Where").Return("where", []any{"arg1", "arg2"})

patch := NewSQLPatch(obj, WithWhere(mf))

s.Equal([]string{"id_tag = ?", "name_tag = ?"}, patch.fields)
s.Equal([]any{1, "test"}, patch.args)
}

func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_Join() {
type testObj struct {
Id *int `db:"id_tag"`
Name *string `db:"name_tag"`
}

obj := testObj{
Id: ptr(1),
Name: ptr("test"),
}

mf := NewMockFilter(s.T())
mf.On("Join").Return("JOIN table2 ON table1.id = table2.id", nil)

patch := NewSQLPatch(obj, WithJoin(mf))

s.Equal([]string{"id_tag = ?", "name_tag = ?"}, patch.fields)
s.Equal([]any{1, "test"}, patch.args)
}

func (s *newSQLPatchSuite) TestNewSQLPatch_Success_Filter_JoinerAndWhere() {
type testObj struct {
Id *int `db:"id_tag"`
Name *string `db:"name_tag"`
}

obj := testObj{
Id: ptr(1),
Name: ptr("test"),
}

mf := NewMockFilter(s.T())
mf.On("Join").Return("JOIN table2 ON table1.id = table2.id", nil)
mf.On("Where").Return("where", []any{"arg1", "arg2"})

patch := NewSQLPatch(obj, WithFilter(mf))

s.Equal([]string{"id_tag = ?", "name_tag = ?"}, patch.fields)
s.Equal([]any{1, "test"}, patch.args)
}

func (s *newSQLPatchSuite) TestNewSQLPatch_Success_MultiFilter() {
type testObj struct {
Id *int `db:"id_tag"`
Expand Down

0 comments on commit e570c65

Please sign in to comment.