Sha256: 557aeca2e566a2b1cd6cbf5086b40ef72a97b5157e33a0bfd1629cf23b89b379

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'

describe Direct::API::V5::Response do
  let(:headers) do
    {
      RequestId: '123',
      Units: '10/100/200'
    }
  end
  let(:body) do
    {
      result: {
        Campaigns: []
      }
    }
  end
  let(:error_body) do
    {
      error: {
        error_code: 54,
        error_string: 'No rights',
        error_detail: 'No rights to indicated client'
      }
    }
  end

  let(:response) { described_class.new(body, headers) }
  let(:error_response) { described_class.new(error_body, headers) }

  describe '#result' do
    it 'return data from result key' do
      expect(response.result).to eq(Campaigns: [])
      expect(error_response.result).to be_nil
    end
  end

  describe '#request_id' do
    it 'return data from headers' do
      expect(response.request_id).to eq('123')
      expect(error_response.request_id).to eq('123')
    end
  end

  describe '#units' do
    it 'return Units object' do
      expect(response.units).to be_a(Direct::API::V5::Response::Units)
      expect(response.units.raw).to eq('10/100/200')
    end
  end

  describe '#error?' do
    it 'check error key' do
      expect(response.error?).to eq(false)
      expect(error_response.error?).to eq(true)
    end
  end

  describe '#error' do
    it 'return Error object' do
      expect(response.error).to be_nil

      expect(error_response.error).to be_a(Direct::API::V5::Response::Error)
      expect(error_response.error.code).to eq(54)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
direct-api-v5-0.1.2 spec/direct/api/v5/response_spec.rb
direct-api-v5-0.1.1 spec/direct/api/v5/response_spec.rb
direct-api-v5-0.1.0 spec/direct/api/v5/response_spec.rb