suretax 0.2.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,109 +1,107 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Suretax::Api::Response do
|
4
|
-
|
5
4
|
let(:api_response) { Suretax::Api::Response.new(response_body) }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
context 'with a successful response' do
|
6
|
+
context "for a normal post request" do
|
7
|
+
context "with a successful response" do
|
10
8
|
let(:response_body) { valid_test_response_body }
|
11
9
|
|
12
|
-
it
|
13
|
-
expect(api_response.status).to eql(
|
10
|
+
it "should return the API status code" do
|
11
|
+
expect(api_response.status).to eql("9999")
|
14
12
|
end
|
15
13
|
|
16
|
-
it
|
14
|
+
it "should be successful" do
|
17
15
|
expect(api_response).to be_success
|
18
16
|
end
|
19
17
|
|
20
|
-
it
|
18
|
+
it "should not have item errors" do
|
21
19
|
expect(api_response).not_to be_item_errors
|
22
20
|
end
|
23
21
|
|
24
22
|
it 'should have a message of "Success"' do
|
25
|
-
expect(api_response.message).to eql(
|
23
|
+
expect(api_response.message).to eql("Success")
|
26
24
|
end
|
27
25
|
|
28
|
-
it
|
26
|
+
it "should have the correct total tax" do
|
29
27
|
expect(api_response.total_tax.to_f).to eql(1.394490)
|
30
28
|
end
|
31
29
|
|
32
|
-
it
|
33
|
-
expect(api_response.transaction).to eql(
|
30
|
+
it "should have a transaction id" do
|
31
|
+
expect(api_response.transaction).to eql("2664495")
|
34
32
|
end
|
35
33
|
|
36
|
-
context
|
37
|
-
it
|
34
|
+
context "invoice groups" do
|
35
|
+
it "should be the correct number" do
|
38
36
|
expect(api_response.groups.count).to eql(1)
|
39
37
|
end
|
40
38
|
|
41
|
-
it
|
39
|
+
it "should respond to #invoice" do
|
42
40
|
expect(api_response.groups.first).to respond_to(:invoice)
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
|
-
context
|
45
|
+
context "with a partially successful response" do
|
48
46
|
let(:response_body) { success_with_item_errors }
|
49
47
|
|
50
|
-
describe
|
51
|
-
it
|
52
|
-
expect(api_response.status).to eql(
|
48
|
+
describe "#status" do
|
49
|
+
it "should return the API status code" do
|
50
|
+
expect(api_response.status).to eql("9001")
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
56
|
-
describe
|
57
|
-
it
|
54
|
+
describe "#success?" do
|
55
|
+
it "should be true" do
|
58
56
|
expect(api_response).to be_success
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
60
|
describe "#item_errors?" do
|
63
|
-
it
|
61
|
+
it "should be true" do
|
64
62
|
expect(api_response).to be_item_errors
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
68
66
|
describe "#item_messages" do
|
69
|
-
it
|
67
|
+
it "should be the correct number" do
|
70
68
|
expect(api_response.item_messages.size).to eql(1)
|
71
69
|
end
|
72
70
|
|
73
|
-
it
|
71
|
+
it "should response to #message" do
|
74
72
|
expect(api_response.item_messages.first).to respond_to(:message)
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
|
-
describe
|
76
|
+
describe "#message" do
|
79
77
|
it 'should start with "Failure"' do
|
80
78
|
expect(api_response.message).to match(/\ASuccess with item errors/i)
|
81
79
|
end
|
82
80
|
end
|
83
81
|
end
|
84
82
|
|
85
|
-
context
|
83
|
+
context "with a failure response" do
|
86
84
|
let(:response_body) { post_failed_response_body }
|
87
85
|
|
88
|
-
describe
|
89
|
-
it
|
90
|
-
expect(api_response.status).to eql(
|
86
|
+
describe "#status" do
|
87
|
+
it "should return the API status code" do
|
88
|
+
expect(api_response.status).to eql("1101")
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
94
|
-
describe
|
95
|
-
it
|
92
|
+
describe "#success?" do
|
93
|
+
it "should be false" do
|
96
94
|
expect(api_response.success?).to eql false
|
97
95
|
end
|
98
96
|
end
|
99
97
|
|
100
98
|
describe "#item_errors?" do
|
101
|
-
it
|
99
|
+
it "should be false" do
|
102
100
|
expect(api_response).not_to be_item_errors
|
103
101
|
end
|
104
102
|
end
|
105
103
|
|
106
|
-
describe
|
104
|
+
describe "#message" do
|
107
105
|
it 'should start with "Failure"' do
|
108
106
|
expect(api_response.message).to match(/\AFailure/)
|
109
107
|
end
|
@@ -111,40 +109,39 @@ describe Suretax::Api::Response do
|
|
111
109
|
end
|
112
110
|
end
|
113
111
|
|
114
|
-
context
|
115
|
-
context
|
112
|
+
context "for a cancel post request" do
|
113
|
+
context "with a successful response" do
|
116
114
|
let(:response_body) { cancel_response_body }
|
117
115
|
|
118
|
-
it
|
119
|
-
expect(api_response.status).to eql(
|
116
|
+
it "should return the API status code" do
|
117
|
+
expect(api_response.status).to eql("9999")
|
120
118
|
end
|
121
119
|
|
122
|
-
it
|
120
|
+
it "should be successful" do
|
123
121
|
expect(api_response).to be_success
|
124
122
|
end
|
125
123
|
|
126
124
|
it 'should have a message of "Success"' do
|
127
|
-
expect(api_response.message).to eql(
|
125
|
+
expect(api_response.message).to eql("Success")
|
128
126
|
end
|
129
127
|
|
130
|
-
it
|
131
|
-
expect(api_response.transaction).to eql(
|
128
|
+
it "should have a transaction id" do
|
129
|
+
expect(api_response.transaction).to eql("0")
|
132
130
|
end
|
133
131
|
|
134
|
-
it
|
135
|
-
expect(api_response.client_tracking).to eql(
|
132
|
+
it "should have the client tracking code set" do
|
133
|
+
expect(api_response.client_tracking).to eql("test")
|
136
134
|
end
|
137
135
|
end
|
138
136
|
|
139
|
-
context
|
140
|
-
|
137
|
+
context "with a failed request" do
|
141
138
|
let(:response_body) { cancel_failed_response_body }
|
142
139
|
|
143
|
-
it
|
140
|
+
it "should return the API status code" do
|
144
141
|
expect(api_response.status).to be_nil
|
145
142
|
end
|
146
143
|
|
147
|
-
it
|
144
|
+
it "should be successful" do
|
148
145
|
expect(api_response).to_not be_success
|
149
146
|
end
|
150
147
|
|
@@ -152,14 +149,13 @@ describe Suretax::Api::Response do
|
|
152
149
|
expect(api_response.message).to be_nil
|
153
150
|
end
|
154
151
|
|
155
|
-
it
|
156
|
-
expect(api_response.transaction).to eql(
|
152
|
+
it "should have a transaction id" do
|
153
|
+
expect(api_response.transaction).to eql("0")
|
157
154
|
end
|
158
155
|
|
159
|
-
it
|
156
|
+
it "should have the client tracking code set" do
|
160
157
|
expect(api_response.client_tracking).to be_nil
|
161
158
|
end
|
162
159
|
end
|
163
160
|
end
|
164
|
-
|
165
161
|
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Suretax::Api::Amount do
|
4
|
-
let(:tax_amount) { Suretax::Api::Amount.new(
|
4
|
+
let(:tax_amount) { Suretax::Api::Amount.new("1.394490") }
|
5
5
|
|
6
6
|
let(:params) {
|
7
7
|
{
|
8
|
-
amount:
|
8
|
+
amount: 1_394_490,
|
9
9
|
precision: 6,
|
10
|
-
divisor:
|
10
|
+
divisor: 1_000_000
|
11
11
|
}
|
12
12
|
}
|
13
13
|
|
14
|
-
it
|
14
|
+
it "should return a Float for #to_f" do
|
15
15
|
expect(tax_amount.to_f).to eql(1.394490)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
expect(tax_amount.to_s).to eql(
|
18
|
+
it "should return a String for #to_s" do
|
19
|
+
expect(tax_amount.to_s).to eql("1.394490")
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
expect(tax_amount.to_i).to eql(
|
22
|
+
it "should provide an integer version via #to_i" do
|
23
|
+
expect(tax_amount.to_i).to eql(1_394_490)
|
24
24
|
end
|
25
25
|
|
26
|
-
it
|
26
|
+
it "should provide a hard currency value via #cents" do
|
27
27
|
expect(tax_amount.cents).to eql(139)
|
28
28
|
end
|
29
29
|
|
30
|
-
it
|
30
|
+
it "should give the number of decimal places via #precision" do
|
31
31
|
expect(tax_amount.precision).to eql(6)
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it "should give integer parameters for calculating the Float via #params" do
|
35
35
|
expect(tax_amount.params).to eql(params)
|
36
36
|
end
|
37
37
|
end
|
@@ -1,70 +1,68 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Suretax::Api::Tax do
|
4
|
-
|
5
4
|
let(:tax) { Suretax::Api::Tax.new(tax_params) }
|
6
5
|
|
7
|
-
context
|
8
|
-
let(:tax_params) { valid_test_response_body[
|
6
|
+
context "with an API v01 response" do
|
7
|
+
let(:tax_params) { valid_test_response_body["GroupList"].first["TaxList"].first }
|
9
8
|
|
10
|
-
it
|
11
|
-
expect(tax.code).to eql(
|
9
|
+
it "should have a code" do
|
10
|
+
expect(tax.code).to eql("106")
|
12
11
|
end
|
13
12
|
|
14
|
-
it
|
15
|
-
expect(tax.description).to eql(
|
13
|
+
it "should have a description" do
|
14
|
+
expect(tax.description).to eql("CA EMERG TEL. USERS SURCHARGE")
|
16
15
|
end
|
17
16
|
|
18
|
-
it
|
17
|
+
it "should have an amount" do
|
19
18
|
expect(tax.amount.to_f).to eql(0.200760)
|
20
19
|
end
|
21
|
-
|
22
20
|
end
|
23
21
|
|
24
|
-
context
|
25
|
-
let(:tax_params) { valid_v03_response_body[
|
22
|
+
context "with an API v03 response" do
|
23
|
+
let(:tax_params) { valid_v03_response_body["GroupList"].first["TaxList"].first }
|
26
24
|
|
27
|
-
it
|
28
|
-
expect(tax.code).to eql(
|
25
|
+
it "should have a code" do
|
26
|
+
expect(tax.code).to eql("106")
|
29
27
|
end
|
30
28
|
|
31
|
-
it
|
32
|
-
expect(tax.description).to eql(
|
29
|
+
it "should have a description" do
|
30
|
+
expect(tax.description).to eql("CA EMERG TEL. USERS SURCHARGE")
|
33
31
|
end
|
34
32
|
|
35
|
-
it
|
33
|
+
it "should have an amount" do
|
36
34
|
expect(tax.amount.to_f).to eql(0.200760)
|
37
35
|
end
|
38
36
|
|
39
|
-
it
|
40
|
-
expect(tax.revenue).to eql(
|
37
|
+
it "should have a revenue code" do
|
38
|
+
expect(tax.revenue).to eql("40")
|
41
39
|
end
|
42
40
|
|
43
|
-
it
|
44
|
-
expect(tax.county).to eql(
|
41
|
+
it "should have a county name" do
|
42
|
+
expect(tax.county).to eql("SAN DIEGO")
|
45
43
|
end
|
46
44
|
|
47
|
-
it
|
48
|
-
expect(tax.city).to eql(
|
45
|
+
it "should have a city name" do
|
46
|
+
expect(tax.city).to eql("SAN DIEGO")
|
49
47
|
end
|
50
48
|
|
51
|
-
it
|
49
|
+
it "should have a tax rate" do
|
52
50
|
expect(tax.rate.to_f).to eql(0.005)
|
53
51
|
end
|
54
52
|
|
55
|
-
it
|
53
|
+
it "should have a percent taxable" do
|
56
54
|
expect(tax.taxable.to_f).to eql(1.0)
|
57
55
|
end
|
58
56
|
|
59
|
-
it
|
57
|
+
it "should have a fee rate" do
|
60
58
|
expect(tax.fee_rate.to_f).to eql 0.0
|
61
59
|
end
|
62
60
|
|
63
|
-
it
|
61
|
+
it "should have a tax on tax" do
|
64
62
|
expect(tax.tax_on_tax.to_f).to eql 0.5
|
65
63
|
end
|
66
64
|
|
67
|
-
it
|
65
|
+
it "should have a revenue base" do
|
68
66
|
expect(tax.revenue_base.to_f).to eql 40.0
|
69
67
|
end
|
70
68
|
end
|
@@ -1,17 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Suretax do
|
4
|
-
|
5
4
|
let(:config) { Suretax.configuration }
|
6
|
-
let(:url) {
|
7
|
-
let(:test_host) {
|
5
|
+
let(:url) { "http://test.dev" }
|
6
|
+
let(:test_host) { "https://testapi.taxrating.net" }
|
8
7
|
|
9
8
|
describe ".configure" do
|
10
|
-
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:cancel_path) { '/Services/V01/SureTax.asmx/CancelPostRequest' }
|
9
|
+
let(:key) { "xxxxxxxx" }
|
10
|
+
let(:client) { "9999999999" }
|
11
|
+
let(:post_path) { "/Services/V04/SureTax.asmx/PostRequest" }
|
12
|
+
let(:cancel_path) { "/Services/V01/SureTax.asmx/CancelPostRequest" }
|
15
13
|
|
16
14
|
before do
|
17
15
|
Suretax.configure do |c|
|
@@ -21,27 +19,27 @@ describe Suretax do
|
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
|
-
it
|
22
|
+
it "should allow me to set the validation key" do
|
25
23
|
expect(config.validation_key).to eql key
|
26
24
|
end
|
27
25
|
|
28
|
-
it
|
26
|
+
it "should allow me to set the API server base url" do
|
29
27
|
expect(config.base_url).to eql test_host
|
30
28
|
end
|
31
29
|
|
32
|
-
it
|
30
|
+
it "should allow me to set the client number" do
|
33
31
|
expect(config.client_number).to eql client
|
34
32
|
end
|
35
33
|
|
36
|
-
it
|
34
|
+
it "should allow me to set the default post path" do
|
37
35
|
expect(config.request_path).to eql post_path
|
38
36
|
end
|
39
37
|
|
40
|
-
it
|
38
|
+
it "should allow me to set the default cancel path" do
|
41
39
|
expect(config.cancel_path).to eql cancel_path
|
42
40
|
end
|
43
41
|
|
44
|
-
it
|
42
|
+
it "should default test mode" do
|
45
43
|
expect(config.test?).to eql true
|
46
44
|
end
|
47
45
|
|
@@ -49,7 +47,7 @@ describe Suretax do
|
|
49
47
|
expect(config.request_version).to eql 4
|
50
48
|
end
|
51
49
|
|
52
|
-
context
|
50
|
+
context "when setting the mode" do
|
53
51
|
around(:each) do |test|
|
54
52
|
original_url = Suretax.configuration.base_url
|
55
53
|
Suretax.configuration.base_url = url
|
@@ -57,16 +55,16 @@ describe Suretax do
|
|
57
55
|
Suretax.configuration.base_url = original_url
|
58
56
|
end
|
59
57
|
|
60
|
-
it
|
58
|
+
it "should allow me to select non-test mode" do
|
61
59
|
expect(config.test?).to eql false
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
65
63
|
|
66
|
-
describe
|
64
|
+
describe "production?" do
|
67
65
|
subject { Suretax.configuration.test? }
|
68
66
|
|
69
|
-
context
|
67
|
+
context "when using the test host" do
|
70
68
|
around(:each) do |test|
|
71
69
|
original_url = Suretax.configuration.base_url
|
72
70
|
Suretax.configuration.base_url = test_host
|
@@ -76,7 +74,7 @@ describe Suretax do
|
|
76
74
|
it { should eql true }
|
77
75
|
end
|
78
76
|
|
79
|
-
context
|
77
|
+
context "when using another host" do
|
80
78
|
around(:each) do |test|
|
81
79
|
original_url = Suretax.configuration.base_url
|
82
80
|
Suretax.configuration.base_url = url
|
@@ -87,16 +85,15 @@ describe Suretax do
|
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
90
|
-
describe
|
91
|
-
it
|
88
|
+
describe "loading from the app environment" do
|
89
|
+
it "should allow me to set the validation key" do
|
92
90
|
expect(suretax_key).to_not match(/\A\s*\z/)
|
93
91
|
expect(config.validation_key).to include(suretax_key)
|
94
92
|
end
|
95
93
|
|
96
|
-
it
|
94
|
+
it "should allow me to set the API server base url" do
|
97
95
|
expect(suretax_url).to_not match(/\A\s*\z/)
|
98
96
|
expect(config.base_url).to include(suretax_url)
|
99
97
|
end
|
100
98
|
end
|
101
|
-
|
102
99
|
end
|