summaryrefslogtreecommitdiff
path: root/spec/controllers/spree/api/orders_controller_spec.rb
blob: 1693b5dfcc01d38c1c070373d0b60ccf1b2f4ccf (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
49
50
51
52
53
54
55
require 'spec_helper'
require 'spree/api/testing_support/helpers'

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

  let(:order) { create :order }
  let(:variant) { create :variant }

  describe 'patch /update' do
    subject(:subscription_line_items) do
      patch :update, params: params
      order.subscription_line_items.reload
    end

    before { stub_authentication! }

    let(:params) do
      {
        order: { line_items_attributes: [line_items_params] },
        id: order.to_param,
        format: 'json',
        order_token: order.guest_token
      }
    end

    let(:line_items_params) do
      {
        variant_id: variant.id,
        quantity: 1,
        subscription_line_items_attributes: [subscription_line_items_params]
      }
    end

    let(:subscription_line_items_params) do
      {
        quantity: 1,
        subscribable_id: variant.id,
        interval_length: 30,
        interval_units: "day"
      }
    end

    it 'is a successful response' do
      subject
      expect(response).to be_successful
    end

    it 'create the correct number of subscription line items' do
      expect(subscription_line_items.length).
        to eq line_items_params[:subscription_line_items_attributes].length
    end
  end
end