Skip to content

Commit

Permalink
tests: AttrIsID
Browse files Browse the repository at this point in the history
  • Loading branch information
mjarkk committed Oct 17, 2021
1 parent ef91dc4 commit 4999b09
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
22 changes: 19 additions & 3 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,35 @@ func (TestCheckMethodsData) ResolveBanana(in struct{}) (string, error) {
func (TestCheckMethodsData) ResolvePeer(in struct{}) string {
return ""
}
func (TestCheckMethodsData) ResolveId(in struct{}) (int, AttrIsID) {
return 0, 0
}

func TestCheckMethods(t *testing.T) {
ctx := newParseCtx()
ref, err := ctx.check(reflect.TypeOf(TestCheckMethodsData{}), false)
a.Nil(t, err)
obj := ctx.schema.types[ref.typeName]

_, ok := obj.objContents[getObjKey([]byte("name"))]
field, ok := obj.objContents[getObjKey([]byte("name"))]
a.True(t, ok)
a.False(t, field.isID)
a.Nil(t, field.method.errorOutNr)

field, ok = obj.objContents[getObjKey([]byte("banana"))]
a.True(t, ok)
_, ok = obj.objContents[getObjKey([]byte("banana"))]
a.False(t, field.isID)
a.NotNil(t, field.method.errorOutNr)

field, ok = obj.objContents[getObjKey([]byte("peer"))]
a.True(t, ok)
_, ok = obj.objContents[getObjKey([]byte("peer"))]
a.False(t, field.isID)
a.Nil(t, field.method.errorOutNr)

field, ok = obj.objContents[getObjKey([]byte("id"))]
a.True(t, ok)
a.True(t, field.isID)
a.Nil(t, field.method.errorOutNr)
}

type TestCheckMethodsFailData1 struct{}
Expand Down
17 changes: 17 additions & 0 deletions resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1830,3 +1830,20 @@ func TestBytecodeResolveQueryCache(t *testing.T) {
}
}
}

type TestBytecodeResolveIDData struct {
DirectId int `gq:",id"`
MethodId func() (int, AttrIsID)
}

func TestBytecodeResolveID(t *testing.T) {
schema := TestBytecodeResolveIDData{
DirectId: 2,
MethodId: func() (int, AttrIsID) {
return 3, 0
},
}
query := `{directId,methodId}`
out := bytecodeParseAndExpectNoErrs(t, query, schema, M{})
a.Equal(t, `{"directId":"2","methodId":"3"}`, out)
}

0 comments on commit 4999b09

Please sign in to comment.