summaryrefslogtreecommitdiff
path: root/spec/controllers/spree/api/users_controller_spec.rb
blob: 21d5185b9420c98e17f59c53d3b3b297ca0bc417 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

require 'spec_helper'
require 'spree/api/testing_support/helpers'

RSpec.describe Spree::Api::UsersController, type: :controller do
  include Spree::Api::TestingSupport::Helpers
  routes { Spree::Core::Engine.routes }

  let!(:user) do
    create(:user, &:generate_spree_api_key).tap(&:save)
  end
  let!(:subscription) { create :subscription, :with_line_item, user: user }

  describe 'patch /update' do
    subject { patch :update, params: params }

    let(:params) do
      {
        id: user.id,
        token: user.spree_api_key,
        format: 'json',
        user: {
          subscriptions_attributes: [{
            id: subscription.id,
            line_items_attributes: [line_item_attributes]
          }]
        }
      }
    end

    let(:line_item_attributes) do
      {
        id: subscription.line_item_ids.first,
        quantity: 6,
        interval_length: 1,
        interval_units: 'month'
      }
    end

    it 'updates the subscription line items' do
      subject
      line_item = subscription.line_items.reload.first

      expect(line_item).to have_attributes(line_item_attributes)
    end
  end
end