# encoding: utf-8 # require 'spec_helper' describe Mode::Sdk::Client::Response do describe '#code' do it 'returns http response code as an integer' do http_response = double(:http_response, code: '200') response = Mode::Sdk::Client::Response.new(http_response) expect(response.code).to eq(200) end end describe '#body' do it 'parses response body' do http_response = double(:http_response, body: '{"foo":"bar"}') response = Mode::Sdk::Client::Response.new(http_response) expect(response.body).to eq('foo' => 'bar') end end describe '#validate!' do it 'raises exception if response is 401' do http_response = double(:http_response, code: '401') response = Mode::Sdk::Client::Response.new(http_response, [200]) expect { response.validate! }.to raise_error(Mode::Sdk::Client::AuthenticationError) end it 'raises exception if response is 403' do http_response = double(:http_response, code: '403') response = Mode::Sdk::Client::Response.new(http_response, [200]) expect { response.validate! }.to raise_error(Mode::Sdk::Client::AuthorizationError) end it 'raises exception if response is unexpected' do http_response = double(:http_response, code: '200', body: '{}') response = Mode::Sdk::Client::Response.new(http_response, [201]) expect { response.validate! }.to raise_error(Mode::Sdk::Client::ResponseError) end it 'returns true if response is expected' do http_response = double(:http_response, code: '201') response = Mode::Sdk::Client::Response.new(http_response, [201]) expect(response.validate!).to eq(true) end end end