Sha256: cd8fae9beed0426e4e865bd8c13d924e60acc8f0ec5392d2961104a70951ca4b

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe Qualtrics::Response, :vcr do
	# it 'has a body' do

	# end
  let(:test_endpoint) do
    Faraday.new do |builder|
      builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |m|
        m.get('/success') { |env| [ 200, {}, '{"Meta":{"Status":"Success","Debug":""},"Result":{"PanelID":"ML_8BKIZdmCic6tkLb"}}' ]}
        m.get('/server_error') { |env| [500, {}, '']}
        m.get('/server_error2') { |env| [400, {}, '{"Meta":{"Status":"Fubar","Debug":"","ErrorMessage":"Invalid request. Missing or invalid parameter RecipientID."}}']}
        m.get('/failure') { |env| [ 200, {}, '{"Meta":{"Status":"Fubar","Debug":""}}' ]}
      end
    end
  end

  it 'is successful when the meta status is success' do
    raw_response = test_endpoint.get('/success')
    response = Qualtrics::Response.new(raw_response)
    expect(response).to be_success
  end

  it 'is not successful when the meta status is not success' do
    raw_response = test_endpoint.get('/failure')
    response = Qualtrics::Response.new(raw_response)
    expect(response).to_not be_success
  end

  it 'has a result hash' do
    raw_response = test_endpoint.get('/success')
    response = Qualtrics::Response.new(raw_response)
    expect(response.result).to be_kind_of(Hash)
    expect(response.status).to eql(200)
  end

  it 'raises an exception when a 5xx error is received' do
    raw_response = test_endpoint.get('/server_error')
    expect(lambda{ Qualtrics::Response.new(raw_response)}).to raise_error(Qualtrics::ServerErrorEncountered)
  end

  it 'raises a error message when a 4xx error is received' do
    raw_response = test_endpoint.get('/server_error2')

    begin
      response = Qualtrics::Response.new(raw_response)
      expect(response.status).to eql(400)
    rescue Qualtrics::ServerErrorEncountered => e
      expect(e.message).to eql('Invalid request. Missing or invalid parameter RecipientID.')
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qualtrics-0.5.7 spec/qualtrics/response_spec.rb
qualtrics-0.5.6 spec/qualtrics/response_spec.rb
qualtrics-0.5.5 spec/qualtrics/response_spec.rb