summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-01 12:00:33 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-01 12:00:33 -0600
commit753bf8499ba5d8815db8d08a1dcf69caa20660cf (patch)
treec758e18e3009f9c6da002164686e88956430847b /spec
parent64214e370778dc3efdaca85acd0cd7a569a79b81 (diff)
Mejora estructura del proyecto
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/product_review.rb10
-rw-r--r--spec/models/product_review_spec.rb14
-rw-r--r--spec/requests/refresh_tokens_controller/post_spec.rb2
3 files changed, 24 insertions, 2 deletions
diff --git a/spec/factories/product_review.rb b/spec/factories/product_review.rb
new file mode 100644
index 0000000..b9778bd
--- /dev/null
+++ b/spec/factories/product_review.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+FactoryBot.define do
+ factory :product_review, class: 'ProductReview' do
+ user_account { create(:user_account) }
+ product { create(:product) }
+ review { Faker::Lorem.paragraphs }
+ rating { rand(1..5) }
+ end
+end
diff --git a/spec/models/product_review_spec.rb b/spec/models/product_review_spec.rb
index 9dfbff2..f4e4999 100644
--- a/spec/models/product_review_spec.rb
+++ b/spec/models/product_review_spec.rb
@@ -1,5 +1,17 @@
require 'rails_helper'
RSpec.describe ProductReview, type: :model do
- pending "add some examples to (or delete) #{__FILE__}"
+ let(:review) { build(:product_review) }
+
+ it { should validate_presence_of(:review) }
+ it { should validate_presence_of(:rating) }
+
+ describe 'rating' do
+ it 'cant be less than 1 or greater than 5' do
+ review.rating = -1
+ expect(review.save).to be_falsey
+ review.rating = 6
+ expect(review.save).to be_falsey
+ end
+ end
end
diff --git a/spec/requests/refresh_tokens_controller/post_spec.rb b/spec/requests/refresh_tokens_controller/post_spec.rb
index 5d8f8f0..c28301a 100644
--- a/spec/requests/refresh_tokens_controller/post_spec.rb
+++ b/spec/requests/refresh_tokens_controller/post_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe 'POST /api/refresh_tokens', type: :request do
context 'with an expired token' do
it 'returns an error message' do
service_params = { email: user.email, role: user.role }
- jwt = Services::TokenGenerationService.new(service_params).call(DateTime.current - 5.days)
+ jwt = TokenGenerationService.new(service_params).call(DateTime.current - 5.days)
headers = { 'CONTENT_TYPE' => 'application/json', 'Authorization' => "Bearer #{jwt[:refresh]}" }
post('/api/refresh_tokens', headers:)
expect(response).to have_http_status(401)