MCPcopy
hub / github.com/dosco/graphjin / TestGraphQLRoleQueryDefaultsToUser

Function TestGraphQLRoleQueryDefaultsToUser

core/role_query_graphql_test.go:35–66  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func TestGraphQLRoleQueryDefaultsToUser(t *testing.T) {
36 db := newGraphQLRoleTestDB(t)
37 defer db.Close() //nolint:errcheck
38
39 conf := graphQLRoleTestConfig()
40 gj, err := core.NewGraphJin(conf, db)
41 if err != nil {
42 t.Fatal(err)
43 }
44 defer gj.Close()
45
46 tests := []struct {
47 name string
48 userID int
49 }{
50 {name: "row does not match", userID: 20},
51 {name: "returned role name is not special", userID: 30},
52 {name: "no row", userID: 999},
53 }
54 for _, tt := range tests {
55 t.Run(tt.name, func(t *testing.T) {
56 ctx := context.WithValue(context.Background(), core.UserIDKey, tt.userID)
57 res, err := gj.GraphQL(ctx, `{ users(id: 20) { id email } }`, nil, nil)
58 if err != nil {
59 t.Fatal(err)
60 }
61 if got := res.Role(); got != "user" {
62 t.Fatalf("role = %q, want user", got)
63 }
64 })
65 }
66}
67
68func TestGraphQLRoleQueryMultipleRowsError(t *testing.T) {
69 db := newGraphQLRoleTestDB(t)

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
GraphQLMethod · 0.95
newGraphQLRoleTestDBFunction · 0.85
graphQLRoleTestConfigFunction · 0.85
RoleMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected