@@ -208,6 +208,50 @@ testCases.forEach(function (testCase) {
208
208
} ) ;
209
209
} ) ;
210
210
211
+ it ( 'Test that admin can change roles' , function ( ) {
212
+ var roles = [ 'sidekick' ] ;
213
+ var newRoles = [ 'superhero' , 'villain' ] ;
214
+ return db . # ( 'robin' , 'dickgrayson' , { roles : roles } ) . then ( function ( res ) {
215
+ res . ok . should . equal ( true ) ;
216
+ return db . getUser ( 'robin' ) ;
217
+ } ) . then ( function ( user ) {
218
+ user . roles . should . deep . equal ( roles ) ;
219
+ } ) . then ( function ( ) {
220
+ return db . putUser ( 'robin' , { roles : newRoles } ) ;
221
+ } ) . then ( function ( res ) {
222
+ res . ok . should . equal ( true ) ;
223
+ return db . getUser ( 'robin' ) ;
224
+ } ) . then ( function ( user ) {
225
+ user . roles . should . deep . equal ( newRoles ) ;
226
+ } ) . catch ( function ( err ) {
227
+ should . not . exist ( err ) ;
228
+ } ) ;
229
+ } ) ;
230
+
231
+ it ( 'Test that user cannot change roles' , function ( ) {
232
+ var roles = [ 'sidekick' ] ;
233
+ var newRoles = [ 'superhero' , 'villain' ] ;
234
+ // We can't test for initial roles as we are in admin party
235
+ // Let us have faith in CouchDB
236
+ return db . # ( 'robin' , 'dickgrayson' , { roles : roles } ) . then ( function ( res ) {
237
+ res . ok . should . equal ( true ) ;
238
+ return db . login ( 'robin' , 'dickgrayson' ) ;
239
+ } ) . then ( function ( ) {
240
+ return db . getUser ( 'robin' ) ;
241
+ } ) . then ( function ( user ) {
242
+ user . roles . should . deep . equal ( roles ) ;
243
+ } ) . then ( function ( ) {
244
+ return db . putUser ( 'robin' , { roles : newRoles } ) ;
245
+ } ) . then ( function ( res ) {
246
+ res . ok . should . not . equal ( true ) ;
247
+ return db . getUser ( 'robin' ) . then ( function ( user ) {
248
+ user . roles . should . deep . equal ( roles ) ;
249
+ } ) ;
250
+ } ) . catch ( function ( err ) {
251
+ should . exist ( err ) ;
252
+ } ) ;
253
+ } ) ;
254
+
211
255
it ( 'Test wrong user for getUser' , function ( ) {
212
256
return db . # ( 'robin' , 'dickgrayson' ) . then ( function ( res ) {
213
257
return db . # ( 'aquaman' , 'sleeps_with_fishes' ) ;
0 commit comments