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
131
132
133
134
135
|
require 'spec_helper'
RSpec.describe SuperGood::SolidusTaxJar::API do
describe "#order_tax_for" do
subject { api.order_tax_for order }
let(:api) do
described_class.new(taxjar_client: dummy_client)
end
let(:dummy_client) do
instance_double ::Taxjar::Client
end
let(:order) do
Spree::Order.create!(
item_total: 28.00,
shipment_total: 3.01,
store: store,
ship_address: ship_address,
line_items: [line_item]
)
end
let(:store) do
Spree::Store.create!(
name: "Default Store",
url: "https://store.example.com",
code: "store",
mail_from_address: "contact@example.com"
)
end
let(:ship_address) do
Spree::Address.create!(
country: country_us,
state: state_california,
zipcode: "90210",
city: "Los Angeles",
address1: "475 N Beverly Dr",
first_name: "Chuck",
last_name: "Schuldiner",
phone: "1-250-555-4444"
)
end
let(:country_us) do
Spree::Country.create!(
iso_name: "UNITED STATES",
iso: "US",
iso3: "USA",
name: "United States",
numcode: 840,
states_required: true
)
end
let(:state_california) do
Spree::State.create!(
country: country_us,
name: "California",
abbr: "CA"
)
end
let(:line_item) do
Spree::LineItem.new(
variant: variant,
price: 10,
quantity: 3,
adjustment_total: -2
)
end
let(:variant) do
Spree::Variant.create!(
product: product,
price: 10
)
end
let(:product) do
Spree::Product.create!(
name: "Product Name",
shipping_category: shipping_category,
tax_category: tax_category,
master: master_variant,
variants: [master_variant]
)
end
let(:shipping_category) do
Spree::ShippingCategory.create!(name: "Default Category")
end
let(:tax_category) do
Spree::TaxCategory.create!(
name: "Default",
is_default: true,
tax_code: "A_GEN_TAX"
)
end
let(:master_variant) do
Spree::Variant.new(
is_master: true,
price: 10
)
end
before do
allow(dummy_client).to receive(:tax_for_order).with(
to_country: "US",
to_zip: "90210",
to_city: "Los Angeles",
to_state: "CA",
to_street: "475 N Beverly Dr",
amount: 28.00,
shipping: 3.01,
line_items: [{
id: order.line_items.first.id,
quantity: 3,
unit_price: 10.00,
discount: 2.00,
product_tax_code: "A_GEN_TAX"
}]
).and_return({ some_kind_of: "response" })
end
it { is_expected.to eq({ some_kind_of: "response" }) }
end
end
|