2019-11-04 16:18:09 +01:00
describe WebhookController , type : :controller do
2022-11-03 11:31:18 +01:00
before do
allow ( controller ) . to receive ( :verify_signature! ) . and_return ( true )
allow ( controller ) . to receive ( :verify_authenticity_token )
end
describe '#helpscout_support_dev' do
subject ( :response ) { post :helpscout_support_dev , params : payload }
let ( :payload ) { JSON . parse ( File . read ( Rails . root . join ( 'spec' , 'fixtures' , 'files' , 'helpscout' , 'tagged-dev.json' ) ) ) }
it 'works' do
allow ( Rails . application . secrets ) . to receive ( :dig ) . with ( :mattermost , :support_webhook_url ) . and_return ( " https://notification_url " )
expect ( controller ) . to receive ( :send_mattermost_notification ) . with ( " \n Nouveau bug taggué # dev : https://secure.helpscout.net/conversation/123456789/123456789?folderId=123456789 \n \n > Bonjour, Je voudrais faire une demande de changement d'adresse et la plateforme m'indique que j'ai plusieurs comptes et que je dois d'abord les fusionner. Cela fait 3 jours que j'essaie de fusio \n \n **personnes impliquées** : anonymous@anon.fr \n **utilisateur en attente depuis** : 11 min ago " )
subject
2020-08-10 17:18:10 +02:00
end
2022-11-03 11:31:18 +01:00
end
2019-11-04 16:18:09 +01:00
2022-11-03 11:31:18 +01:00
describe '#helpscout' do
2019-11-04 16:18:09 +01:00
subject ( :response ) { get :helpscout , params : { customer : { email : customer_email } } }
let ( :payload ) { JSON . parse ( subject . body ) }
2020-08-10 17:18:10 +02:00
let ( :customer_email ) { 'a-user@exemple.fr' }
it " doesn't verify authenticity token " do
subject
expect ( controller ) . not_to have_received ( :verify_authenticity_token )
end
2019-11-04 16:18:09 +01:00
context 'when there is no matching user' do
let ( :customer_email ) { 'not-a-user@exemple.fr' }
it 'returns an empty response' do
expect ( subject . status ) . to eq ( 404 )
expect ( subject . body ) . to be_empty
end
end
context 'when there is a matching user' do
2020-09-18 09:57:26 +02:00
let ( :user ) { create ( :user , :with_strong_password ) }
2019-11-04 16:18:09 +01:00
let ( :customer_email ) { user . email }
it 'returns a 200 response' do
expect ( subject . status ) . to eq ( 200 )
expect ( subject . body ) . to be_present
end
it 'returns a link to the User profile in the Manager' do
expect ( payload ) . to have_key ( 'html' )
expect ( payload [ 'html' ] ) . to have_selector ( " a[href=' #{ manager_user_url ( user ) } '] " )
end
context 'when there are an associated Instructeur and Administrateur' do
let! ( :instructeur ) { create ( :instructeur , user : user ) }
2021-10-25 15:50:48 +02:00
let! ( :admin ) { create ( :administrateur , user : user , instructeur : instructeur ) }
2019-11-04 16:18:09 +01:00
it 'returns a link to the Instructeur profile in the Manager' do
expect ( payload ) . to have_key ( 'html' )
expect ( payload [ 'html' ] ) . to have_selector ( " a[href=' #{ manager_instructeur_url ( instructeur ) } '] " )
end
it 'returns a link to the Administrateur profile in the Manager' do
expect ( payload ) . to have_key ( 'html' )
expect ( payload [ 'html' ] ) . to have_selector ( " a[href=' #{ manager_administrateur_url ( admin ) } '] " )
end
end
end
end
end