Sha256: 03dcd7253c7ee7ff45b34c3f8f62f4c5284cb2bc261204de41c113b8d657ac2d

Contents?: true

Size: 1.9 KB

Versions: 19

Compression:

Stored size: 1.9 KB

Contents

require 'rails_helper'

describe LHS::Record do
  before do
    class Business < LHS::Record
      configuration(
        items_key: [:response, :businesses],
        total_key: [:response, :count],
        limit_key: { body: [:response, :max] },
        pagination_key: { body: [:response, :offset] },
        pagination_strategy: :offset
      )
      endpoint 'http://uberall/businesses'
    end
  end

  let(:stub_single_business_request) do
    stub_request(:get, "http://uberall/businesses?identifier=ABC123&limit=1")
      .to_return(body: {
        status: "SUCCESS",
        response: {
          offset: 0,
          max: 50,
          count: 1,
          businesses: [
            {
              identifier: 'ABC123',
              name: 'localsearch'
            }
          ]
        }
      }.to_json)
  end

  let(:stub_multiple_businesses_request) do
    stub_request(:get, "http://uberall/businesses?name=localsearch")
      .to_return(body: {
        status: "SUCCESS",
        response: {
          offset: 0,
          max: 50,
          count: 2,
          businesses: [
            {
              identifier: 'ABC123',
              name: 'localsearch'
            },
            {
              identifier: 'ABC121',
              name: 'Swisscom'
            }
          ]
        }
      }.to_json)
  end

  context 'access nested keys for configuration' do
    it 'uses paths from configuration to access nested values' do
      stub_single_business_request
      business = Business.find_by(identifier: 'ABC123')
      expect(business.identifier).to eq 'ABC123'
      expect(business.name).to eq 'localsearch'
    end

    it 'digs for meta data when meta information is nested' do
      stub_multiple_businesses_request
      businesses = Business.where(name: 'localsearch')
      expect(businesses.length).to eq 2
      expect(businesses.count).to eq 2
      expect(businesses.offset).to eq 0
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
lhs-16.1.5 spec/record/dig_configuration_spec.rb
lhs-16.1.4 spec/record/dig_configuration_spec.rb
lhs-16.1.3 spec/record/dig_configuration_spec.rb
lhs-16.1.2 spec/record/dig_configuration_spec.rb
lhs-16.1.1 spec/record/dig_configuration_spec.rb
lhs-16.1.0 spec/record/dig_configuration_spec.rb
lhs-16.0.1 spec/record/dig_configuration_spec.rb
lhs-16.0.0 spec/record/dig_configuration_spec.rb
lhs-15.7.0 spec/record/dig_configuration_spec.rb
lhs-15.6.1 spec/record/dig_configuration_spec.rb
lhs-15.6.0 spec/record/dig_configuration_spec.rb
lhs-15.5.1 spec/record/dig_configuration_spec.rb
lhs-15.5.0 spec/record/dig_configuration_spec.rb
lhs-15.4.1 spec/record/dig_configuration_spec.rb
lhs-15.4.0 spec/record/dig_configuration_spec.rb
lhs-15.4.0.pre.hasone.1 spec/record/dig_configuration_spec.rb
lhs-15.3.3 spec/record/dig_configuration_spec.rb
lhs-15.3.3.pre.fixoptions.1 spec/record/dig_configuration_spec.rb
lhs-15.3.2 spec/record/dig_configuration_spec.rb