Sha256: c7855a00c71bfddd8d65c57c5d950c85a1a335607e5263ef106f2f345b99a14f

Contents?: true

Size: 1.93 KB

Versions: 76

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

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

76 entries across 76 versions & 1 rubygems

Version Path
lhs-26.2.0 spec/record/dig_configuration_spec.rb
lhs-26.1.0 spec/record/dig_configuration_spec.rb
lhs-26.0.1 spec/record/dig_configuration_spec.rb
lhs-26.0.0 spec/record/dig_configuration_spec.rb
lhs-25.2.0 spec/record/dig_configuration_spec.rb
lhs-25.1.0 spec/record/dig_configuration_spec.rb
lhs-25.0.4 spec/record/dig_configuration_spec.rb
lhs-25.0.3 spec/record/dig_configuration_spec.rb
lhs-25.0.2 spec/record/dig_configuration_spec.rb
lhs-25.0.1 spec/record/dig_configuration_spec.rb
lhs-25.0.0 spec/record/dig_configuration_spec.rb
lhs-24.1.2 spec/record/dig_configuration_spec.rb
lhs-24.1.1 spec/record/dig_configuration_spec.rb
lhs-24.1.0 spec/record/dig_configuration_spec.rb
lhs-24.1.0.pre.2 spec/record/dig_configuration_spec.rb
lhs-24.1.0.pre.1 spec/record/dig_configuration_spec.rb
lhs-24.0.0 spec/record/dig_configuration_spec.rb
lhs-23.0.2 spec/record/dig_configuration_spec.rb
lhs-23.0.1 spec/record/dig_configuration_spec.rb
lhs-23.0.0 spec/record/dig_configuration_spec.rb