|
| 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