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(:new_game) { strutta.games.create } let(:game) { strutta.games(VALID_GAME_01[:id]) } let(:flow_no_game) { strutta.games.flow } let(:flow_params) do { definition: [ { id: SUBMISSION_ROUND[:id], pass_round: RANDOM_DRAW_ROUND[:id], fail_round: nil, start: true }, { id: RANDOM_DRAW_ROUND[:id], pass_round: PRIZE_FULFILLMENT_ROUND[:id], fail_round: nil }, { id: PRIZE_FULFILLMENT_ROUND[:id], pass_round: nil, fail_round: nil } ] } end let(:flow) { game.flow.create(flow_params) } describe 'games(:id).flow' do context 'when no id is given' do context '.get' do before do stub_request(:get, /.*flow/) .to_return(status: 200, body: FLOW.to_json, headers: {}) end it 'should return flow hash' do f = game.flow.get expect(f['flow'].is_a? Array).to be true end end context '.delete' do before do stub_request(:delete, /.*flow/) .to_return(status: 204, body: '', headers: {}) end it 'should delete flow' do expect(game.flow.delete).to be true end end context '.create' do context 'with valid parameters' do before do stub_request(:post, /.*flow/) .to_return(status: 201, body: FLOW.to_json, headers: {}) end it 'should return a new flow hash' do expect(flow['flow'].is_a? Array).to be true expect(flow['flow'].first['id']).to eq(SUBMISSION_ROUND[:id]) end end end context '.update' do it 'should throw error' do expect { game.flow.update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.all' do it 'should throw error' do expect { game.flow.all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end end context 'when id is given' do context '.get' do it 'should throw error' do expect { game.flow(1).get }.to raise_error(Strutta::Errors::ObjectIDNotAllowed) end end context '.delete' do it 'should throw error' do expect { game.flow(1).delete }.to raise_error(Strutta::Errors::ObjectIDNotAllowed) end end context '.create' do it 'should throw error' do expect { game.flow(1).create(flow_params) }.to raise_error(Strutta::Errors::ObjectIDNotAllowed) end end context '.update' do it 'should throw error' do expect { game.flow(1).update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.all' do it 'should throw error' do expect { game.flow(1).all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end end end end