summaryrefslogtreecommitdiff
path: root/spec/requests/carts_controller/create_spec.rb
blob: c0d2e4bba8ac7fafa4fe346fdf7f8f77f381e80f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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