@ -1538,7 +1538,7 @@ RSpec.describe UsersController, type: :request do
expect ( whodunnit_actor . id ) . to eq ( user . id )
expect ( whodunnit_actor . id ) . to eq ( user . id )
end
end
context " when user changes email, dpo and key contact " do
context " when user changes email, dpo and key contact " , :aggregate_failures do
let ( :params ) { { id : user . id , user : { name : new_name , email : new_email , is_dpo : " true " , is_key_contact : " true " } } }
let ( :params ) { { id : user . id , user : { name : new_name , email : new_email , is_dpo : " true " , is_key_contact : " true " } } }
let ( :personalisation ) do
let ( :personalisation ) do
{
{
@ -1551,6 +1551,8 @@ RSpec.describe UsersController, type: :request do
before do
before do
user . legacy_users . destroy_all
user . legacy_users . destroy_all
allow ( FeatureToggle ) . to receive ( :new_email_journey? ) . and_return ( false )
end
end
it " allows changing email and dpo " do
it " allows changing email and dpo " do
@ -1566,6 +1568,43 @@ RSpec.describe UsersController, type: :request do
expect ( notify_client ) . to receive ( :send_email ) . with ( email_address : user . email , template_id : User :: CONFIRMABLE_TEMPLATE_ID , personalisation : ) . once
expect ( notify_client ) . to receive ( :send_email ) . with ( email_address : user . email , template_id : User :: CONFIRMABLE_TEMPLATE_ID , personalisation : ) . once
request
request
end
end
context " with new email journy enabled " do
before do
allow ( FeatureToggle ) . to receive ( :new_email_journey? ) . and_return ( true )
end
it " shows flash notice " do
patch ( " /users/ #{ other_user . id } " , headers : , params : )
expect ( flash [ :notice ] ) . to eq ( " An email has been sent to #{ new_email } to confirm this change. " )
end
it " sends new flow emails " do
expect ( notify_client ) . to receive ( :send_email ) . with (
email_address : other_user . email ,
template_id : User :: FOR_OLD_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID ,
personalisation : {
new_email : ,
old_email : other_user . email ,
} ,
) . once
expect ( notify_client ) . to receive ( :send_email ) . with (
email_address : new_email ,
template_id : User :: FOR_NEW_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID ,
personalisation : {
new_email : ,
old_email : other_user . email ,
link : include ( " /account/confirmation?confirmation_token= " ) ,
} ,
) . once
expect ( notify_client ) . not_to receive ( :send_email )
patch " /users/ #{ other_user . id } " , headers : , params :
end
end
end
end
context " when we update the user password " do
context " when we update the user password " do
@ -1679,13 +1718,28 @@ RSpec.describe UsersController, type: :request do
expect ( page ) . to have_content ( other_user . reload . email . to_s )
expect ( page ) . to have_content ( other_user . reload . email . to_s )
end
end
context " when the support user tries to update the user’s password " do
context " when the support user tries to update the user’s password " , :aggregate_failures do
let ( :params ) do
let ( :params ) do
{
{
id : user . id , user : { password : new_name , password_confirmation : new_name , name : " new name " }
id : user . id , user : { password : new_name , password_confirmation : new_name , name : " new name " , email : new_email }
}
end
let ( :personalisation ) do
{
name : params [ :user ] [ :name ] ,
email : new_email ,
organisation : other_user . organisation . name ,
link : include ( " /account/confirmation?confirmation_token= " ) ,
}
}
end
end
before do
other_user . legacy_users . destroy_all
allow ( FeatureToggle ) . to receive ( :new_email_journey? ) . and_return ( false )
end
it " does not update the password " do
it " does not update the password " do
expect { patch " /users/ #{ other_user . id } " , headers : , params : }
expect { patch " /users/ #{ other_user . id } " , headers : , params : }
. not_to change ( other_user , :encrypted_password )
. not_to change ( other_user , :encrypted_password )
@ -1695,6 +1749,57 @@ RSpec.describe UsersController, type: :request do
expect { patch " /users/ #{ other_user . id } " , headers : , params : }
expect { patch " /users/ #{ other_user . id } " , headers : , params : }
. to change { other_user . reload . name } . from ( " Danny Rojas " ) . to ( " new name " )
. to change { other_user . reload . name } . from ( " Danny Rojas " ) . to ( " new name " )
end
end
it " allows changing email " do
expect { patch " /users/ #{ other_user . id } " , headers : , params : }
. to change { other_user . reload . unconfirmed_email } . from ( nil ) . to ( new_email )
end
it " sends a confirmation email to both emails " do
expect ( notify_client ) . to receive ( :send_email ) . with ( email_address : other_user . email , template_id : User :: CONFIRMABLE_TEMPLATE_ID , personalisation : ) . once
expect ( notify_client ) . to receive ( :send_email ) . with ( email_address : new_email , template_id : User :: CONFIRMABLE_TEMPLATE_ID , personalisation : ) . once
expect ( notify_client ) . not_to receive ( :send_email )
patch " /users/ #{ other_user . id } " , headers : , params :
end
context " with new user email flow enabled " do
before do
allow ( FeatureToggle ) . to receive ( :new_email_journey? ) . and_return ( true )
end
it " shows flash notice " do
patch ( " /users/ #{ other_user . id } " , headers : , params : )
expect ( flash [ :notice ] ) . to eq ( " An email has been sent to #{ new_email } to confirm this change. " )
end
it " sends new flow emails " do
expect ( notify_client ) . to receive ( :send_email ) . with (
email_address : other_user . email ,
template_id : User :: FOR_OLD_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID ,
personalisation : {
new_email : ,
old_email : other_user . email ,
} ,
) . once
expect ( notify_client ) . to receive ( :send_email ) . with (
email_address : new_email ,
template_id : User :: FOR_NEW_EMAIL_CHANGED_BY_OTHER_USER_TEMPLATE_ID ,
personalisation : {
new_email : ,
old_email : other_user . email ,
link : include ( " /account/confirmation?confirmation_token= " ) ,
} ,
) . once
expect ( notify_client ) . not_to receive ( :send_email )
patch " /users/ #{ other_user . id } " , headers : , params :
end
end
end
end
end
end
end
end