From 753bf8499ba5d8815db8d08a1dcf69caa20660cf Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Sat, 1 Apr 2023 12:00:33 -0600 Subject: Mejora estructura del proyecto --- spec/factories/product_review.rb | 10 ++++++++++ spec/models/product_review_spec.rb | 14 +++++++++++++- spec/requests/refresh_tokens_controller/post_spec.rb | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 spec/factories/product_review.rb (limited to 'spec') 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) -- cgit v1.2.3