summaryrefslogtreecommitdiff
path: root/spec/super_good/solidus_taxjar/api_spec.rb
blob: 0f890cac8d7fb3ed32f56404e04f27c73fc40768 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require 'spec_helper'

RSpec.describe SuperGood::SolidusTaxJar::API do
  describe "#tax_for" do
    subject { api.tax_for order }

    let(:api) { described_class.new(taxjar_client: dummy_client) }
    let(:dummy_client) { instance_double ::Taxjar::Client }
    let(:order) { Spree::Order.new }

    before do
      allow(SuperGood::SolidusTaxJar::APIParams)
        .to receive(:order_params)
        .with(order)
        .and_return({ order: "params" })

      allow(dummy_client)
        .to receive(:tax_for_order)
        .with({ order: "params" })
        .and_return({ some_kind_of: "response" })
    end

    it { is_expected.to eq({ some_kind_of: "response" }) }
  end

  describe "#tax_rates_for" do
    subject { api.tax_rates_for address }

    let(:api) { described_class.new(taxjar_client: dummy_client) }
    let(:dummy_client) { instance_double ::Taxjar::Client }
    let(:address) { Spree::Address.new }

    before do
      allow(SuperGood::SolidusTaxJar::APIParams)
        .to receive(:address_params)
        .with(address)
        .and_return(["zipcode", { address: "params" }])

      allow(dummy_client)
        .to receive(:rates_for_location)
        .with("zipcode", { address: "params" })
        .and_return({ some_kind_of: "response" })
    end

    it { is_expected.to eq({ some_kind_of: "response" }) }
  end

  describe "#create_transaction_for" do
    subject { api.create_transaction_for order }

    let(:api) { described_class.new(taxjar_client: dummy_client) }
    let(:dummy_client) { instance_double ::Taxjar::Client }
    let(:order) { Spree::Order.new }

    before do
      allow(SuperGood::SolidusTaxJar::APIParams)
        .to receive(:transaction_params)
        .with(order)
        .and_return({ transaction: "params" })

      allow(dummy_client)
        .to receive(:create_order)
        .with({ transaction: "params" })
        .and_return({ some_kind_of: "response" })
    end

    it { is_expected.to eq({ some_kind_of: "response" }) }
  end

  describe "#update_transaction_for" do
    subject { api.update_transaction_for order }

    let(:api) { described_class.new(taxjar_client: dummy_client) }
    let(:dummy_client) { instance_double ::Taxjar::Client }
    let(:order) { Spree::Order.new }

    before do
      allow(SuperGood::SolidusTaxJar::APIParams)
        .to receive(:transaction_params)
        .with(order)
        .and_return({ transaction: "params" })

      allow(dummy_client)
        .to receive(:update_order)
        .with({ transaction: "params" })
        .and_return({ some_kind_of: "response" })
    end

    it { is_expected.to eq({ some_kind_of: "response" }) }
  end

  describe "#update_transaction_for" do
    subject { api.delete_transaction_for order }

    let(:api) { described_class.new(taxjar_client: dummy_client) }
    let(:dummy_client) { instance_double ::Taxjar::Client }
    let(:order) { Spree::Order.new(number: "R111222333") }

    before do
      allow(dummy_client)
        .to receive(:delete_order)
        .with("R111222333")
        .and_return({ some_kind_of: "response" })
    end

    it { is_expected.to eq({ some_kind_of: "response" }) }
  end

  describe "#create_refund_for" do
    subject { api.create_refund_for reimbursement }

    let(:api) { described_class.new(taxjar_client: dummy_client) }
    let(:dummy_client) { instance_double ::Taxjar::Client }
    let(:reimbursement) { Spree::Reimbursement.new }

    before do
      allow(SuperGood::SolidusTaxJar::APIParams)
        .to receive(:refund_params)
        .with(reimbursement)
        .and_return({ refund: "params" })

      allow(dummy_client)
        .to receive(:create_refund)
        .with({ refund: "params" })
        .and_return({ some_kind_of: "response" })
    end

    it { is_expected.to eq({ some_kind_of: "response" }) }
  end
end