2021-10-01 12:10:10 +02:00
|
|
|
describe Users::TransfersController, type: :controller do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:dossier) { create(:dossier, user: user) }
|
|
|
|
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
|
|
|
describe 'DELETE destroy' do
|
|
|
|
let(:dossier_transfert) { DossierTransfer.initiate(user.email, [dossier]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
delete :destroy, params: { id: dossier_transfert.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect { dossier_transfert.reload }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
2022-08-02 15:20:33 +02:00
|
|
|
|
|
|
|
describe "POST create" do
|
|
|
|
subject { post :create, params: { dossier_transfer: { email: email, dossier: dossier.id } } }
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
context "with valid email" do
|
|
|
|
let(:email) { "test@rspec.net" }
|
|
|
|
|
|
|
|
it { expect(DossierTransfer.last.email).to eq(email) }
|
|
|
|
it { expect(DossierTransfer.last.dossiers).to eq([dossier]) }
|
|
|
|
end
|
|
|
|
|
2023-01-31 14:36:51 +01:00
|
|
|
context 'with upper case email' do
|
|
|
|
let(:email) { "Test@rspec.net" }
|
|
|
|
it { expect(DossierTransfer.last.email).to eq(email.strip.downcase) }
|
|
|
|
end
|
|
|
|
|
2022-08-02 15:20:33 +02:00
|
|
|
shared_examples 'email error' do
|
|
|
|
it { expect { subject }.not_to change { DossierTransfer.count } }
|
|
|
|
it { expect(flash.alert).to match([/invalide/]) }
|
|
|
|
it { is_expected.to redirect_to transferer_dossier_path(dossier.id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when email is empty" do
|
|
|
|
let(:email) { "" }
|
|
|
|
it_behaves_like 'email error'
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when email is invalid" do
|
|
|
|
let(:email) { "not-an-email" }
|
|
|
|
it_behaves_like 'email error'
|
|
|
|
end
|
|
|
|
end
|
2021-10-01 12:10:10 +02:00
|
|
|
end
|