MCPcopy Index your code
hub / github.com/authorizerdev/authorizer / TestUsers

Function TestUsers

internal/integration_tests/users_test.go:16–70  ·  view source on GitHub ↗

TestUsers tests the _users admin query

(t *testing.T)

Source from the content-addressed store, hash-verified

14
15// TestUsers tests the _users admin query
16func TestUsers(t *testing.T) {
17 cfg := getTestConfig()
18 ts := initTestSetup(t, cfg)
19 req, ctx := createContext(ts)
20
21 // Create test users
22 for i := 0; i < 3; i++ {
23 email := fmt.Sprintf("users_test_%s_%d@authorizer.dev", uuid.New().String(), i)
24 password := "Password@123"
25 signupReq := &model.SignUpRequest{
26 Email: &email,
27 Password: password,
28 ConfirmPassword: password,
29 }
30 _, err := ts.GraphQLProvider.SignUp(ctx, signupReq)
31 require.NoError(t, err)
32 }
33
34 t.Run("should fail without admin auth", func(t *testing.T) {
35 req.Header.Set("Cookie", "")
36 users, err := ts.GraphQLProvider.Users(ctx, &model.PaginatedRequest{})
37 assert.Error(t, err)
38 assert.Nil(t, users)
39 })
40
41 t.Run("should list users with admin auth", func(t *testing.T) {
42 h, err := crypto.EncryptPassword(cfg.AdminSecret)
43 require.NoError(t, err)
44 req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
45
46 users, err := ts.GraphQLProvider.Users(ctx, &model.PaginatedRequest{})
47 require.NoError(t, err)
48 assert.NotNil(t, users)
49 assert.GreaterOrEqual(t, len(users.Users), 3)
50 assert.NotNil(t, users.Pagination)
51 })
52
53 t.Run("should support pagination", func(t *testing.T) {
54 h, err := crypto.EncryptPassword(cfg.AdminSecret)
55 require.NoError(t, err)
56 req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AdminCookieName, h))
57
58 limit := int64(2)
59 page := int64(1)
60 users, err := ts.GraphQLProvider.Users(ctx, &model.PaginatedRequest{
61 Pagination: &model.PaginationRequest{
62 Limit: &limit,
63 Page: &page,
64 },
65 })
66 require.NoError(t, err)
67 assert.NotNil(t, users)
68 assert.LessOrEqual(t, int64(len(users.Users)), limit)
69 })
70}

Callers

nothing calls this directly

Calls 10

EncryptPasswordFunction · 0.92
getTestConfigFunction · 0.85
initTestSetupFunction · 0.85
createContextFunction · 0.85
ErrorMethod · 0.80
SignUpMethod · 0.65
SetMethod · 0.65
UsersMethod · 0.65
StringMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected