2018-08-29 11:44:12 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe SupportController, type: :controller do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
context 'signed in' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2018-08-30 15:08:26 +02:00
|
|
|
it 'should not have email field' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).not_to have_content("Email *")
|
|
|
|
end
|
|
|
|
|
2018-08-29 11:44:12 +02:00
|
|
|
describe "with dossier" do
|
|
|
|
let(:user) { dossier.user }
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
it 'should fill dossier_id' do
|
|
|
|
get :index, params: { dossier_id: dossier.id }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include("#{dossier.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-30 15:08:26 +02:00
|
|
|
describe "with tag" do
|
2018-08-29 11:44:12 +02:00
|
|
|
let(:tag) { 'yolo' }
|
|
|
|
|
|
|
|
it 'should fill tags' do
|
|
|
|
get :index, params: { tags: [tag] }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include(tag)
|
|
|
|
end
|
|
|
|
end
|
2018-08-30 13:48:03 +02:00
|
|
|
|
|
|
|
describe "with multiple tags" do
|
|
|
|
let(:tags) { ['yolo', 'toto'] }
|
|
|
|
|
|
|
|
it 'should fill tags' do
|
|
|
|
get :index, params: { tags: tags }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include(tags.join(','))
|
|
|
|
end
|
|
|
|
end
|
2018-08-30 16:12:40 +02:00
|
|
|
|
|
|
|
describe "send form" do
|
|
|
|
it 'should create conversation' do
|
|
|
|
expect(subject).not_to receive(:create_commentaire)
|
|
|
|
allow(subject).to receive(:create_conversation).and_return(true)
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
subject: 'bonjour',
|
|
|
|
text: 'un message'
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
|
|
|
expect(response).to redirect_to root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with dossier" do
|
|
|
|
let(:user) { dossier.user }
|
|
|
|
let(:dossier) { create(:dossier) }
|
|
|
|
|
|
|
|
it 'should create conversation' do
|
|
|
|
expect(subject).not_to receive(:create_commentaire)
|
|
|
|
allow(subject).to receive(:create_conversation).and_return(true)
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
type: Helpscout::FormAdapter::TYPE_INSTRUCTION,
|
|
|
|
subject: 'bonjour',
|
|
|
|
text: 'un message'
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
|
|
|
expect(response).to redirect_to root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
context "en_construction" do
|
|
|
|
let(:dossier) { create(:dossier, :en_construction) }
|
|
|
|
|
|
|
|
it 'should create commentaire' do
|
|
|
|
allow(subject).to receive(:create_commentaire).and_return(true)
|
|
|
|
expect(subject).not_to receive(:create_conversation)
|
|
|
|
|
|
|
|
post :create, params: {
|
|
|
|
dossier_id: dossier.id,
|
|
|
|
type: Helpscout::FormAdapter::TYPE_INSTRUCTION,
|
|
|
|
subject: 'bonjour',
|
|
|
|
text: 'un message'
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(flash[:notice]).to match('Votre message a été envoyé sur la messagerie de votre dossier.')
|
2018-09-27 17:14:00 +02:00
|
|
|
expect(response).to redirect_to messagerie_dossier_path(dossier)
|
2018-08-30 16:12:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-08-29 11:44:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'signed out' do
|
|
|
|
describe "with dossier" do
|
|
|
|
it 'should have email field' do
|
|
|
|
get :index
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to have_content("Email *")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with dossier" do
|
|
|
|
let(:tag) { 'yolo' }
|
|
|
|
|
|
|
|
it 'should fill tags' do
|
|
|
|
get :index, params: { tags: [tag] }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include(tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|