Sha256: 9d27ceb90d2161622ad7f81209ed7ec6a31059aa0d92a3759679bb4e8255cb2c

Contents?: true

Size: 1.88 KB

Versions: 3

Compression:

Stored size: 1.88 KB

Contents

require "spec_helper"

describe RedboothRuby::Request::Validator do
  let(:info) { RedboothRuby::Request::Info.new(:get, nil, "random", OpenStruct.new(id: 1)) }
  let(:validator) { RedboothRuby::Request::Validator.new info }
  let(:headers) { {} }
  let(:response) { OpenStruct.new(body: '{"response":"ok"}', status: 200, headers: headers) }

  describe "#validated_response_for" do
    subject { validator.validated_response_for(response) }

    it { should be_a RedboothRuby::Request::Response }
    it { expect(subject.data).to eq("response" => "ok") }

    context 'where 401 status code returned' do
      let(:response) { OpenStruct.new(body: '{"error":{"message":"Unauthorized"}}', status: 401, headers: headers) }

      it { expect{subject}.to raise_error(RedboothRuby::AuthenticationError) }

      context 'where token was expired' do
        before { headers['WWW-Authenticate'] = %{Bearer realm="Doorkeeper", error="invalid_token", error_description="The access token was expired"} }

        it { expect{subject}.to raise_error(RedboothRuby::OauhtTokenExpired) }
      end

      context 'where token was revoked' do
        before { headers['WWW-Authenticate'] = %{Bearer realm="Doorkeeper", error="invalid_token", error_description="The access token was revoked"} }

        it { expect{subject}.to raise_error(RedboothRuby::OauhtTokenRevoked) }
      end
    end

    context 'where 500 status code returned' do
      let(:response) { OpenStruct.new(body: '{"error":{"message":"Something went wrong"}}', status: 500, headers: headers) }

      it { expect{subject}.to raise_error(RedboothRuby::APIError) }
    end

    context 'where 404 status code returned' do
      let(:response) { OpenStruct.new(body: '{"error":{"message":"There is no task with the given id in the system"}}', status: 404, headers: headers) }

      it { expect{subject}.to raise_error(RedboothRuby::NotFound) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redbooth-ruby-0.0.5 spec/redbooth-ruby/request/validator_spec.rb
redbooth-ruby-0.0.4 spec/redbooth-ruby/request/validator_spec.rb
redbooth-ruby-0.0.3 spec/redbooth-ruby/request/validator_spec.rb