Skip to content

Commit 26439d6

Browse files
authored
[5.4] [webservices] Create a user access level via POST (joomla#46080)
1 parent 01ebeac commit 26439d6

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

administrator/components/com_users/forms/level.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
type="hidden"
77
default="0"
88
readonly="true"
9-
required="true"
109
/>
1110

1211
<field
@@ -27,7 +26,6 @@
2726
<field
2827
name="rules"
2928
type="hidden"
30-
filter="intarray"
3129
/>
3230
</fieldset>
3331
</form>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
describe('Test that field users API endpoint', () => {
2+
afterEach(() => cy.task('queryDB', "DELETE FROM #__viewlevels where title = 'automated test level'"));
3+
4+
it('can deliver a list of levels', () => {
5+
cy.api_get('/users/levels')
6+
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
7+
.its('title')
8+
.should('include', 'Public'));
9+
});
10+
11+
it('can deliver a single level', () => {
12+
cy.api_get('/users/levels/1')
13+
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
14+
.its('title')
15+
.should('include', 'Public'));
16+
});
17+
18+
it('can create a level', () => {
19+
cy.api_post('/users/levels', {
20+
id: '0',
21+
title: 'automated test level',
22+
rules: '[1]',
23+
})
24+
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
25+
.its('title')
26+
.should('include', 'automated test level'));
27+
});
28+
29+
it('can patch a level', () => {
30+
// First create a level we can PATCH
31+
cy.api_post('/users/levels', {
32+
id: '0',
33+
title: 'automated test level',
34+
rules: '[1]', // valid initial rules
35+
}).then((createResponse) => {
36+
const createdId = createResponse.body.data.id;
37+
38+
// Now try to PATCH it with valid rules payload
39+
cy.api_patch(`/users/levels/${createdId}`, {
40+
title: 'automated test level',
41+
rules: '[1,2]',
42+
}).then((patchResponse) => {
43+
expect(patchResponse.status).to.eq(200);
44+
cy.wrap(patchResponse).its('body').its('data').its('attributes').its('rules')
45+
.then((rules) => {
46+
if (typeof rules === 'string') {
47+
const normalized = rules.replace(/\s+/g, '');
48+
expect(normalized).to.eq('[1,2]');
49+
} else {
50+
const nums = rules.map((r) => (typeof r === 'string' ? Number(r) : r));
51+
expect(nums).to.deep.equal([1, 2]);
52+
}
53+
});
54+
});
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)