@ -1956,7 +1956,6 @@ RSpec.describe UsersController, type: :request do
end
end
context " when the current user does not match the user ID " do
context " when the user is not part of the same organisation as the current user " do
let ( :other_user ) { create ( :user ) }
let ( :params ) { { id : other_user . id , user : { name : new_name } } }
@ -2074,6 +2073,122 @@ RSpec.describe UsersController, type: :request do
end
end
end
context " when updating log reassignment " do
let ( :new_organisation ) { create ( :organisation , name : " New org " ) }
let ( :new_organisation_2 ) { create ( :organisation , name : " New org 2 " ) }
let ( :new_organisation_3 ) { create ( :organisation , name : " New org 3 " ) }
context " and log reassignment choice is not present " do
let ( :params ) { { user : { organisation_id : new_organisation . id , log_reassignment : nil } } }
before do
patch " /users/ #{ other_user . id } /log-reassignment " , headers : , params :
end
it " does not update the user's organisation " do
expect ( other_user . reload . organisation ) . not_to eq ( new_organisation )
end
it " displays the error message " do
expect ( response ) . to have_http_status ( :unprocessable_entity )
expect ( page ) . to have_content ( " Select if you want to reassign logs " )
end
end
context " and log reassignment choice is to change the stock owner and managing agent " do
let ( :params ) { { user : { organisation_id : new_organisation . id , log_reassignment : " reassign_all " } } }
before do
patch " /users/ #{ other_user . id } /log-reassignment " , headers : , params :
end
it " does not update the user's organisation " do
expect ( other_user . reload . organisation ) . not_to eq ( new_organisation )
end
it " redirects to confirmation page " do
expect ( response ) . to redirect_to ( " /users/ #{ other_user . id } /confirm-organisation-change?log_reassignment=reassign_all&organisation_id= #{ new_organisation . id } " )
end
end
context " and log reassignment choice is to unassign logs " do
let ( :params ) { { user : { organisation_id : new_organisation . id , log_reassignment : " unassign " } } }
before do
patch " /users/ #{ other_user . id } /log-reassignment " , headers : , params :
end
it " does not update the user's organisation " do
expect ( other_user . reload . organisation ) . not_to eq ( new_organisation )
end
it " redirects to confirmation page " do
expect ( response ) . to redirect_to ( " /users/ #{ other_user . id } /confirm-organisation-change?log_reassignment=unassign&organisation_id= #{ new_organisation . id } " )
end
end
context " and log reassignment choice is to change stock owner " do
let ( :params ) { { user : { organisation_id : new_organisation . id , log_reassignment : " reassign_stock_owner " } } }
context " when users organisation manages the logs " do
before do
create ( :lettings_log , managing_organisation : other_user . organisation , assigned_to : other_user )
create ( :sales_log , managing_organisation : other_user . organisation , assigned_to : other_user )
patch " /users/ #{ other_user . id } /log-reassignment " , headers : , params :
end
it " required the new org to have stock owner relationship with the current user org " do
expect ( response ) . to have_http_status ( :unprocessable_entity )
expect ( page ) . to have_content ( " New org must be a stock owner of #{ other_user . organisation_name } to make this change. " )
end
end
context " when different organisations manage the logs " do
before do
create ( :lettings_log , managing_organisation : other_user . organisation , assigned_to : other_user )
create ( :lettings_log , managing_organisation : new_organisation_2 , assigned_to : other_user )
create ( :sales_log , managing_organisation : new_organisation_3 , assigned_to : other_user )
patch " /users/ #{ other_user . id } /log-reassignment " , headers : , params :
end
it " required the new org to have stock owner relationship with the managing organisations " do
expect ( response ) . to have_http_status ( :unprocessable_entity )
expect ( page ) . to have_content ( " New org must be a stock owner of #{ other_user . organisation_name } , #{ new_organisation_2 . name } , and #{ new_organisation_3 . name } to make this change. " )
end
end
end
context " and log reassignment choice is to change managing agent " do
let ( :params ) { { user : { organisation_id : new_organisation . id , log_reassignment : " reassign_managing_agent " } } }
context " when users organisation manages the logs " do
before do
create ( :lettings_log , owning_organisation : other_user . organisation , assigned_to : other_user )
create ( :sales_log , owning_organisation : other_user . organisation , assigned_to : other_user )
patch " /users/ #{ other_user . id } /log-reassignment " , headers : , params :
end
it " required the new org to have managing agent relationship with the current user org " do
expect ( response ) . to have_http_status ( :unprocessable_entity )
expect ( page ) . to have_content ( " New org must be a managing agent of #{ other_user . organisation_name } to make this change. " )
end
end
context " when different organisations manage the logs " do
before do
create ( :lettings_log , owning_organisation : other_user . organisation , assigned_to : other_user )
create ( :lettings_log , owning_organisation : new_organisation_2 , assigned_to : other_user )
create ( :sales_log , owning_organisation : new_organisation_3 , managing_organisation : other_user . organisation , assigned_to : other_user )
patch " /users/ #{ other_user . id } /log-reassignment " , headers : , params :
end
it " required the new org to have managing agent relationship with owning organisations " do
expect ( response ) . to have_http_status ( :unprocessable_entity )
expect ( page ) . to have_content ( " New org must be a managing agent of #{ other_user . organisation_name } , #{ new_organisation_2 . name } , and #{ new_organisation_3 . name } to make this change. " )
end
end
end
end
end
end