Sha256: eb7fda03bb4b71ed54bc8723e5932e8c5e09987abe394afa48c098ef148d173d

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

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 }

  describe 'Errors' do
    before do
      stub_request(:get, /.*games/)
       .to_return(status: 401, body: '{}', headers: {})
    end
    context 'when token is invalid' do
      it 'should throw Unauthorized error' do
        invalid_strutta = Strutta::API.new 'not_a_token', host, path
        expect { invalid_strutta.games.all }.to raise_error(Strutta::Errors::Unauthorized)
      end
    end

    context 'when object does not exist' do
      before do
        stub_request(:get, /.*games\/\d+/)
         .to_return(status: 404, body: '{}', headers: {})
      end
      it 'should throw ObjectNotFoundError error' do
        expect { strutta.games(345).get }.to raise_error(Strutta::Errors::ObjectNotFoundError)
      end
    end

    context 'when parameters are missing' do
      before do
        stub_request(:post, %r{.*games\/\d+\/rounds})
         .to_return(status: 422, body: '{}', headers: {})
      end
      it 'should throw UnprocessableEntityError error' do
        expect { strutta.games(VALID_GAME_01[:id]).rounds.create(type: 'submission') }.to raise_error(Strutta::Errors::UnprocessableEntityError)
      end
    end

    context 'when parameters are missing' do
      before do
        stub_request(:post, %r{.*games\/\d+\/rounds})
         .to_return(status: 400, body: '{}', headers: {})
      end
      it 'should throw BadRequestError error' do
        expect { strutta.games(VALID_GAME_01[:id]).rounds.create(type: 'not_a_type') }.to raise_error(Strutta::Errors::BadRequestError)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strutta-api-1.0.3.1 spec/errors_spec.rb
strutta-api-1.0.2 spec/errors_spec.rb
strutta-api-1.0.1 spec/errors_spec.rb