Skip to content

Commit

Permalink
Support updating customer emails
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemanrubia committed Dec 15, 2020
1 parent 918008e commit e3d11a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/help_scout/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ def initialize(params = {})

@hrefs = HelpScout::Util.map_links(params[:_links])
end

def update_email(email_id, new_email, type: :other)
email_path = "#{URI.parse(hrefs[:self]).path}/emails/#{email_id}"
HelpScout.api.put(email_path, { type: type, value: new_email })
true
end
end
end
14 changes: 13 additions & 1 deletion spec/integration/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@
include_examples 'listable integration'

describe 'list' do
it "finds customers filtered with query" do
it 'finds customers filtered with query' do
result = described_class.list(query: '(email="[email protected]")')

expect(result).to be_a Array
expect(result).to all(be_a(described_class))
end
end

describe '#update_email' do
it 'updates the customer email' do
customer = described_class.get(id)
original_email = customer.emails.first
new_email = "changed#{original_email[:value]}"

expect(customer.update_email(original_email[:id], new_email, type: original_email[:type])).to be_truthy
expect(described_class.get(id).emails.first[:value]).to eq(new_email)
end
end
end
2 changes: 1 addition & 1 deletion spec/shared_examples/integration/listable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
expect(subject).to all(be_a(described_class))
end
end
end
end

0 comments on commit e3d11a7

Please sign in to comment.