require 'spec_helper' describe 'Strutta API Wrapper' do before { WebMock.disable_net_connect!(allow_localhost: true, allow: /codeclimate/) } after { WebMock.allow_net_connect! } let(:token) { 'dc1479c52801fbfa0975947de092a1e7' } let(:host) { 'http://api.strutta.dev:4000' } let(:path) { '/v2/' } let(:strutta) { Strutta::API.new token, host, path } let(:point_params) do { round_id: POINTS_ROUND[:id], entry_id: ENTRY_01[:id], participant: PARTICIPANT_01[:id], weight: 5 } end let(:new_game) { strutta.games.create } let(:game) { strutta.games(VALID_GAME_01[:id]) } describe 'games(:id).points' do context 'when no id is given' do context '.create' do context 'with valid parameters' do before do stub_request(:post, /.*points/) .to_return(status: 201, body: POINTS_RESPONSE.to_json, headers: {}) end it 'should return a new flow hash' do points = strutta.games(333).points.create(point_params) expect(points['id'].is_a? Integer).to be true expect(points['weight']).to eq point_params[:weight] end end end context '.all' do it 'should throw disabled endpoint error' do expect { game.points.all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.get' do it 'should throw disabled endpoint error' do expect { game.points.get({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.update' do it 'should throw disabled endpoint error' do expect { game.points.update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.delete' do it 'should throw disabled endpoint error' do expect { game.points.delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end end context 'when id is given' do context '.all' do it 'should throw disabled endpoint error' do expect { game.points(1).all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.get' do it 'should throw disabled endpoint error' do expect { game.points(1).get({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.update' do it 'should throw disabled endpoint error' do expect { game.points(1).update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.delete' do it 'should throw disabled endpoint error' do expect { game.points(1).delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.create' do it 'should throw error' do expect { game.flow(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed) end end end end end