summaryrefslogtreecommitdiff
path: root/spec/lib/solidus_subscriptions/subscription_promotion_rule_spec.rb
blob: f4c65cc18602c7eb99acd79421dad78daa9da2b9 (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'

RSpec.describe SolidusSubscriptions::SubscriptionPromotionRule do
  let(:rule) { described_class.new }

  describe '#applicable' do
    subject { rule.applicable? promotable }

    context 'when the promotable is a Spree::Order' do
      let(:promotable) { build_stubbed :order }

      it { is_expected.to be_truthy }
    end

    context 'when the promotable is not a Spree::Order' do
      let(:promotable) { build_stubbed :line_item }

      it { is_expected.to be_falsy }
    end
  end

  describe '#eligible?' do
    subject { rule.eligible? order }

    let(:order) { create(:order, line_items: line_items) }

    context 'when the order contains a line item with a subscription' do
      let(:line_items) { build_list(:line_item, 1, :with_subscription_line_items) }

      it { is_expected.to be_truthy }
    end

    context 'when the order does not contain a line item with a subscription' do
      let(:line_items) { build_list(:line_item, 1) }

      it { is_expected.to be_falsy }
    end
  end

  describe '#actionable?' do
    subject { rule.actionable? line_item }

    context 'when the line item has a subscription' do
      let(:line_item) { build_stubbed(:line_item, :with_subscription_line_items) }

      it { is_expected.to be_truthy }
    end

    context 'when the line item has no subscription' do
      let(:line_item) { build_stubbed :line_item }

      it { is_expected.to be_falsy }
    end
  end
end