Sha256: 3c40be94817be8a01e11b96749d613248e2bcd4c09810ee1b62ac82d6fef30ed

Contents?: true

Size: 1.53 KB

Versions: 49

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHC do
  context 'get' do
    before(:each) do
      stub_request(:get, 'http://datastore/v2/feedbacks?has_reviews=true')
        .to_return(status: 200, body: { total: 99 }.to_json, headers: { 'Content-Encoding' => 'UTF-8' })
    end

    let(:parameters) do
      { has_reviews: true }
    end

    it 'does a get request when providing a complete url' do
      LHC.get('http://datastore/v2/feedbacks', params: parameters)
    end

    it 'does a get request when providing the name of a configured endpoint' do
      url = 'http://{+datastore}/v2/feedbacks'
      options = { params: { datastore: 'datastore' } }
      LHC.configure { |c| c.endpoint(:feedbacks, url, options) }
      LHC.get(:feedbacks, params: parameters)
    end

    it 'makes response data available in a rails way' do
      response = LHC.get('http://datastore/v2/feedbacks', params: parameters)
      expect(response.data.total).to eq 99
    end

    it 'provides response headers' do
      response = LHC.get('http://datastore/v2/feedbacks', params: parameters)
      expect(response.headers).to be_present
    end
  end

  context 'get json' do
    before(:each) do
      stub_request(:get, 'http://datastore/v2/feedbacks').with(headers: { 'Content-Type' => 'application/json; charset=utf-8' })
        .to_return(body: { some: 'json' }.to_json)
    end

    it 'requests json and parses response body' do
      data = LHC.json.get('http://datastore/v2/feedbacks').data
      expect(data.some).to eq 'json'
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
lhc-15.2.1 spec/basic_methods/get_spec.rb
lhc-15.2.0 spec/basic_methods/get_spec.rb
lhc-15.1.3 spec/basic_methods/get_spec.rb
lhc-15.1.2 spec/basic_methods/get_spec.rb
lhc-15.1.1 spec/basic_methods/get_spec.rb
lhc-15.1.0 spec/basic_methods/get_spec.rb
lhc-16.0.0.pre.pro2162.2 spec/basic_methods/get_spec.rb
lhc-16.0.0.pre.pro2162 spec/basic_methods/get_spec.rb
lhc-15.0.1 spec/basic_methods/get_spec.rb
lhc-15.0.0 spec/basic_methods/get_spec.rb
lhc-14.0.0 spec/basic_methods/get_spec.rb
lhc-13.4.0.pre.pro1766.1 spec/basic_methods/get_spec.rb
lhc-13.2.0 spec/basic_methods/get_spec.rb
lhc-13.1.0 spec/basic_methods/get_spec.rb
lhc-13.0.0 spec/basic_methods/get_spec.rb
lhc-12.3.0 spec/basic_methods/get_spec.rb
lhc-12.2.1 spec/basic_methods/get_spec.rb
lhc-12.2.0 spec/basic_methods/get_spec.rb
lhc-12.1.3 spec/basic_methods/get_spec.rb
lhc-12.1.2 spec/basic_methods/get_spec.rb