(t *testing.T)
| 33 | } |
| 34 | |
| 35 | func 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 | |
| 68 | func TestGraphQLRoleQueryMultipleRowsError(t *testing.T) { |
| 69 | db := newGraphQLRoleTestDB(t) |
nothing calls this directly
no test coverage detected