summaryrefslogtreecommitdiff
path: root/spec/requests/reviews_controller/create_spec.rb
blob: 8ff2f0c5d69cdc366a148aefa245cd3f3c06ca97 (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
26
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'POST /api/products/:product_id/reviews', type: :request do
  let(:review) { build(:product_review) }
  let(:product) { create(:product) }
  let(:user) { create(:user_account, role: 'regular') }
  let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
  let(:token) { jwt(user) }
  let(:params) { { review: review.review, rating: review.rating } }

  it_behaves_like 'a POST request' do
    let(:route) { "/api/products/#{product.public_id}/reviews" }
    let(:expected_error_messages) do
      ["can't be blank", "can't be blank", 'is not included in the list']
    end
    let(:desired_error_status) { 422 }
    let(:expected_text) do
      [review.review, review.rating]
    end
    let(:wrong_params) do
      { review: '', rating: '' }
    end
  end
end