summaryrefslogtreecommitdiff
path: root/spec/requests/reviews_controller
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/reviews_controller')
-rw-r--r--spec/requests/reviews_controller/create_spec.rb26
-rw-r--r--spec/requests/reviews_controller/index_spec.rb25
2 files changed, 51 insertions, 0 deletions
diff --git a/spec/requests/reviews_controller/create_spec.rb b/spec/requests/reviews_controller/create_spec.rb
new file mode 100644
index 0000000..8ff2f0c
--- /dev/null
+++ b/spec/requests/reviews_controller/create_spec.rb
@@ -0,0 +1,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
diff --git a/spec/requests/reviews_controller/index_spec.rb b/spec/requests/reviews_controller/index_spec.rb
new file mode 100644
index 0000000..1a2863d
--- /dev/null
+++ b/spec/requests/reviews_controller/index_spec.rb
@@ -0,0 +1,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