MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / TestProfile

Function TestProfile

internal/integration_tests/profile_test.go:16–90  ·  view source on GitHub ↗

TestProfile tests the profile functionality

(t *testing.T)

Source from the content-addressed store, hash-verified

14
15// TestProfile tests the profile functionality
16func TestProfile(t *testing.T) {
17 // Initialize test setup
18 cfg := getTestConfig()
19 ts := initTestSetup(t, cfg)
20 req, ctx := createContext(ts)
21
22 // Test setup - create a test user
23 email := "profile_test_" + uuid.New().String() + "@authorizer.dev"
24 password := "Password@123"
25
26 signupReq := &model.SignUpRequest{
27 Email: &email,
28 Password: password,
29 ConfirmPassword: password,
30 }
31 res, err := ts.GraphQLProvider.SignUp(ctx, signupReq)
32 assert.NoError(t, err)
33 assert.NotNil(t, res)
34
35 // Profile tests
36 t.Run("after login", func(t *testing.T) {
37 loginReq := &model.LoginRequest{
38 Email: &email,
39 Password: password,
40 }
41 loginRes, err := ts.GraphQLProvider.Login(ctx, loginReq)
42 assert.NoError(t, err)
43 assert.NotNil(t, loginRes)
44
45 // Verify response contains expected tokens
46 assert.NotEmpty(t, loginRes.AccessToken)
47 assert.NotNil(t, loginRes.User)
48 assert.Equal(t, email, *loginRes.User.Email)
49 assert.True(t, loginRes.User.EmailVerified)
50
51 t.Run("should fail without cookie and authorization header", func(t *testing.T) {
52 res, err := ts.GraphQLProvider.Profile(ctx)
53 assert.Error(t, err)
54 assert.Nil(t, res)
55 })
56
57 t.Run("should return profile with browser session", func(t *testing.T) {
58 sessionToken := latestAppSessionCookie(ts)
59 require.NotEmpty(t, sessionToken)
60 req.Header.Set("Cookie", fmt.Sprintf("%s=%s", constants.AppCookieName+"_session", sessionToken))
61 defer func() {
62 req.Header.Del("Cookie")
63 }()
64 res, err := ts.GraphQLProvider.Profile(ctx)
65 require.NoError(t, err)
66 require.NotNil(t, res)
67 assert.Equal(t, email, *res.Email)
68 })
69
70 t.Run("should return profile with authorization header", func(t *testing.T) {
71 allData, err := ts.MemoryStoreProvider.GetAllData()
72 require.NoError(t, err)
73 accessToken := ""

Callers

nothing calls this directly

Calls 13

getTestConfigFunction · 0.85
initTestSetupFunction · 0.85
createContextFunction · 0.85
latestAppSessionCookieFunction · 0.85
ErrorMethod · 0.80
DelMethod · 0.80
SignUpMethod · 0.65
LoginMethod · 0.65
ProfileMethod · 0.65
SetMethod · 0.65
GetAllDataMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected