Sha256: 2f9edf0609126068ffbf59b15e4a69d61229b54188c3d11e24f8c0e5bf7e3401

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

require 'rails_helper'

describe LHC do
  context 'post' do
    let(:feedback) do
      {
        recommended: true,
        source_id: 'aaa',
        content_ad_id: '1z-5r1fkaj'
      }
    end

    before(:each) do
      stub_request(:post, "http://datastore/v2/feedbacks")
        .with(body: feedback.to_json)
        .to_return(status: 200, body: feedback.to_json, headers: { 'Content-Encoding' => 'UTF-8' })
    end

    it 'does a post request when providing a complete url' do
      described_class.post('http://datastore/v2/feedbacks', body: feedback.to_json)
    end

    it 'does a post request when providing the name of a configured endpoint' do
      url = 'http://:datastore/v2/feedbacks'
      options = { params: { datastore: 'datastore' } }
      described_class.configure { |c| c.endpoint(:feedbacks, url, options) }
      described_class.post(:feedbacks, body: feedback.to_json)
    end

    it 'it makes response data available in a rails way' do
      response = described_class.post('http://datastore/v2/feedbacks', body: feedback.to_json)
      expect(response.data.source_id).to eq 'aaa'
    end

    it 'provides response headers' do
      response = described_class.post('http://datastore/v2/feedbacks', body: feedback.to_json)
      expect(response.headers).to be
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lhc-3.5.4 spec/basic_methods/post_spec.rb
lhc-3.5.3 spec/basic_methods/post_spec.rb
lhc-3.5.2 spec/basic_methods/post_spec.rb
lhc-3.5.1 spec/basic_methods/post_spec.rb
lhc-3.5.0 spec/basic_methods/post_spec.rb