diff options
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/carts_controller/create_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
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 |