Add helpscout API adapter
This commit is contained in:
parent
c1bdb8a4be
commit
6453b53a41
3 changed files with 259 additions and 0 deletions
70
spec/lib/helpscout/form_adapter_spec.rb
Normal file
70
spec/lib/helpscout/form_adapter_spec.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Helpscout::FormAdapter do
|
||||
describe '#send_form' do
|
||||
let(:api) { spy(double(:api)) }
|
||||
|
||||
context 'create_conversation' do
|
||||
before do
|
||||
allow(api).to receive(:create_conversation)
|
||||
.and_return(double(success?: false))
|
||||
described_class.new(params, api).send_form
|
||||
end
|
||||
|
||||
let(:params) {
|
||||
{
|
||||
email: email,
|
||||
subject: subject,
|
||||
text: text
|
||||
}
|
||||
}
|
||||
let(:email) { 'paul.chavard@beta.gouv.fr' }
|
||||
let(:subject) { 'Bonjour' }
|
||||
let(:text) { "J'ai un problem" }
|
||||
|
||||
it 'should call method' do
|
||||
expect(api).to have_received(:create_conversation)
|
||||
.with(email, subject, text, nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'add_tags' do
|
||||
before do
|
||||
allow(api).to receive(:create_conversation)
|
||||
.and_return(
|
||||
double(
|
||||
success?: true,
|
||||
headers: {
|
||||
'Resource-ID' => conversation_id
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
described_class.new(params, api).send_form
|
||||
end
|
||||
|
||||
let(:params) {
|
||||
{
|
||||
email: email,
|
||||
subject: subject,
|
||||
text: text,
|
||||
tags: tags
|
||||
}
|
||||
}
|
||||
let(:email) { 'paul.chavard@beta.gouv.fr' }
|
||||
let(:subject) { 'Bonjour' }
|
||||
let(:text) { "J'ai un problem" }
|
||||
let(:tags) { ['info demarche'] }
|
||||
let(:conversation_id) { '123' }
|
||||
|
||||
it 'should call method' do
|
||||
expect(api).to have_received(:create_conversation)
|
||||
.with(email, subject, text, nil)
|
||||
expect(api).to have_received(:add_tags)
|
||||
.with(conversation_id, tags)
|
||||
expect(api).to have_received(:add_custom_fields)
|
||||
.with(conversation_id, nil, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue