|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe WebhookController, type: :controller do |
| 4 | + describe '#helpscout' do |
| 5 | + before { allow(controller).to receive(:verify_signature!).and_return(true) } |
| 6 | + |
| 7 | + subject(:response) { get :helpscout, params: { customer: { email: customer_email } } } |
| 8 | + |
| 9 | + let(:payload) { JSON.parse(subject.body) } |
| 10 | + |
| 11 | + context 'when there is no matching user' do |
| 12 | + let(:customer_email) { 'not-a-user@exemple.fr' } |
| 13 | + |
| 14 | + it 'returns an empty response' do |
| 15 | + expect(subject.status).to eq(404) |
| 16 | + expect(subject.body).to be_empty |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + context 'when there is a matching user' do |
| 21 | + let(:user) { create(:user) } |
| 22 | + let(:customer_email) { user.email } |
| 23 | + |
| 24 | + it 'returns a 200 response' do |
| 25 | + expect(subject.status).to eq(200) |
| 26 | + expect(subject.body).to be_present |
| 27 | + end |
| 28 | + |
| 29 | + it 'returns a link to the User profile in the Manager' do |
| 30 | + expect(payload).to have_key('html') |
| 31 | + expect(payload['html']).to have_selector("a[href='#{manager_user_url(user)}']") |
| 32 | + end |
| 33 | + |
| 34 | + context 'when there are an associated Instructeur and Administrateur' do |
| 35 | + let!(:instructeur) { create(:instructeur, user: user) } |
| 36 | + let!(:admin) { create(:administrateur, user: user) } |
| 37 | + |
| 38 | + it 'returns a link to the Instructeur profile in the Manager' do |
| 39 | + expect(payload).to have_key('html') |
| 40 | + expect(payload['html']).to have_selector("a[href='#{manager_instructeur_url(instructeur)}']") |
| 41 | + end |
| 42 | + |
| 43 | + it 'returns a link to the Administrateur profile in the Manager' do |
| 44 | + expect(payload).to have_key('html') |
| 45 | + expect(payload['html']).to have_selector("a[href='#{manager_administrateur_url(admin)}']") |
| 46 | + end |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | +end |
0 commit comments