Skip to content

Commit ce7f0fb

Browse files
Merge pull request #12 from Springest/actual_validation_errors
Actual validation errors
2 parents bc55ded + 496a818 commit ce7f0fb

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

help_scout.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ require 'help_scout/version'
66
Gem::Specification.new do |spec|
77
spec.name = "help_scout"
88
spec.version = HelpScout::VERSION
9-
spec.authors = ["Dennis Paagman", "Miriam Tocino", "Mark Mulder"]
10-
9+
spec.authors = ["Dennis Paagman", "Miriam Tocino", "Mark Mulder", "Martin Balk"]
10+
1111

1212
spec.summary = "HelpScout is an API client for Help Scout"
1313
spec.homepage = "https://github.com/Springest/help_scout"

lib/help_scout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def request(method, path, options)
234234
when HTTP_OK, HTTP_CREATED, HTTP_NO_CONTENT
235235
@last_response.parsed_response
236236
when HTTP_BAD_REQUEST
237-
raise ValidationError, last_response.parsed_response["message"]
237+
raise ValidationError, last_response.parsed_response["validationErrors"]
238238
when HTTP_FORBIDDEN
239239
raise ForbiddenError
240240
when HTTP_NOT_FOUND

spec/helpscout_spec.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
context 'with invalid input' do
2323
it 'returns validation errors' do
24-
data = { subject: "Help me!", customer: { email: "" } }
24+
data = { subject: "Help me!", customer: { email: "[email protected]" } }
2525

2626
url = 'https://api.helpscout.net/v1/conversations.json'
2727
stub_request(:post, url).
@@ -30,10 +30,19 @@
3030
headers: {
3131
'Content-Type' => 'application/json'
3232
},
33-
body: { error: "Input could not be validated", message: "Email is not valid" }.to_json
33+
body: {
34+
"error" => "Input could not be validated",
35+
"validationErrors" => [
36+
{
37+
"property" => "customer:email",
38+
"value" => "[email protected]",
39+
"message" => "Email is not valid"
40+
}
41+
]
42+
}.to_json
3443
)
3544

36-
expect { client.create_conversation(data) }.to raise_error(HelpScout::ValidationError, "Email is not valid")
45+
expect { client.create_conversation(data) }.to raise_error(HelpScout::ValidationError, '[{"property"=>"customer:email", "value"=>"[email protected]", "message"=>"Email is not valid"}]')
3746
end
3847
end
3948

0 commit comments

Comments
 (0)