summaryrefslogtreecommitdiff
path: root/spec/services/solidus_subscriptions/line_item_builder_spec.rb
blob: 96ca02727b5db9a9eb69bf79f1295c860ca33240 (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
require 'spec_helper'

RSpec.describe SolidusSubscriptions::LineItemBuilder do
  let(:builder) { described_class.new subscription_line_items }
  let(:variant) { create(:variant, subscribable: true) }
  let(:subscription_line_item) { subscription_line_items.first }
  let(:subscription_line_items) do
    build_stubbed_list(:subscription_line_item, 1, subscribable_id: variant.id)
  end

  describe '#spree_line_items' do
    subject { builder.spree_line_items }

    let(:expected_attributes) do
      {
        variant_id: subscription_line_item.subscribable_id,
        quantity: subscription_line_item.quantity
      }
    end

    it { is_expected.to be_a Array }

    it 'contains a line item with the correct attributes' do
      expect(subject.first).to have_attributes expected_attributes
    end

    context 'the variant is not subscribable' do
      let!(:variant) { create(:variant) }

      it 'raises an unsubscribable error' do
        expect { subject }.to raise_error(
          SolidusSubscriptions::UnsubscribableError,
          /cannot be subscribed to/
        )
      end
    end

    context 'the variant is out of stock' do
      before { create :stock_location, backorderable_default: false }

      it { is_expected.to be_empty }
    end
  end
end