2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-05-23 15:09:22 +02:00
|
|
|
|
describe TargetedUserLinksController, type: :controller do
|
|
|
|
|
describe '#show' do
|
2022-06-13 16:00:41 +02:00
|
|
|
|
context 'avis' do
|
2022-10-04 11:41:32 +02:00
|
|
|
|
let!(:targeted_user_link) { create(:targeted_user_link, target_context: target_context, target_model: target_model, user: user) }
|
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
let(:target_context) { :avis }
|
|
|
|
|
let!(:expert) { create(:expert, user: user) }
|
|
|
|
|
let!(:target_model) { create(:avis, experts_procedure: expert_procedure) }
|
|
|
|
|
let!(:expert_procedure) { create(:experts_procedure, expert: expert) }
|
2022-05-23 15:09:22 +02:00
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
context 'not connected as active expert' do
|
|
|
|
|
let(:user) { create(:user, last_sign_in_at: 2.days.ago) }
|
2022-05-23 15:09:22 +02:00
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
before { get :show, params: { id: targeted_user_link.id } }
|
|
|
|
|
|
|
|
|
|
it 'redirects to expert_avis_url' do
|
|
|
|
|
expect(response).to redirect_to(expert_avis_path(target_model.procedure, target_model))
|
2023-12-14 10:10:20 +01:00
|
|
|
|
expect(controller.stored_location_for(:user)).to eq(controller.request.path)
|
2022-06-13 16:00:41 +02:00
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
context 'not connected as inactive expert' do
|
|
|
|
|
let(:user) { create(:user, last_sign_in_at: nil) }
|
2022-05-23 15:09:22 +02:00
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
before { get :show, params: { id: targeted_user_link.id } }
|
2022-05-23 15:09:22 +02:00
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
it 'redirects to sign_up_expert_avis_url' do
|
|
|
|
|
expect(response).to redirect_to(sign_up_expert_avis_path(target_model.procedure, target_model, email: user.email))
|
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
context 'connected as expected user' do
|
|
|
|
|
let(:user) { create(:user, last_sign_in_at: 2.days.ago) }
|
2022-05-23 15:09:22 +02:00
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
before do
|
|
|
|
|
sign_in(targeted_user_link.user)
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'redirects to expert_avis_url' do
|
|
|
|
|
expect(response).to redirect_to(expert_avis_path(target_model.procedure, target_model))
|
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
context 'connected as different user' do
|
|
|
|
|
let(:user) { create(:user, last_sign_in_at: 2.days.ago) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
sign_in(create(:expert).user)
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'renders error page ' do
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-07-11 13:46:12 +02:00
|
|
|
|
context 'with invite having user' do
|
2022-10-04 11:41:32 +02:00
|
|
|
|
let!(:targeted_user_link) { create(:targeted_user_link, target_context: target_context, target_model: target_model, user: user) }
|
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
let(:target_context) { 'invite' }
|
|
|
|
|
let(:target_model) { create(:invite, user: user) }
|
|
|
|
|
|
|
|
|
|
context 'connected with expected user' do
|
|
|
|
|
let(:user) { build(:user, last_sign_in_at: 2.days.ago) }
|
|
|
|
|
before do
|
|
|
|
|
sign_in(targeted_user_link.user)
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
end
|
|
|
|
|
it 'works' do
|
|
|
|
|
expect(response).to redirect_to(invite_path(target_model))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'connected as different user' do
|
|
|
|
|
let(:user) { create(:user, last_sign_in_at: 2.days.ago) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
sign_in(create(:expert).user)
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
it 'renders error page ' do
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
|
|
|
|
|
2022-06-13 16:00:41 +02:00
|
|
|
|
context 'when invite user does not exists' do
|
|
|
|
|
let(:user) { nil }
|
|
|
|
|
before { get :show, params: { id: targeted_user_link.id } }
|
|
|
|
|
it 'works' do
|
|
|
|
|
expect(response).to redirect_to(invite_path(target_model, email: target_model.email))
|
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
2022-10-17 19:09:51 +02:00
|
|
|
|
|
|
|
|
|
context 'when there is no dossier visible anymore' do
|
|
|
|
|
let(:user) { nil }
|
|
|
|
|
let(:target_model) { create(:invite, user: user, dossier: create(:dossier, hidden_by_user_at: 1.day.ago)) }
|
|
|
|
|
|
|
|
|
|
it 'redirect nicely' do
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
expect(response).to redirect_to(root_path)
|
2022-12-01 13:41:12 +01:00
|
|
|
|
expect(flash[:error]).to match(/dossier n’est plus accessible/)
|
2022-10-17 19:09:51 +02:00
|
|
|
|
end
|
2022-10-24 14:31:34 +02:00
|
|
|
|
|
|
|
|
|
it 'redirect nicely also when user is signed on another account' do
|
|
|
|
|
sign_in(create(:expert).user)
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
expect(response).to redirect_to(root_path)
|
2022-12-01 13:41:12 +01:00
|
|
|
|
expect(flash[:error]).to match(/dossier n’est plus accessible/)
|
2022-10-24 14:31:34 +02:00
|
|
|
|
end
|
2022-10-17 19:09:51 +02:00
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
2022-07-11 13:46:12 +02:00
|
|
|
|
|
|
|
|
|
context 'with invite not having user' do
|
2022-10-04 11:41:32 +02:00
|
|
|
|
let!(:targeted_user_link) { create(:targeted_user_link, target_context: target_context, target_model: target_model, user: user) }
|
2022-07-11 13:46:12 +02:00
|
|
|
|
let(:target_context) { 'invite' }
|
2022-07-11 14:33:01 +02:00
|
|
|
|
let(:user_email) { 'not_yet_registered@a.com' }
|
2022-07-11 13:46:12 +02:00
|
|
|
|
let(:target_model) { create(:invite, user: nil, email: user_email) }
|
|
|
|
|
|
|
|
|
|
context 'connected with expected user' do
|
|
|
|
|
let(:user) { create(:user, email: user_email, last_sign_in_at: 2.days.ago) }
|
|
|
|
|
before do
|
|
|
|
|
sign_in(user)
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
end
|
|
|
|
|
it 'works' do
|
|
|
|
|
expect(response).to redirect_to(invite_path(target_model))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'connected as different user' do
|
|
|
|
|
let(:user) { create(:user, last_sign_in_at: 2.days.ago) }
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
sign_in(create(:expert).user)
|
|
|
|
|
get :show, params: { id: targeted_user_link.id }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'renders error page ' do
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when invite user does not exists' do
|
|
|
|
|
let(:user) { nil }
|
|
|
|
|
before { get :show, params: { id: targeted_user_link.id } }
|
|
|
|
|
it 'works' do
|
|
|
|
|
expect(response).to redirect_to(invite_path(target_model, email: target_model.email))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-10-04 11:41:32 +02:00
|
|
|
|
|
|
|
|
|
context 'not found' do
|
|
|
|
|
it 'redirect nicely' do
|
|
|
|
|
sign_in(create(:user))
|
|
|
|
|
get :show, params: { id: "asldjiasld" }
|
|
|
|
|
expect(response).to redirect_to(root_path)
|
|
|
|
|
expect(flash[:error]).to be_present
|
2022-12-01 13:41:12 +01:00
|
|
|
|
expect(flash[:error]).to match(/invitation n’est plus valable/)
|
2022-10-04 11:41:32 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2022-05-23 15:09:22 +02:00
|
|
|
|
end
|
|
|
|
|
end
|