summaryrefslogtreecommitdiff
path: root/spec/requests/carts_controller/show_spec.rb
blob: b8a59ce8460276fb5442cbe1ea122e98436a6b92 (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
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'GET /api/account/cart', type: :request do
  let(:user) { create(:user_account) }
  let(:token) { jwt(user) }
  let(:headers) { { 'Authorization' => "Bearer #{token['token']}" } }
  let(:product) { create(:product) }

  before(:each) do
    cart = Cart.new(user_account_id: user.id)
    cart.save
    user.cart = cart
    user.save
    user.cart.add_product(product.id, 1)
    user.cart.save
  end

  it_behaves_like 'a GET resource request', sole_route: true do
    let(:route) { '/api/account/cart' }
    let(:expected_text) do
      [product.name, product.bulk_price.to_i, product.unitary_price.to_i, user.cart.product_carts.first.quantity]
    end
  end
end