diff --git a/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Users/users.ts b/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Users/users.ts index 12a9bee7a20b..8cf2eb8579c3 100644 --- a/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Users/users.ts +++ b/tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Users/users.ts @@ -1,13 +1,40 @@ /// context('Users', () => { + const name = "Alice Bobson"; + const email = "alice-bobson@acceptancetest.umbraco"; + const startContentIds = []; + const startMediaIds = []; + const userGroups = ["admin"]; + + const userData = + { + "id": -1, + "parentId": -1, + "name": name, + "username": email, + "culture": "en-US", + "email": email, + "startContentIds": startContentIds, + "startMediaIds": startMediaIds, + "userGroups": userGroups, + "message": "" + }; + beforeEach(() => { cy.umbracoLogin(Cypress.env('username'), Cypress.env('password')); }); + afterEach(() => { + //Clean up + cy.umbracoEnsureUserEmailNotExists(email); + }); + + function createUser(){ + let url = '/umbraco/backoffice/umbracoapi/users/PostCreateUser'; + cy.umbracoApiRequest(url, 'POST', userData); + } it('Create user', () => { - const name = "Alice Bobson"; - const email = "alice-bobson@acceptancetest.umbraco"; cy.umbracoEnsureUserEmailNotExists(email); cy.umbracoSection('users'); @@ -24,55 +51,16 @@ context('Users', () => { cy.get('.umb-button > .btn > .umb-button__content').click(); - cy.umbracoButtonByLabelKey("user_goToProfile").should('be.visible'); - - //Clean up - cy.umbracoEnsureUserEmailNotExists(email); - }); it('Update user', () => { - // Set userdata - const name = "Alice Bobson"; - const email = "alice-bobson@acceptancetest.umbraco"; - const startContentIds = []; - const startMediaIds = []; - const userGroups = ["admin"]; - - var userData = - { - "id": -1, - "parentId": -1, - "name": name, - "username": email, - "culture": "en-US", - "email": email, - "startContentIds": startContentIds, - "startMediaIds": startMediaIds, - "userGroups": userGroups, - "message": "" - }; // Ensure user doesn't exist cy.umbracoEnsureUserEmailNotExists(email); - - // Create user through API - cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => { - cy.request({ - method: 'POST', - url: '/umbraco/backoffice/umbracoapi/users/PostCreateUser', - followRedirect: true, - headers: { - Accept: 'application/json', - 'X-UMB-XSRF-TOKEN': token.value, - }, - body: userData, - log: false, - }).then((response) => { - return; - }); - }); + + //Create user through API + createUser(); // Go to the user and edit their name cy.umbracoSection('users'); @@ -82,50 +70,15 @@ context('Users', () => { // assert save succeeds cy.umbracoSuccessNotification().should('be.visible'); - cy.umbracoEnsureUserEmailNotExists(email); }) - + it('Delete user', () => { - // Set userdata - const name = "Alice Bobson"; - const email = "alice-bobson@acceptancetest.umbraco"; - const startContentIds = []; - const startMediaIds = []; - const userGroups = ["admin"]; - - var userData = - { - "id": -1, - "parentId": -1, - "name": name, - "username": email, - "culture": "en-US", - "email": email, - "startContentIds": startContentIds, - "startMediaIds": startMediaIds, - "userGroups": userGroups, - "message": "" - }; // Ensure user doesn't exist cy.umbracoEnsureUserEmailNotExists(email); - // Create user through API - cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => { - cy.request({ - method: 'POST', - url: '/umbraco/backoffice/umbracoapi/users/PostCreateUser', - followRedirect: true, - headers: { - Accept: 'application/json', - 'X-UMB-XSRF-TOKEN': token.value, - }, - body: userData, - log: false, - }).then((response) => { - return; - }); - }); + //Create user through API + createUser(); // Go to the user and delete them cy.umbracoSection('users'); @@ -135,6 +88,5 @@ context('Users', () => { // assert deletion succeeds cy.umbracoSuccessNotification().should('be.visible'); - cy.umbracoEnsureUserEmailNotExists(email); }) -}); \ No newline at end of file +});