1+ import { STRAPI_ADMIN_ROLES } from './utils'
2+
13const ADMIN_CREDENTIALS = {
2435 password : 'password' ,
46}
57
6- const _USER_WITHOUT_ACCESS = {
7- username : 'user_without_access' ,
8- 9- password : 'strapiPassword' ,
10- }
11-
128describe ( 'wip test refactor' , ( ) => {
139 // JWT token for admin panel operations (creating users, roles, permissions)
1410 let adminToken
@@ -21,16 +17,20 @@ describe('wip test refactor', () => {
2117 const uniqueEmail = `test.user.${ timestamp } @example.com`
2218 const uniqueRoleName = `Content Manager ${ timestamp } `
2319
24- before ( ( ) => {
25- // Login as admin to get JWT token for admin panel operations
26- cy . request ( {
20+ const loginAsAdmin = ( email , password ) => {
21+ return cy . request ( {
2722 method : 'POST' ,
2823 url : 'http://localhost:1337/admin/login' ,
2924 body : {
30- email : ADMIN_CREDENTIALS . email ,
31- password : ADMIN_CREDENTIALS . password ,
25+ email,
26+ password,
3227 } ,
3328 } )
29+ }
30+
31+ before ( ( ) => {
32+ // Login as admin to get JWT token for admin panel operations
33+ loginAsAdmin ( ADMIN_CREDENTIALS . email , ADMIN_CREDENTIALS . password )
3434 . then ( response => {
3535 expect ( response . status ) . to . eq ( 200 )
3636 adminToken = response . body . data . token
@@ -59,102 +59,153 @@ describe('wip test refactor', () => {
5959 } )
6060 } )
6161
62- it ( 'should be able to create a new admin user with admin token' , ( ) => {
63- // Create a new admin user using the admin JWT token
64- cy . request ( {
65- method : 'POST' ,
66- url : 'http://localhost:1337/admin/users' ,
67- headers : {
68- Authorization : `Bearer ${ adminToken } ` ,
69- } ,
70- body : {
71- firstname : 'Test' ,
72- lastname : 'User' ,
73- email : uniqueEmail ,
74- roles : [ 2 ] , // Editor role
75- } ,
76- } ) . then ( response => {
77- expect ( response . status ) . to . eq ( 201 )
78- expect ( response . body . data ) . to . have . property ( 'id' )
79- expect ( response . body . data . email ) . to . eq ( uniqueEmail )
80- expect ( response . body . data . firstname ) . to . eq ( 'Test' )
81- expect ( response . body . data . lastname ) . to . eq ( 'User' )
82- expect ( response . body . data . roles ) . to . have . length ( 1 )
83- expect ( response . body . data . roles [ 0 ] . code ) . to . eq ( 'strapi-editor' )
84-
85- // Store the created user ID for cleanup
86- Cypress . env ( 'createdUserId' , response . body . data . id )
87- } )
88- } )
62+ describe ( 'admin user without plugin access' , ( ) => {
63+ const userCredentials = {
64+ email : `no-access-${ timestamp } @example.com` ,
65+ password : 'strapiPassword1234' ,
66+ username : `no-access-${ timestamp } ` ,
67+ }
68+ let userWithoutAccess
69+ before ( ( ) => {
70+ cy . request ( {
71+ method : 'POST' ,
72+ url : 'http://localhost:1337/admin/users' ,
73+ headers : {
74+ Authorization : `Bearer ${ adminToken } ` ,
75+ } ,
76+ body : {
77+ firstname : 'Admin No Access' ,
78+ email : userCredentials . email ,
79+ roles : [ STRAPI_ADMIN_ROLES . EDITOR ] ,
80+ } ,
81+ } ) . then ( response => {
82+ expect ( response . status ) . to . eq ( 201 )
83+ userWithoutAccess = response . body . data
8984
90- it ( 'should be able to create a custom admin role with admin token' , ( ) => {
91- // Create a new custom admin role using the admin JWT token
92- cy . request ( {
93- method : 'POST' ,
94- url : 'http://localhost:1337/admin/roles' ,
95- headers : {
96- Authorization : `Bearer ${ adminToken } ` ,
97- } ,
98- body : {
99- name : uniqueRoleName ,
100- description : 'Can manage content but not system settings' ,
101- } ,
102- } ) . then ( response => {
103- expect ( response . status ) . to . eq ( 201 )
104- expect ( response . body . data ) . to . have . property ( 'id' )
105- expect ( response . body . data . name ) . to . eq ( uniqueRoleName )
106- expect ( response . body . data . description ) . to . eq (
107- 'Can manage content but not system settings' ,
108- )
85+ cy . request ( {
86+ method : 'PUT' ,
87+ url : `http://localhost:1337/admin/users/${ userWithoutAccess . id } ` ,
88+ headers : { Authorization : `Bearer ${ adminToken } ` } ,
89+ body : {
90+ isActive : true ,
91+ password : userCredentials . password ,
92+ } ,
93+ } ) . then ( response => {
94+ expect ( response . status ) . to . eq ( 200 )
95+ expect ( response . body . data . isActive ) . to . be . true
96+ } )
97+ } )
98+ } )
10999
110- // Store the created role ID for cleanup
111- Cypress . env ( 'createdRoleId' , response . body . data . id )
100+ it ( 'works' , ( ) => {
101+ expect ( true ) . to . be . true
112102 } )
113- } )
114103
115- it ( 'should be able to list all admin users' , ( ) => {
116- // List all admin users using the admin JWT token
117- cy . request ( {
118- method : 'GET' ,
119- url : 'http://localhost:1337/admin/users' ,
120- headers : {
121- Authorization : `Bearer ${ adminToken } ` ,
122- } ,
123- } ) . then ( response => {
124- expect ( response . status ) . to . eq ( 200 )
125- expect ( response . body . data ) . to . have . property ( 'results' )
126- expect ( response . body . data . results ) . to . be . an ( 'array' )
127- expect ( response . body . data . results . length ) . to . be . greaterThan ( 0 )
128-
129- // Should include our original admin user
130- const adminUser = response . body . data . results . find (
131- user => user . email === '[email protected] ' , 104+ it ( 'should not see plugin in sidepanel' , ( ) => {
105+ loginAsAdmin ( userCredentials . email , userCredentials . password ) . then (
106+ response => {
107+ expect ( response . status ) . to . eq ( 200 )
108+ } ,
132109 )
133- expect ( adminUser ) . to . exist
134- expect ( adminUser . roles [ 0 ] . code ) . to . eq ( 'strapi-super-admin' )
135110 } )
136111 } )
137112
138- it ( 'should be able to list all admin roles' , ( ) => {
139- // List all admin roles using the admin JWT token
140- cy . request ( {
141- method : 'GET' ,
142- url : 'http://localhost:1337/admin/roles' ,
143- headers : {
144- Authorization : `Bearer ${ adminToken } ` ,
145- } ,
146- } ) . then ( response => {
147- expect ( response . status ) . to . eq ( 200 )
148- expect ( response . body . data ) . to . be . an ( 'array' )
149- expect ( response . body . data . length ) . to . be . greaterThan ( 2 ) // At least Super Admin, Editor, Author
150-
151- // Should include the default roles
152- const roleNames = response . body . data . map ( role => role . name )
153- expect ( roleNames ) . to . include ( 'Super Admin' )
154- expect ( roleNames ) . to . include ( 'Editor' )
155- expect ( roleNames ) . to . include ( 'Author' )
156- } )
157- } )
113+ // it('should be able to create a new admin user with admin token', () => {
114+ // // Create a new admin user using the admin JWT token
115+ // cy.request({
116+ // method: 'POST',
117+ // url: 'http://localhost:1337/admin/users',
118+ // headers: {
119+ // Authorization: `Bearer ${adminToken}`,
120+ // },
121+ // body: {
122+ // firstname: 'Test',
123+ // lastname: 'User',
124+ // email: uniqueEmail,
125+ // roles: [2], // Editor role
126+ // },
127+ // }).then(response => {
128+ // expect(response.status).to.eq(201)
129+ // expect(response.body.data).to.have.property('id')
130+ // expect(response.body.data.email).to.eq(uniqueEmail)
131+ // expect(response.body.data.firstname).to.eq('Test')
132+ // expect(response.body.data.lastname).to.eq('User')
133+ // expect(response.body.data.roles).to.have.length(1)
134+ // expect(response.body.data.roles[0].code).to.eq('strapi-editor')
135+
136+ // // Store the created user ID for cleanup
137+ // Cypress.env('createdUserId', response.body.data.id)
138+ // })
139+ // })
140+
141+ // it('should be able to create a custom admin role with admin token', () => {
142+ // // Create a new custom admin role using the admin JWT token
143+ // cy.request({
144+ // method: 'POST',
145+ // url: 'http://localhost:1337/admin/roles',
146+ // headers: {
147+ // Authorization: `Bearer ${adminToken}`,
148+ // },
149+ // body: {
150+ // name: uniqueRoleName,
151+ // description: 'Can manage content but not system settings',
152+ // },
153+ // }).then(response => {
154+ // expect(response.status).to.eq(201)
155+ // expect(response.body.data).to.have.property('id')
156+ // expect(response.body.data.name).to.eq(uniqueRoleName)
157+ // expect(response.body.data.description).to.eq(
158+ // 'Can manage content but not system settings',
159+ // )
160+
161+ // // Store the created role ID for cleanup
162+ // Cypress.env('createdRoleId', response.body.data.id)
163+ // })
164+ // })
165+
166+ // it('should be able to list all admin users', () => {
167+ // // List all admin users using the admin JWT token
168+ // cy.request({
169+ // method: 'GET',
170+ // url: 'http://localhost:1337/admin/users',
171+ // headers: {
172+ // Authorization: `Bearer ${adminToken}`,
173+ // },
174+ // }).then(response => {
175+ // expect(response.status).to.eq(200)
176+ // expect(response.body.data).to.have.property('results')
177+ // expect(response.body.data.results).to.be.an('array')
178+ // expect(response.body.data.results.length).to.be.greaterThan(0)
179+
180+ // // Should include our original admin user
181+ // const adminUser = response.body.data.results.find(
182+ // user => user.email === '[email protected] ', 183+ // )
184+ // expect(adminUser).to.exist
185+ // expect(adminUser.roles[0].code).to.eq('strapi-super-admin')
186+ // })
187+ // })
188+
189+ // it('should be able to list all admin roles', () => {
190+ // // List all admin roles using the admin JWT token
191+ // cy.request({
192+ // method: 'GET',
193+ // url: 'http://localhost:1337/admin/roles',
194+ // headers: {
195+ // Authorization: `Bearer ${adminToken}`,
196+ // },
197+ // }).then(response => {
198+ // expect(response.status).to.eq(200)
199+ // expect(response.body.data).to.be.an('array')
200+ // expect(response.body.data.length).to.be.greaterThan(2) // At least Super Admin, Editor, Author
201+
202+ // // Should include the default roles
203+ // const roleNames = response.body.data.map(role => role.name)
204+ // expect(roleNames).to.include('Super Admin')
205+ // expect(roleNames).to.include('Editor')
206+ // expect(roleNames).to.include('Author')
207+ // })
208+ // })
158209
159210 // Cleanup tests - run after the main tests
160211 after ( ( ) => {
0 commit comments