@@ -94,6 +94,139 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbsecurity.model
94
94
});
95
95
});
96
96
97
+
98
+ describe ( " action context methods" , function (){
99
+ describe ( " when() methods" , function (){
100
+ it ( " can call the sucess closure when the permissions pass" , function (){
101
+ var testVar = false ;
102
+ mockUser .$( " hasPermission" , true );
103
+
104
+ cbsecurity .when ( " test" , function ( user ){
105
+ testVar = true ;
106
+ } );
107
+
108
+ expect ( testVar ).toBeTrue ();
109
+ });
110
+ it ( " can call the fail closure when the permissions fail" , function (){
111
+ var testVar = " " ;
112
+ mockUser .$( " hasPermission" , false );
113
+
114
+ cbsecurity .when (
115
+ " test" ,
116
+ // success
117
+ function ( user ){
118
+ testVar = false ;
119
+ },
120
+ // fail
121
+ function ( user ){
122
+ testVar = true ;
123
+ }
124
+ );
125
+
126
+ expect ( testVar ).toBeTrue ();
127
+ });
128
+ it ( " can ignore the success when the permissions fail and no fail has been provided" , function (){
129
+ var testVar = " " ;
130
+ mockUser .$( " hasPermission" , false );
131
+
132
+ cbsecurity .when (
133
+ " test" ,
134
+ // success
135
+ function ( user ){
136
+ testVar = false ;
137
+ }
138
+ );
139
+ expect ( testVar ).toBe ( " " );
140
+ });
141
+ });
142
+ describe ( " whenAll() methods" , function (){
143
+ it ( " can call the sucess closure when the permissions pass" , function (){
144
+ var testVar = false ;
145
+ mockUser .$( " hasPermission" ).$results ( true , true );
146
+
147
+ cbsecurity .whenAll ( " test,test2" , function ( user ){
148
+ testVar = true ;
149
+ } );
150
+
151
+ expect ( testVar ).toBeTrue ();
152
+ });
153
+ it ( " can call the fail closure when the permissions fail" , function (){
154
+ var testVar = " " ;
155
+ mockUser .$( " hasPermission" , false );
156
+
157
+ cbsecurity .whenAll (
158
+ " test" ,
159
+ // success
160
+ function ( user ){
161
+ testVar = false ;
162
+ },
163
+ // fail
164
+ function ( user ){
165
+ testVar = true ;
166
+ }
167
+ );
168
+
169
+ expect ( testVar ).toBeTrue ();
170
+ });
171
+ it ( " can ignore the success when the permissions fail and no fail has been provided" , function (){
172
+ var testVar = " " ;
173
+ mockUser .$( " hasPermission" , false );
174
+
175
+ cbsecurity .whenAll (
176
+ " test" ,
177
+ // success
178
+ function ( user ){
179
+ testVar = false ;
180
+ }
181
+ );
182
+ expect ( testVar ).toBe ( " " );
183
+ });
184
+ });
185
+ describe ( " whenNone() methods" , function (){
186
+ it ( " can call the sucess closure when the permissions are none" , function (){
187
+ var testVar = false ;
188
+ mockUser .$( " hasPermission" ).$results ( false , false );
189
+
190
+ cbsecurity .whenNone ( " test,test2" , function ( user ){
191
+ testVar = true ;
192
+ } );
193
+
194
+ expect ( testVar ).toBeTrue ();
195
+ });
196
+ it ( " can call the fail closure when the permissions are found" , function (){
197
+ var testVar = " " ;
198
+ mockUser .$( " hasPermission" , true );
199
+
200
+ cbsecurity .whenNone (
201
+ " test" ,
202
+ // success
203
+ function ( user ){
204
+ testVar = false ;
205
+ },
206
+ // fail
207
+ function ( user ){
208
+ testVar = true ;
209
+ }
210
+ );
211
+
212
+ expect ( testVar ).toBeTrue ();
213
+ });
214
+ it ( " can ignore the success when the permissions are found and no fail has been provided" , function (){
215
+ var testVar = " " ;
216
+ mockUser .$( " hasPermission" , true );
217
+
218
+ cbsecurity .whenNone (
219
+ " test" ,
220
+ // success
221
+ function ( user ){
222
+ testVar = false ;
223
+ }
224
+ );
225
+ expect ( testVar ).toBe ( " " );
226
+ });
227
+ });
228
+ });
229
+
97
230
describe ( " blocking methods" , function (){
98
231
describe ( " secure() method" , function (){
99
232
it ( " can allow a secure() function if permissions pass" , function (){
@@ -149,7 +282,6 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbsecurity.model
149
282
}).toThrow ( type = " NotAuthorized" , regex = " Invalid User Baby" );
150
283
});
151
284
});
152
-
153
285
describe ( " secureWhen() method" , function (){
154
286
it ( " can secure if a boolean true is passed" , function (){
155
287
expect ( function (){
@@ -168,7 +300,6 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbsecurity.model
168
300
it ( " can allow if a closure executes as false" , function (){
169
301
cbsecurity .secureWhen ( function ( user ){ return false ; } );
170
302
});
171
-
172
303
});
173
304
});
174
305
0 commit comments