Skip to content

Commit 94de0fd

Browse files
committed
test: add coverage for OR clause condition
1 parent dcd46e6 commit 94de0fd

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tests/query_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3639,13 +3639,16 @@ func (s *QueryTestSuite) TestWithNesting() {
36393639
func (s *QueryTestSuite) TestJsonWhereClauses() {
36403640
mockApp := mocksfoundation.NewApplication(s.T())
36413641
mockJson := mocksfoundation.NewJson(s.T())
3642-
mockJson.EXPECT().Marshal("abc").RunAndReturn(func(i interface{}) ([]byte, error) {
3642+
mockJson.EXPECT().Marshal("abc").RunAndReturn(func(i any) ([]byte, error) {
36433643
return json.Marshal(i)
36443644
}).Times(4)
3645-
mockJson.EXPECT().Marshal([]string{"abc", "def"}).RunAndReturn(func(i interface{}) ([]byte, error) {
3645+
mockJson.EXPECT().Marshal("ghi").RunAndReturn(func(i any) ([]byte, error) {
36463646
return json.Marshal(i)
36473647
}).Twice()
3648-
mockApp.EXPECT().GetJson().Return(mockJson).Times(6)
3648+
mockJson.EXPECT().Marshal([]string{"abc", "def"}).RunAndReturn(func(i any) ([]byte, error) {
3649+
return json.Marshal(i)
3650+
}).Twice()
3651+
mockApp.EXPECT().GetJson().Return(mockJson).Times(8)
36493652

36503653
for driver, query := range s.queries {
36513654
s.Run(driver, func() {
@@ -3820,6 +3823,24 @@ func (s *QueryTestSuite) TestJsonWhereClauses() {
38203823
s.JSONEq(data[1].Data, items[1].Data)
38213824
},
38223825
},
3826+
{
3827+
name: "string or float key",
3828+
find: query.Query().Where("data->string", "first").OrWhere("data->float", 789.123).Find,
3829+
assert: func(items []JsonData) {
3830+
s.Len(items, 2)
3831+
s.JSONEq(data[0].Data, items[0].Data)
3832+
s.JSONEq(data[1].Data, items[1].Data)
3833+
},
3834+
},
3835+
{
3836+
name: "contains or key does not exist",
3837+
find: query.Query().WhereJsonContains("data->array", "ghi").OrWhereJsonDoesntContainKey("data->nested->string").Find,
3838+
assert: func(items []JsonData) {
3839+
s.Len(items, 2)
3840+
s.JSONEq(data[0].Data, items[0].Data)
3841+
s.JSONEq(data[1].Data, items[1].Data)
3842+
},
3843+
},
38233844
}
38243845

38253846
for _, test := range tests {

0 commit comments

Comments
 (0)