suretax 0.2.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.example +4 -0
- data/.rubocop.yml +111 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +9 -9
- data/lib/suretax.rb +0 -1
- data/lib/suretax/api.rb +7 -7
- data/lib/suretax/api/cancel_request.rb +7 -7
- data/lib/suretax/api/group.rb +5 -6
- data/lib/suretax/api/item_message.rb +3 -3
- data/lib/suretax/api/request.rb +37 -37
- data/lib/suretax/api/request_item.rb +13 -17
- data/lib/suretax/api/response.rb +18 -19
- data/lib/suretax/api/tax.rb +11 -12
- data/lib/suretax/api/tax_amount.rb +3 -4
- data/lib/suretax/concerns.rb +1 -3
- data/lib/suretax/concerns/validatable.rb +21 -27
- data/lib/suretax/configuration.rb +17 -20
- data/lib/suretax/connection.rb +3 -5
- data/lib/suretax/constants/regulatory_codes.rb +8 -8
- data/lib/suretax/constants/response_groups.rb +6 -6
- data/lib/suretax/constants/sales_type_codes.rb +5 -5
- data/lib/suretax/constants/tax_situs_codes.rb +10 -10
- data/lib/suretax/constants/transaction_type_codes.rb +2 -2
- data/lib/suretax/response.rb +7 -10
- data/lib/suretax/version.rb +1 -1
- data/spec/lib/suretax/api/group_spec.rb +21 -22
- data/spec/lib/suretax/api/request_item_spec.rb +10 -12
- data/spec/lib/suretax/api/request_item_validations_spec.rb +73 -76
- data/spec/lib/suretax/api/request_spec.rb +62 -66
- data/spec/lib/suretax/api/request_validations_spec.rb +141 -143
- data/spec/lib/suretax/api/response_spec.rb +48 -52
- data/spec/lib/suretax/api/tax_amount_spec.rb +12 -12
- data/spec/lib/suretax/api/tax_spec.rb +26 -28
- data/spec/lib/suretax/configuration_spec.rb +21 -24
- data/spec/lib/suretax/connection_spec.rb +11 -15
- data/spec/lib/suretax/response_spec.rb +27 -31
- data/spec/spec_helper.rb +16 -17
- data/spec/support/cancellation_helper.rb +0 -1
- data/spec/support/connection_shared_examples.rb +8 -10
- data/spec/support/request_helper.rb +13 -14
- data/spec/support/suretax_helper.rb +2 -4
- data/spec/support/validations_shared_examples.rb +12 -12
- data/suretax.gemspec +10 -8
- metadata +7 -7
- data/.travis.yml +0 -13
@@ -1,13 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Suretax::Connection do
|
4
|
-
|
5
4
|
let(:connection) { Suretax::Connection.new }
|
6
5
|
|
7
|
-
context
|
8
|
-
|
9
|
-
|
10
|
-
it_should_behave_like 'API connection' do
|
6
|
+
context "using v01 of the API" do
|
7
|
+
describe "#post" do
|
8
|
+
it_should_behave_like "API connection" do
|
11
9
|
let(:api_path) { suretax_post_path }
|
12
10
|
let(:request_body) { valid_encoded_test_request_body }
|
13
11
|
let(:response) { connection.post(body: request_body) }
|
@@ -22,8 +20,8 @@ describe Suretax::Connection do
|
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
25
|
-
describe
|
26
|
-
it_should_behave_like
|
23
|
+
describe "#cancel" do
|
24
|
+
it_should_behave_like "API connection" do
|
27
25
|
let(:api_path) { suretax_cancel_path }
|
28
26
|
let(:request_body) { cancel_request_body }
|
29
27
|
let(:response) { connection.cancel(body: request_body) }
|
@@ -37,13 +35,11 @@ describe Suretax::Connection do
|
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
40
|
-
|
41
38
|
end
|
42
39
|
|
43
|
-
context
|
44
|
-
|
45
|
-
|
46
|
-
it_should_behave_like 'API connection' do
|
40
|
+
context "using v03 of the API" do
|
41
|
+
describe "#post" do
|
42
|
+
it_should_behave_like "API connection" do
|
47
43
|
let(:api_path) { suretax_post_path }
|
48
44
|
let(:request_body) { valid_encoded_test_request_body }
|
49
45
|
let(:response) { connection.post(body: request_body) }
|
@@ -58,8 +54,8 @@ describe Suretax::Connection do
|
|
58
54
|
end
|
59
55
|
end
|
60
56
|
|
61
|
-
describe
|
62
|
-
it_should_behave_like
|
57
|
+
describe "#cancel" do
|
58
|
+
it_should_behave_like "API connection" do
|
63
59
|
let(:api_path) { suretax_cancel_path }
|
64
60
|
let(:request_body) { cancel_request_body }
|
65
61
|
let(:response) { connection.cancel(body: request_body) }
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Suretax::Response do
|
4
4
|
let(:api_response_class) {
|
5
|
-
Struct.new(:status
|
5
|
+
Struct.new(:status, :body, :success) do
|
6
6
|
def success?
|
7
7
|
success
|
8
8
|
end
|
@@ -21,17 +21,16 @@ describe Suretax::Response do
|
|
21
21
|
|
22
22
|
let(:client_response) { Suretax::Response.new(api_response_object) }
|
23
23
|
|
24
|
-
context
|
25
|
-
|
24
|
+
context "when posting is successful" do
|
26
25
|
let(:response_body) do
|
27
26
|
suretax_wrap_response(valid_test_response_body.to_json)
|
28
27
|
end
|
29
28
|
|
30
|
-
it
|
29
|
+
it "has a body" do
|
31
30
|
expect(client_response.body).to be_instance_of(Hash)
|
32
31
|
end
|
33
32
|
|
34
|
-
it
|
33
|
+
it "has a status" do
|
35
34
|
expect(client_response.status).to eql(200)
|
36
35
|
end
|
37
36
|
|
@@ -39,18 +38,17 @@ describe Suretax::Response do
|
|
39
38
|
expect(client_response).to be_success
|
40
39
|
end
|
41
40
|
|
42
|
-
it
|
41
|
+
it "has a response object" do
|
43
42
|
client_response.response.should respond_to(:status, :body)
|
44
43
|
end
|
45
44
|
|
46
|
-
it
|
47
|
-
expect(client_response.body[
|
48
|
-
expect(client_response.body[
|
45
|
+
it "should return the correct response body" do
|
46
|
+
expect(client_response.body["ResponseCode"]).to eql("9999")
|
47
|
+
expect(client_response.body["TotalTax"]).to eql("1.394490")
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
52
|
-
|
53
|
-
context 'when posting is partially successful' do
|
51
|
+
context "when posting is partially successful" do
|
54
52
|
let(:response_body) do
|
55
53
|
suretax_wrap_response(success_with_item_errors.to_json)
|
56
54
|
end
|
@@ -59,11 +57,11 @@ describe Suretax::Response do
|
|
59
57
|
api_response_object.success = false
|
60
58
|
end
|
61
59
|
|
62
|
-
it
|
60
|
+
it "has a body" do
|
63
61
|
expect(client_response.body).to be_instance_of(Hash)
|
64
62
|
end
|
65
63
|
|
66
|
-
it
|
64
|
+
it "responds with a 409" do
|
67
65
|
expect(client_response.status).to eql(409)
|
68
66
|
end
|
69
67
|
|
@@ -71,18 +69,17 @@ describe Suretax::Response do
|
|
71
69
|
expect(client_response).to_not be_success
|
72
70
|
end
|
73
71
|
|
74
|
-
it
|
72
|
+
it "has a response object" do
|
75
73
|
client_response.response.should respond_to(:status, :body)
|
76
74
|
end
|
77
75
|
|
78
|
-
it
|
79
|
-
expect(client_response.body[
|
80
|
-
expect(client_response.body[
|
76
|
+
it "should return the correct response body" do
|
77
|
+
expect(client_response.body["ResponseCode"]).to eql("9001")
|
78
|
+
expect(client_response.body["TotalTax"]).to eql("26.53")
|
81
79
|
end
|
82
80
|
end
|
83
81
|
|
84
|
-
context
|
85
|
-
|
82
|
+
context "when posting fails" do
|
86
83
|
let(:response_body) do
|
87
84
|
suretax_wrap_response(post_failed_response_body.to_json)
|
88
85
|
end
|
@@ -91,11 +88,11 @@ describe Suretax::Response do
|
|
91
88
|
api_response_object.success = false
|
92
89
|
end
|
93
90
|
|
94
|
-
it
|
91
|
+
it "has a body" do
|
95
92
|
expect(client_response.body).to be_instance_of(Hash)
|
96
93
|
end
|
97
94
|
|
98
|
-
it
|
95
|
+
it "responds with a 400" do
|
99
96
|
expect(client_response.status).to eql(400)
|
100
97
|
end
|
101
98
|
|
@@ -103,29 +100,28 @@ describe Suretax::Response do
|
|
103
100
|
expect(client_response).to_not be_success
|
104
101
|
end
|
105
102
|
|
106
|
-
it
|
103
|
+
it "has a response object" do
|
107
104
|
client_response.response.should respond_to(:status, :body)
|
108
105
|
end
|
109
106
|
|
110
|
-
it
|
111
|
-
expect(client_response.body[
|
112
|
-
expect(client_response.body[
|
107
|
+
it "should return the correct response body" do
|
108
|
+
expect(client_response.body["ResponseCode"]).to eql("1101")
|
109
|
+
expect(client_response.body["TotalTax"]).to be_nil
|
113
110
|
end
|
114
111
|
end
|
115
112
|
|
116
|
-
context
|
117
|
-
|
113
|
+
context "when posting fails from a malformed request" do
|
118
114
|
let(:response_body) { suretax_wrap_response("invalid request") }
|
119
115
|
|
120
116
|
before do
|
121
117
|
api_response_object.success = true
|
122
118
|
end
|
123
119
|
|
124
|
-
it
|
125
|
-
expect(client_response.body).to eql(
|
120
|
+
it "has a body" do
|
121
|
+
expect(client_response.body).to eql("invalid request")
|
126
122
|
end
|
127
123
|
|
128
|
-
it
|
124
|
+
it "responds with a 409" do
|
129
125
|
expect(client_response.status).to eql(400)
|
130
126
|
end
|
131
127
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,39 +1,38 @@
|
|
1
|
-
require
|
1
|
+
require "dotenv" # First line of spec_helper
|
2
2
|
Dotenv.load # Second line of spec_helper
|
3
3
|
|
4
|
-
require
|
4
|
+
require "simplecov"
|
5
5
|
SimpleCov.start do
|
6
|
-
add_filter
|
7
|
-
add_filter
|
6
|
+
add_filter "/spec/"
|
7
|
+
add_filter "/.bundle/"
|
8
8
|
end
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
10
|
+
require "pry"
|
11
|
+
require "rspec"
|
12
|
+
require "rspec/its"
|
13
|
+
require "suretax"
|
14
|
+
require "awesome_print"
|
15
|
+
require "webmock/rspec"
|
16
16
|
|
17
17
|
# Load support files
|
18
|
-
Dir[File.expand_path(File.dirname(__FILE__) +
|
19
|
-
|
18
|
+
Dir[File.expand_path(File.dirname(__FILE__) + "/support/**/*.rb")].each do |support_file|
|
19
|
+
require support_file
|
20
20
|
end
|
21
21
|
|
22
22
|
RSpec.configure do |config|
|
23
|
-
|
24
23
|
config.before(:each) do
|
25
24
|
Suretax.configure do |c|
|
26
|
-
c.validation_key = ENV[
|
27
|
-
c.client_number = ENV[
|
25
|
+
c.validation_key = ENV["SURETAX_VALIDATION_KEY"]
|
26
|
+
c.client_number = ENV["SURETAX_CLIENT_NUMBER"]
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
30
|
config.expect_with :rspec do |c|
|
32
|
-
c.syntax = [
|
31
|
+
c.syntax = %i[should expect]
|
33
32
|
end
|
34
33
|
|
35
34
|
config.mock_with :rspec do |c|
|
36
|
-
c.syntax = [
|
35
|
+
c.syntax = %i[should expect]
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
shared_examples_for
|
4
|
-
context
|
3
|
+
shared_examples_for "API connection" do
|
4
|
+
context "with a valid request" do
|
5
5
|
before do
|
6
6
|
stub_request(:post, "#{suretax_url}#{api_path}").to_return(
|
7
7
|
status: 200,
|
@@ -9,17 +9,16 @@ shared_examples_for 'API connection' do
|
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it "should be successful" do
|
13
13
|
expect(response).to be_success
|
14
14
|
end
|
15
15
|
|
16
|
-
it
|
17
|
-
expect(connection.headers[
|
16
|
+
it "should have a urlencode header" do
|
17
|
+
expect(connection.headers["Content-Type"]).to include("application/x-www-form-urlencoded")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
context
|
22
|
-
|
21
|
+
context "with an invalid request" do
|
23
22
|
let(:request_body) { {} }
|
24
23
|
|
25
24
|
before do
|
@@ -29,9 +28,8 @@ shared_examples_for 'API connection' do
|
|
29
28
|
)
|
30
29
|
end
|
31
30
|
|
32
|
-
it
|
31
|
+
it "should not be successful" do
|
33
32
|
expect(response).to_not be_success
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
37
|
-
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module RequestSpecHelper
|
4
|
-
|
5
4
|
def valid_encoded_test_request_body
|
6
5
|
{
|
7
6
|
"ClientNumber" => suretax_client_number,
|
@@ -38,9 +37,9 @@ module RequestSpecHelper
|
|
38
37
|
"TransTypeCode" => "010101",
|
39
38
|
"SalesTypeCode" => "R",
|
40
39
|
"RegulatoryCode" => "99",
|
41
|
-
"TaxExemptionCodeList" => [
|
42
|
-
|
43
|
-
|
40
|
+
"TaxExemptionCodeList" => %w[
|
41
|
+
00
|
42
|
+
00
|
44
43
|
],
|
45
44
|
"UDF" => "",
|
46
45
|
"ShipFromZipCode" => "",
|
@@ -57,7 +56,7 @@ module RequestSpecHelper
|
|
57
56
|
"MailOrder" => "1",
|
58
57
|
"CommonCarrier" => "1",
|
59
58
|
"OriginCountryCode" => "",
|
60
|
-
"DestCountryCode" => ""
|
59
|
+
"DestCountryCode" => ""
|
61
60
|
}
|
62
61
|
]
|
63
62
|
}
|
@@ -71,7 +70,7 @@ module RequestSpecHelper
|
|
71
70
|
"ItemMessages" => [],
|
72
71
|
"ClientTracking" => "track",
|
73
72
|
"TotalTax" => "1.394490",
|
74
|
-
"TransId" =>
|
73
|
+
"TransId" => 2_664_495,
|
75
74
|
"GroupList" => [
|
76
75
|
{
|
77
76
|
"StateCode" => "CA",
|
@@ -132,10 +131,10 @@ module RequestSpecHelper
|
|
132
131
|
"ItemMessages" => [],
|
133
132
|
"ClientTracking" => "track",
|
134
133
|
"TotalTax" => "1.394490",
|
135
|
-
"TransId" =>
|
134
|
+
"TransId" => 2_872_159,
|
136
135
|
"GroupList" => [
|
137
136
|
{
|
138
|
-
|
137
|
+
"LineNumber" => "1",
|
139
138
|
"StateCode" => "CA",
|
140
139
|
"InvoiceNumber" => "1",
|
141
140
|
"CustomerNumber" => "000000007",
|
@@ -243,7 +242,8 @@ module RequestSpecHelper
|
|
243
242
|
"PercentTaxable" => 1.0,
|
244
243
|
"FeeRate" => 0.0,
|
245
244
|
"TaxOnTax" => 0.0
|
246
|
-
}
|
245
|
+
}
|
246
|
+
]
|
247
247
|
}
|
248
248
|
]
|
249
249
|
}
|
@@ -257,7 +257,7 @@ module RequestSpecHelper
|
|
257
257
|
"ItemMessages"=>[],
|
258
258
|
"ClientTracking"=>nil,
|
259
259
|
"TotalTax"=>nil,
|
260
|
-
"TransId"=>
|
260
|
+
"TransId"=>2_667_859,
|
261
261
|
"GroupList"=>[]
|
262
262
|
}
|
263
263
|
end
|
@@ -306,7 +306,7 @@ module RequestSpecHelper
|
|
306
306
|
|
307
307
|
def suretax_valid_request_params
|
308
308
|
{
|
309
|
-
|
309
|
+
business_unit: "testing",
|
310
310
|
client_number: suretax_client_number,
|
311
311
|
client_tracking: "track",
|
312
312
|
data_month: "7",
|
@@ -317,7 +317,7 @@ module RequestSpecHelper
|
|
317
317
|
return_file_code: "0",
|
318
318
|
total_revenue: "40",
|
319
319
|
validation_key: suretax_key,
|
320
|
-
items: [
|
320
|
+
items: [suretax_valid_request_item_params]
|
321
321
|
}
|
322
322
|
end
|
323
323
|
|
@@ -343,7 +343,7 @@ module RequestSpecHelper
|
|
343
343
|
unit_type: nil,
|
344
344
|
units: "1",
|
345
345
|
zipcode: "",
|
346
|
-
tax_exemption_codes: [
|
346
|
+
tax_exemption_codes: %w[00 00],
|
347
347
|
aux_revenue: nil,
|
348
348
|
aux_revenue_type: nil,
|
349
349
|
ship_from_pob: nil,
|
@@ -351,5 +351,4 @@ module RequestSpecHelper
|
|
351
351
|
common_carrier: nil
|
352
352
|
}
|
353
353
|
end
|
354
|
-
|
355
354
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module SuretaxSpecHelper
|
2
|
-
|
3
2
|
def suretax_key
|
4
|
-
ENV[
|
3
|
+
ENV["SURETAX_VALIDATION_KEY"]
|
5
4
|
end
|
6
5
|
|
7
6
|
def suretax_url
|
@@ -9,7 +8,7 @@ module SuretaxSpecHelper
|
|
9
8
|
end
|
10
9
|
|
11
10
|
def suretax_client_number
|
12
|
-
ENV[
|
11
|
+
ENV["SURETAX_CLIENT_NUMBER"]
|
13
12
|
end
|
14
13
|
|
15
14
|
def suretax_post_path
|
@@ -23,5 +22,4 @@ module SuretaxSpecHelper
|
|
23
22
|
def suretax_wrap_response(json_string)
|
24
23
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">" + json_string + "</string>"
|
25
24
|
end
|
26
|
-
|
27
25
|
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
|
-
shared_examples_for
|
4
|
-
it
|
5
|
-
request_item.send("#{subject}=",nil)
|
3
|
+
shared_examples_for "optional phone number" do
|
4
|
+
it "can be blank" do
|
5
|
+
request_item.send("#{subject}=", nil)
|
6
6
|
|
7
7
|
expect(request_item.errors.any?).to eq false
|
8
8
|
end
|
9
9
|
|
10
|
-
it
|
11
|
-
request_item.send("#{subject}=",
|
10
|
+
it "must be numeric" do
|
11
|
+
request_item.send("#{subject}=", "abcdefghij")
|
12
12
|
|
13
13
|
expect(request_item.errors.any?).to eq true
|
14
|
-
expect(request_item.errors.messages).to eq [%
|
14
|
+
expect(request_item.errors.messages).to eq [%(Invalid #{subject}: abcdefghij)]
|
15
15
|
end
|
16
16
|
|
17
|
-
it
|
18
|
-
request_item.send("#{subject}=",
|
17
|
+
it "must ten digits" do
|
18
|
+
request_item.send("#{subject}=", "1" * 11)
|
19
19
|
|
20
20
|
expect(request_item.errors.any?).to eq true
|
21
|
-
expect(request_item.errors.messages).to eq [%
|
21
|
+
expect(request_item.errors.messages).to eq [%(Invalid #{subject}: #{'1' * 11})]
|
22
22
|
|
23
|
-
request_item.send("#{subject}=",
|
23
|
+
request_item.send("#{subject}=", "1" * 9)
|
24
24
|
|
25
25
|
expect(request_item.errors.any?).to eq true
|
26
|
-
expect(request_item.errors.messages).to eq [%
|
26
|
+
expect(request_item.errors.messages).to eq [%(Invalid #{subject}: #{'1' * 9})]
|
27
27
|
end
|
28
28
|
end
|