-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathprofile.cy.js
More file actions
151 lines (136 loc) · 4.92 KB
/
profile.cy.js
File metadata and controls
151 lines (136 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* Copyright 2026 GitProxy Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Profile Page
* Strategy: Real API for all tests.
*/
describe('Profile Page', () => {
const testUser = {
username: 'profile_testuser',
password: 'profile123',
email: 'profile_testuser@example.com',
gitAccount: 'profile_testuser',
};
const nonAdminUser = {
username: 'profile_regular',
password: 'regular123',
email: 'profile_regular@example.com',
gitAccount: 'profile_regular',
};
before(() => {
cy.login('admin', 'admin');
// Clean up stale users from previous interrupted runs before creating
cy.deleteTestUser(testUser.username);
cy.deleteTestUser(nonAdminUser.username);
cy.createUser(testUser.username, testUser.password, testUser.email, testUser.gitAccount);
cy.createUser(
nonAdminUser.username,
nonAdminUser.password,
nonAdminUser.email,
nonAdminUser.gitAccount,
);
// Verify users were created successfully
cy.request({
method: 'GET',
url: `${Cypress.config('baseUrl')}/api/v1/user/${testUser.username}`,
failOnStatusCode: false,
})
.its('status')
.should('eq', 200);
cy.request({
method: 'GET',
url: `${Cypress.config('baseUrl')}/api/v1/user/${nonAdminUser.username}`,
failOnStatusCode: false,
})
.its('status')
.should('eq', 200);
cy.logout();
});
after(() => {
cy.login('admin', 'admin');
cy.deleteTestUser(testUser.username);
cy.deleteTestUser(nonAdminUser.username);
cy.logout();
});
beforeEach(() => {
cy.login('admin', 'admin');
});
afterEach(() => {
cy.logout();
});
// --- 5.1 Displays user info ---
it('5.1 — Displays user info: name, role, email, GitHub username, admin status', () => {
cy.login('admin', 'admin');
cy.visit('/dashboard/profile');
cy.get('[data-testid="profile-name"]').should('be.visible');
cy.get('[data-testid="profile-role"]').should('be.visible');
cy.get('[data-testid="profile-email"]').should('be.visible');
cy.get('[data-testid="profile-gitAccount"]').should('be.visible');
cy.get('[data-testid="profile-admin-status"]').should('be.visible');
});
// --- 5.2 User can edit own GitHub username ---
it('5.2 — User can edit their own GitHub username', () => {
cy.login(testUser.username, testUser.password);
cy.visit('/dashboard/profile');
// Edit field and update button should be visible for own profile
cy.get('[data-testid="gitAccount-input"]').should('be.visible');
cy.get('[data-testid="update-profile-btn"]').should('be.visible');
});
// --- 5.3 Admin can edit another user's GitHub username ---
it("5.3 — Admin can edit another user's GitHub username", () => {
cy.login('admin', 'admin');
// Stub both the auth profile call (so AuthProvider/RouteGuard resolve quickly)
// and the target user API call to avoid UserProfile throwing on a real API error.
cy.intercept('GET', '**/api/auth/profile', {
statusCode: 200,
body: {
username: 'admin',
displayName: 'admin',
email: 'admin@place.com',
title: '',
gitAccount: 'none',
admin: true,
},
}).as('getAuthUser');
cy.intercept('GET', `**/api/v1/user/${testUser.username}`, {
statusCode: 200,
body: {
username: testUser.username,
displayName: 'Profile Test User',
email: testUser.email,
title: 'QA Tester',
gitAccount: testUser.gitAccount,
admin: false,
},
}).as('getUser');
cy.visit(`/dashboard/user/${testUser.username}`);
cy.wait('@getAuthUser');
cy.wait('@getUser');
// Wait for profile to render
cy.get('[data-testid="profile-name"]', { timeout: 10000 }).should('be.visible');
// Edit field and update button should be visible for admin viewing other user
cy.get('[data-testid="gitAccount-input"]').should('be.visible');
cy.get('[data-testid="update-profile-btn"]').should('be.visible');
});
// --- 5.4 Non-admin cannot edit other user ---
it("5.4 — Non-admin viewing another user's profile cannot edit", () => {
cy.login(nonAdminUser.username, nonAdminUser.password);
cy.visit(`/dashboard/user/${testUser.username}`);
// Edit field and update button should NOT be visible
cy.get('[data-testid="gitAccount-input"]').should('not.exist');
cy.get('[data-testid="update-profile-btn"]').should('not.exist');
});
});