-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7df4572
commit d96415f
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe Seam::Errors::SeamHttpInvalidInputError do | ||
let(:api_key) { "seam_apikey1_token" } | ||
let(:client) { Seam::Client.new(api_key: api_key) } | ||
|
||
describe "handling invalid input errors" do | ||
let(:error_response) do | ||
{ | ||
error: { | ||
type: "invalid_input", | ||
message: "Invalid input", | ||
validation_errors: { | ||
device_ids: { | ||
_errors: ["Expected array, received number"] | ||
} | ||
} | ||
} | ||
} | ||
end | ||
|
||
it "raises SeamHttpInvalidInputError with correct validation messages" do | ||
stub_seam_request(:post, "/devices/list", | ||
error_response, | ||
status: 400).with do |req| | ||
req.body.source == {device_ids: 123}.to_json | ||
end | ||
|
||
expect { | ||
client.devices.list(device_ids: 123) | ||
}.to raise_error(Seam::Errors::SeamHttpInvalidInputError) do |error| | ||
expect(error.code).to eq("invalid_input") | ||
expect(error.status_code).to eq(400) | ||
expect(error.get_validation_error_messages("device_ids")).to eq(["Expected array, received number"]) | ||
end | ||
end | ||
|
||
it "returns an empty array for non-existent validation errors" do | ||
stub_seam_request(:post, "/devices/list", | ||
error_response, | ||
status: 400).with do |req| | ||
req.body.source == {device_ids: 123}.to_json | ||
end | ||
|
||
begin | ||
client.devices.list(device_ids: 123) | ||
rescue Seam::Errors::SeamHttpInvalidInputError => error | ||
expect(error.get_validation_error_messages("non_existent_field")).to eq([]) | ||
end | ||
end | ||
end | ||
end |