1
1
/// <reference types="Cypress" />
2
2
context ( 'Users' , ( ) => {
3
3
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
+
4
24
beforeEach ( ( ) => {
5
25
cy . umbracoLogin ( Cypress . env ( 'username' ) , Cypress . env ( 'password' ) ) ;
6
26
} ) ;
7
27
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
+ }
8
37
it ( 'Create user' , ( ) => {
9
- const name = "Alice Bobson" ;
10
- const email = "[email protected] " ;
11
38
12
39
cy . umbracoEnsureUserEmailNotExists ( email ) ;
13
40
cy . umbracoSection ( 'users' ) ;
@@ -24,55 +51,16 @@ context('Users', () => {
24
51
25
52
cy . get ( '.umb-button > .btn > .umb-button__content' ) . click ( ) ;
26
53
27
-
28
54
cy . umbracoButtonByLabelKey ( "user_goToProfile" ) . should ( 'be.visible' ) ;
29
-
30
- //Clean up
31
- cy . umbracoEnsureUserEmailNotExists ( email ) ;
32
-
33
55
} ) ;
34
56
35
57
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
- } ;
56
58
57
59
// Ensure user doesn't exist
58
60
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 ( ) ;
76
64
77
65
// Go to the user and edit their name
78
66
cy . umbracoSection ( 'users' ) ;
@@ -82,50 +70,15 @@ context('Users', () => {
82
70
83
71
// assert save succeeds
84
72
cy . umbracoSuccessNotification ( ) . should ( 'be.visible' ) ;
85
- cy . umbracoEnsureUserEmailNotExists ( email ) ;
86
73
} )
87
-
74
+
88
75
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
- } ;
109
76
110
77
// Ensure user doesn't exist
111
78
cy . umbracoEnsureUserEmailNotExists ( email ) ;
112
79
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 ( ) ;
129
82
130
83
// Go to the user and delete them
131
84
cy . umbracoSection ( 'users' ) ;
@@ -135,6 +88,5 @@ context('Users', () => {
135
88
136
89
// assert deletion succeeds
137
90
cy . umbracoSuccessNotification ( ) . should ( 'be.visible' ) ;
138
- cy . umbracoEnsureUserEmailNotExists ( email ) ;
139
91
} )
140
- } ) ;
92
+ } ) ;
0 commit comments