require 'rails_helper'

RSpec.describe ShopsController, type: :controller do

  let!(:shops) do
    Array(1..4).collect { FactoryGirl.create :shop }
  end

  describe 'GET #index' do
    it 'should respond with all shops' do
      get :index

      expect(response).to have_http_status :ok

      data = JSON.parse(response.body)['data']
      expect(data.count).to eq shops.count
      data.each { |d| expect(d['id'].in? shops.collect(&:id)) }
    end
  end

  describe 'GET #show' do
    context 'with a valid shop' do
      let(:shop) { shops.sample }

      it 'should respond with the requested shop' do
        get :show, params: { id: shop.id }

        expect(response).to have_http_status :ok

        data = JSON.parse(response.body)['data']
        expect(data).to be_a Hash
        expect(data['id']).to eq shop.id.to_s
      end
    end
  end
end
