summaryrefslogtreecommitdiff
path: root/spec/super_good/solidus_taxjar_spec.rb
blob: efc38b04d238cf59d94c8ced946496aad2d70fc5 (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
56
57
58
59
60
61
62
require 'spec_helper'

RSpec.describe SuperGood::SolidusTaxJar do
  it "has a version number" do
    expect(SuperGood::SolidusTaxJar::VERSION).not_to be nil
  end

  describe "configuration" do
    describe ".discount_calculator" do
      subject { described_class.discount_calculator }
      it { is_expected.to eq SuperGood::SolidusTaxJar::DiscountCalculator }
    end

    describe ".test_mode" do
      subject { described_class.test_mode }
      it { is_expected.to eq false }
    end

    describe ".exception_handler" do
      subject { described_class.exception_handler.(exception) }

      let(:exception) { StandardError.new("Something happened") }

      it "reports the exception using the Rails logger" do
        expect(Rails.logger).to receive(:error).with(
          "An error occurred while fetching TaxJar tax rates - Something happened: Something happened"
        )
        subject
      end
    end

    describe ".taxable_address_check" do
      subject { described_class.taxable_address_check.(address) }

      let(:address) { Spree::Address.new }

      it { is_expected.to eq true }
    end

    describe ".taxable_order_check" do
      subject { described_class.taxable_order_check.(order) }

      let(:order) { Spree::Order.new }

      it { is_expected.to eq true }
    end

    describe ".shipping_tax_label_maker" do
      subject { described_class.shipping_tax_label_maker.(shipment, shipping_tax) }
      let(:shipment) { Spree::Shipment.new }
      let(:shipping_tax) { BigDecimal("3.25") }
      it { is_expected.to eq "Sales Tax" }
    end

    describe ".line_item_tax_label_maker" do
      subject { described_class.line_item_tax_label_maker.(taxjar_line_item, spree_line_item) }
      let(:taxjar_line_item) { instance_double Taxjar::BreakdownLineItem }
      let(:spree_line_item) { Spree::LineItem.new }
      it { is_expected.to eq "Sales Tax" }
    end
  end
end