summaryrefslogtreecommitdiff
path: root/spec/requests/reviews_controller/index_spec.rb
blob: 1a2863d0117cce9e9d27b92ee4e48447f7b44062 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'rails_helper'

RSpec.describe 'GET /api/products/:product_id/reviews', type: :request do
  let!(:product) { create(:product, public_id: SecureRandom.hex(12)) }

  before(:each) do
    create_list(:product_review, 26, product:)
  end

  it_behaves_like 'a GET index request' do
    let(:headers) { {} }
    let(:route) { "/api/products/#{product.public_id}/reviews" }
    let(:pagination_size) { 15 }
  end

  describe '?by=:user_account_id' do
    it 'tells if a product has a review made by the user with the id' do
      user = create(:user_account)
      create(:product_review, user_account: user, product:)
      get "/api/products/#{product.public_id}/reviews?by=#{user.id}"
      expect(response).to have_http_status(200)
      expect(response.body).to include('true')
    end
  end
end