Skip to content

Commit

Permalink
Add test with filtering on nil value
Browse files Browse the repository at this point in the history
  • Loading branch information
islamaliev committed Jan 9, 2024
1 parent 9719dd9 commit a21a95c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions db/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ func (i *collectionUniqueIndex) newUniqueIndexError(
fieldVal, err := doc.GetValue(i.fieldDesc.Name)
var val any
if err != nil {
// If the error is ErrFieldNotExist, we leave `val` as is (e.g. nil)
// otherwise we return the error
if !errors.Is(err, client.ErrFieldNotExist) {
return err
}

Check warning on line 299 in db/index.go

View check run for this annotation

Codecov / codecov/patch

db/index.go#L298-L299

Added lines #L298 - L299 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,41 @@ func TestQueryWithUniqueIndex_IfNoMatch_ReturnEmptyResult(t *testing.T) {

testUtils.ExecuteTestCase(t, test)
}

func TestQueryWithUniqueIndex_WithEqualFilterOnNilValue_ShouldFetch(t *testing.T) {
test := testUtils.TestCase{
Description: "Test index filtering with _eq filter on nil value",
Actions: []any{
testUtils.SchemaUpdate{
Schema: `
type User {
name: String
age: Int @index(unique: true)
}`,
},
testUtils.CreatePredefinedDocs{
Docs: getUserDocs(),
},
testUtils.CreateDoc{
CollectionID: 0,
Doc: `
{
"name": "Alice"
}`,
},
testUtils.Request{
Request: `
query {
User(filter: {age: {_eq: null}}) {
name
}
}`,
Results: []map[string]any{
{"name": "Alice"},
},
},
},
}

testUtils.ExecuteTestCase(t, test)
}

0 comments on commit a21a95c

Please sign in to comment.