Skip to content

Commit 837cef0

Browse files
Zeegaanmikecp
authored andcommitted
Update user test to use constants
1 parent f92070c commit 837cef0

File tree

1 file changed

+36
-84
lines changed
  • tests/Umbraco.Tests.AcceptanceTest/cypress/integration/Users

1 file changed

+36
-84
lines changed
Lines changed: 36 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
11
/// <reference types="Cypress" />
22
context('Users', () => {
33

4+
const name = "Alice Bobson";
5+
const email = "[email protected]";
6+
const startContentIds = [];
7+
const startMediaIds = [];
8+
const userGroups = ["admin"];
9+
10+
const userData =
11+
{
12+
"id": -1,
13+
"parentId": -1,
14+
"name": name,
15+
"username": email,
16+
"culture": "en-US",
17+
"email": email,
18+
"startContentIds": startContentIds,
19+
"startMediaIds": startMediaIds,
20+
"userGroups": userGroups,
21+
"message": ""
22+
};
23+
424
beforeEach(() => {
525
cy.umbracoLogin(Cypress.env('username'), Cypress.env('password'));
626
});
727

28+
afterEach(() => {
29+
//Clean up
30+
cy.umbracoEnsureUserEmailNotExists(email);
31+
});
32+
33+
function createUser(){
34+
let url = '/umbraco/backoffice/umbracoapi/users/PostCreateUser';
35+
cy.umbracoApiRequest(url, 'POST', userData);
36+
}
837
it('Create user', () => {
9-
const name = "Alice Bobson";
10-
const email = "[email protected]";
1138

1239
cy.umbracoEnsureUserEmailNotExists(email);
1340
cy.umbracoSection('users');
@@ -24,55 +51,16 @@ context('Users', () => {
2451

2552
cy.get('.umb-button > .btn > .umb-button__content').click();
2653

27-
2854
cy.umbracoButtonByLabelKey("user_goToProfile").should('be.visible');
29-
30-
//Clean up
31-
cy.umbracoEnsureUserEmailNotExists(email);
32-
3355
});
3456

3557
it('Update user', () => {
36-
// Set userdata
37-
const name = "Alice Bobson";
38-
const email = "[email protected]";
39-
const startContentIds = [];
40-
const startMediaIds = [];
41-
const userGroups = ["admin"];
42-
43-
var userData =
44-
{
45-
"id": -1,
46-
"parentId": -1,
47-
"name": name,
48-
"username": email,
49-
"culture": "en-US",
50-
"email": email,
51-
"startContentIds": startContentIds,
52-
"startMediaIds": startMediaIds,
53-
"userGroups": userGroups,
54-
"message": ""
55-
};
5658

5759
// Ensure user doesn't exist
5860
cy.umbracoEnsureUserEmailNotExists(email);
59-
60-
// Create user through API
61-
cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => {
62-
cy.request({
63-
method: 'POST',
64-
url: '/umbraco/backoffice/umbracoapi/users/PostCreateUser',
65-
followRedirect: true,
66-
headers: {
67-
Accept: 'application/json',
68-
'X-UMB-XSRF-TOKEN': token.value,
69-
},
70-
body: userData,
71-
log: false,
72-
}).then((response) => {
73-
return;
74-
});
75-
});
61+
62+
//Create user through API
63+
createUser();
7664

7765
// Go to the user and edit their name
7866
cy.umbracoSection('users');
@@ -82,50 +70,15 @@ context('Users', () => {
8270

8371
// assert save succeeds
8472
cy.umbracoSuccessNotification().should('be.visible');
85-
cy.umbracoEnsureUserEmailNotExists(email);
8673
})
87-
74+
8875
it('Delete user', () => {
89-
// Set userdata
90-
const name = "Alice Bobson";
91-
const email = "[email protected]";
92-
const startContentIds = [];
93-
const startMediaIds = [];
94-
const userGroups = ["admin"];
95-
96-
var userData =
97-
{
98-
"id": -1,
99-
"parentId": -1,
100-
"name": name,
101-
"username": email,
102-
"culture": "en-US",
103-
"email": email,
104-
"startContentIds": startContentIds,
105-
"startMediaIds": startMediaIds,
106-
"userGroups": userGroups,
107-
"message": ""
108-
};
10976

11077
// Ensure user doesn't exist
11178
cy.umbracoEnsureUserEmailNotExists(email);
11279

113-
// Create user through API
114-
cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => {
115-
cy.request({
116-
method: 'POST',
117-
url: '/umbraco/backoffice/umbracoapi/users/PostCreateUser',
118-
followRedirect: true,
119-
headers: {
120-
Accept: 'application/json',
121-
'X-UMB-XSRF-TOKEN': token.value,
122-
},
123-
body: userData,
124-
log: false,
125-
}).then((response) => {
126-
return;
127-
});
128-
});
80+
//Create user through API
81+
createUser();
12982

13083
// Go to the user and delete them
13184
cy.umbracoSection('users');
@@ -135,6 +88,5 @@ context('Users', () => {
13588

13689
// assert deletion succeeds
13790
cy.umbracoSuccessNotification().should('be.visible');
138-
cy.umbracoEnsureUserEmailNotExists(email);
13991
})
140-
});
92+
});

0 commit comments

Comments
 (0)