# encoding: utf-8 # require 'spec_helper' describe Mode::Sdk::Client do describe '.head' do it 'performs a head request' do expect(Mode::Sdk::Client).to receive(:request) do |request| expect(request).to be_an_instance_of(Net::HTTP::Head) end Mode::Sdk::Client.head('some/path') end end describe '.get' do it 'performs a get request' do expect(Mode::Sdk::Client).to receive(:request) do |request| expect(request).to be_an_instance_of(Net::HTTP::Get) end Mode::Sdk::Client.get('some/path') end end describe '.post' do it 'performs a post request' do expect(Mode::Sdk::Client).to receive(:request) do |request| expect(request).to be_an_instance_of(Net::HTTP::Post) end Mode::Sdk::Client.post('some/path', nil) end end describe '.put' do it 'performs a put request' do expect(Mode::Sdk::Client).to receive(:request) do |request| expect(request).to be_an_instance_of(Net::HTTP::Put) end Mode::Sdk::Client.put('some/path', nil) end end describe '.request' do it 'returns response' do mock_response = Mode::Sdk::Client::Response.new(nil) expect_any_instance_of(Mode::Sdk::Client::Request).to( receive(:response).and_return(mock_response)) response = Mode::Sdk::Client.send(:request, nil, nil) expect(response).to be_an_instance_of(Mode::Sdk::Client::Response) end end describe '.account' do it 'returns account representation' do mock_response = double(:response, body: { 'username' => 'someone' }) expect_any_instance_of(Mode::Sdk::Client::Request).to( receive(:response).and_return(mock_response)) response = Mode::Sdk::Client.account expect(response).to eq('username' => 'someone') end end describe '.authenticated' do it 'returns true if authenticated' do mock_response = double(:response, code: 200) expect_any_instance_of(Mode::Sdk::Client::Request).to( receive(:response).and_return(mock_response)) expect(Mode::Sdk::Client.authenticated?).to eq(true) end it 'returns false if not authenticated' do mock_response = double(:response, code: 401) expect_any_instance_of(Mode::Sdk::Client::Request).to( receive(:response).and_return(mock_response)) expect(Mode::Sdk::Client.authenticated?).to eq(false) end end end