From 4611fdd6da7f9a1cc04144104e5ca26398f1b502 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Thu, 6 Apr 2023 15:29:08 -0600 Subject: AƱade specs de product_cart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/requests/carts_controller/create_spec.rb | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 spec/requests/carts_controller/create_spec.rb (limited to 'spec/requests/carts_controller') diff --git a/spec/requests/carts_controller/create_spec.rb b/spec/requests/carts_controller/create_spec.rb new file mode 100644 index 0000000..c0d2e4b --- /dev/null +++ b/spec/requests/carts_controller/create_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'POST /account/cart', type: :request do + let(:cart) { create(:cart) } + let(:products) { create_list(:product, 2) } + let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } } + let(:token) { jwt(cart.user_account) } + let(:params) do + { product_id: products[0].id, quantity: 1 } + end + + before(:each) do + cart.user_account.cart = cart + cart.user_account.save + end + + it_behaves_like 'a POST request' do + let(:route) { '/api/account/cart' } + let(:expected_error_messages) do + ['must exist', 'must be greater than 0'] + end + let(:desired_error_status) { 422 } + let(:expected_text) do + [products[0].name, 'quantity'] + end + let(:wrong_params) do + { product_id: SecureRandom.hex(25), quantity: -1 } + end + end +end -- cgit v1.2.3