summaryrefslogtreecommitdiff
path: root/spec/super_good/solidus_taxjar_spec.rb
blob: 30a2d014d7c0501b45d0c172da047ed89f2198fd (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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 ".cache_key" do
      subject { described_class.cache_key.call(order) }

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

      it "returns the API params converted to JSON" do
        allow(SuperGood::SolidusTaxJar::APIParams)
          .to receive(:order_params)
          .with(order)
          .and_return({some: "hash", with: "stuff", in: "it"})

        expect(subject).to eq '{"some":"hash","with":"stuff","in":"it"}'
      end
    end

    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.call(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.call(address) }

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

      it { is_expected.to eq true }
    end

    describe ".taxable_order_check" do
      subject { described_class.taxable_order_check.call(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.call(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.call(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