@@ -359,6 +359,71 @@ describe("POST reset password", function () {
359359 } ) ;
360360} ) ;
361361
362+ describe ( "PATCH change password for logged in user" , function ( ) {
363+ const successChangePassword = {
364+ "oldPassword" : Admin1 . password ,
365+ "newPassword" : "password12345"
366+ } ;
367+ const failChangePassword = {
368+ "oldPassword" : "WrongPassword" ,
369+ "newPassword" : "password12345"
370+ } ;
371+ // fail on authentication
372+ it ( "should fail to change the user's password because they are not logged in" , function ( done ) {
373+ chai . request ( server . app )
374+ . patch ( "/api/auth/password/change" )
375+ . type ( "application/json" )
376+ . send ( failChangePassword )
377+ . end ( function ( err , res ) {
378+ res . should . have . status ( 401 ) ;
379+ res . should . be . json ;
380+ res . body . should . have . property ( "message" ) ;
381+ res . body . message . should . equal ( Constants . Error . AUTH_401_MESSAGE ) ;
382+ done ( ) ;
383+ } ) ;
384+ } ) ;
385+ // success case
386+ it ( "should change the logged in user's password to a new password" , function ( done ) {
387+ util . auth . login ( agent , Admin1 , ( error ) => {
388+ if ( error ) {
389+ agent . close ( ) ;
390+ return done ( error ) ;
391+ }
392+ agent
393+ . patch ( "/api/auth/password/change" )
394+ . type ( "application/json" )
395+ . send ( successChangePassword )
396+ . end ( function ( err , res ) {
397+ res . should . have . status ( 200 ) ;
398+ res . should . be . json ;
399+ res . body . should . have . property ( "message" ) ;
400+ res . body . message . should . equal ( "Successfully reset password" ) ;
401+ done ( ) ;
402+ } ) ;
403+ } ) ;
404+ } ) ;
405+ // fail case because old password in incorrect
406+ it ( "should fail to change the logged in user's password to a new password because old password is incorrect" , function ( done ) {
407+ util . auth . login ( agent , Admin1 , ( error ) => {
408+ if ( error ) {
409+ agent . close ( ) ;
410+ return done ( error ) ;
411+ }
412+ agent
413+ . patch ( "/api/auth/password/change" )
414+ . type ( "application/json" )
415+ . send ( failChangePassword )
416+ . end ( function ( err , res ) {
417+ res . should . have . status ( 401 ) ;
418+ res . should . be . json ;
419+ res . body . should . have . property ( "message" ) ;
420+ res . body . message . should . equal ( Constants . Error . AUTH_401_MESSAGE ) ;
421+ done ( ) ;
422+ } ) ;
423+ } ) ;
424+ } ) ;
425+ } ) ;
426+
362427describe ( "GET retrieve permissions" , function ( ) {
363428 it ( "should SUCCEED and retrieve the rolebindings for the user" , function ( done ) {
364429 util . auth . login ( agent , storedAccount1 , ( error ) => {
0 commit comments