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(:moderation_post) do [ { id: ENTRY_01[:id], pass: true }, { id: ENTRY_02[:id], pass: false }, { id: ENTRY_03[:id], pass: false } ] end describe 'games(:id).moderation' do context 'when no id is given' do context '.create' do context 'with valid parameters' do before do stub_request(:post, /.*moderation/) .to_return(status: 201, body: MODERATION_POST_RESPONSE.to_json, headers: {}) end it 'should return a new flow hash' do moderation = strutta.games(333).moderation.create(moderation: moderation_post) expect(moderation['results'].is_a? Array).to be true expect(moderation['results'].first['id'].is_a? Integer).to be true expect(moderation['results'].first['state'].is_a? Integer).to be true end end end context '.get' do before do stub_request(:get, /.*moderation/) .to_return(status: 200, body: MODERATION_GET.to_json, headers: {}) end it 'should throw disabled endpoint error' do moderation = strutta.games(333).moderation.get expect(moderation['results'].is_a? Array).to be true expect(moderation['results'].first['id'].is_a? Integer).to be true end end context '.all' do it 'should throw disabled endpoint error' do expect { game.moderation.all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.update' do it 'should throw disabled endpoint error' do expect { game.moderation.update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.delete' do it 'should throw disabled endpoint error' do expect { game.moderation.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.moderation(1).all({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.update' do it 'should throw disabled endpoint error' do expect { game.moderation(1).update({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.delete' do it 'should throw disabled endpoint error' do expect { game.moderation(1).delete({}) }.to raise_error(Strutta::Errors::DisabledEndpointError) end end context '.create' do it 'should throw error' do expect { game.moderation(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed) end end context '.get' do it 'should throw error' do expect { game.moderation(1).create }.to raise_error(Strutta::Errors::ObjectIDNotAllowed) end end end end end