Sha256: 586f2c439b5014b2b73dba02cb405c8dd3b09824b53a6c4fa9780a2ec9bc7a0d

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

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 '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
    end
  end

  context 'get json' do
    before(:each) do
      stub_request(:get, 'http://datastore/v2/feedbacks').with(headers: { 'Content-Type' => 'application/json' })
        .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

13 entries across 13 versions & 1 rubygems

Version Path
lhc-8.1.1 spec/basic_methods/get_spec.rb
lhc-9.0.0 spec/basic_methods/get_spec.rb
lhc-8.1.0 spec/basic_methods/get_spec.rb
lhc-8.0.0 spec/basic_methods/get_spec.rb
lhc-7.3.3 spec/basic_methods/get_spec.rb
lhc-7.3.2 spec/basic_methods/get_spec.rb
lhc-7.3.1 spec/basic_methods/get_spec.rb
lhc-7.3.0 spec/basic_methods/get_spec.rb
lhc-7.2.0 spec/basic_methods/get_spec.rb
lhc-7.1.0 spec/basic_methods/get_spec.rb
lhc-7.0.1 spec/basic_methods/get_spec.rb
lhc-7.0.0 spec/basic_methods/get_spec.rb
lhc-7.0.0.beta1 spec/basic_methods/get_spec.rb