zoho_invoice 0.2.2 → 0.3.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.
- data/.gitignore +1 -0
- data/lib/zoho_invoice.rb +2 -0
- data/lib/zoho_invoice/base.rb +25 -37
- data/lib/zoho_invoice/error.rb +2 -3
- data/lib/zoho_invoice/error/client_error.rb +28 -0
- data/lib/zoho_invoice/invoice.rb +38 -0
- data/lib/zoho_invoice/version.rb +1 -1
- data/spec/fixtures/successful_empty_customer_response +3 -0
- data/spec/fixtures/successful_empty_response +3 -0
- data/spec/fixtures/successful_multiple_customer_response +12 -0
- data/spec/fixtures/successful_multiple_record_response +12 -0
- data/spec/fixtures/successful_single_customer_response +8 -0
- data/spec/fixtures/successful_single_record_response +8 -0
- data/spec/fixtures/successful_something_response +4 -0
- data/spec/fixtures/successful_unpaid_empty_customer_response +3 -0
- data/spec/fixtures/successful_unpaid_multiple_customer_response +12 -0
- data/spec/fixtures/successful_unpaid_single_customer_response +8 -0
- data/spec/spec_helper.rb +49 -0
- data/spec/zoho_invoice/base_spec.rb +31 -32
- data/spec/zoho_invoice/error/client_error_spec.rb +32 -0
- data/spec/zoho_invoice/invoice_spec.rb +57 -0
- metadata +27 -2
data/.gitignore
CHANGED
data/lib/zoho_invoice.rb
CHANGED
data/lib/zoho_invoice/base.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
module ZohoInvoice
|
2
|
-
class Error < Struct.new(:message, :code, :status, :http_status)
|
3
|
-
end
|
4
|
-
|
5
2
|
# Used for instances when some of the representations in zoho
|
6
3
|
# dont have their own end points in the API
|
7
4
|
#
|
@@ -33,19 +30,11 @@ module ZohoInvoice
|
|
33
30
|
def self.search(client, input_text, options = {})
|
34
31
|
result_hash = client.get("/api/view/search/#{self.to_s.split('::').last.downcase}s", :searchtext => input_text).body
|
35
32
|
objects_to_hydrate = result_hash['Response']["#{self.to_s.split('::').last}s"]["#{self.to_s.split('::').last}"]
|
36
|
-
|
37
|
-
return []
|
38
|
-
else
|
39
|
-
objects_to_hydrate.map do |result|
|
40
|
-
new_hash = {}
|
41
|
-
result.each do |key, value|
|
42
|
-
new_hash[key.to_underscore.to_sym] = value if !value.is_a?(Hash) && !value.is_a?(Array)
|
43
|
-
end
|
44
|
-
self.new(client, new_hash)
|
45
|
-
end
|
46
|
-
end
|
33
|
+
self.process_objects(client, objects_to_hydrate)
|
47
34
|
rescue Faraday::Error::ClientError => e
|
48
|
-
|
35
|
+
if e.response[:body]
|
36
|
+
raise ZohoInvoice::Error::ClientError.from_response(e.response)
|
37
|
+
end
|
49
38
|
end
|
50
39
|
|
51
40
|
def initialize(client, options = {})
|
@@ -84,14 +73,9 @@ module ZohoInvoice
|
|
84
73
|
self.class.instance_variable_get(:'@attributes') || []
|
85
74
|
end
|
86
75
|
|
87
|
-
def errors
|
88
|
-
@errors ||= []
|
89
|
-
end
|
90
|
-
|
91
76
|
# TODO Determining the resource to use will need to change
|
92
77
|
#
|
93
78
|
def save
|
94
|
-
@errors = []
|
95
79
|
|
96
80
|
action = 'create'
|
97
81
|
action = 'update' if !send("#{self.class.to_s.split('::').last.downcase}_id").nil?
|
@@ -105,9 +89,8 @@ module ZohoInvoice
|
|
105
89
|
self
|
106
90
|
rescue Faraday::Error::ClientError => e
|
107
91
|
if e.response[:body]
|
108
|
-
|
92
|
+
raise ZohoInvoice::Error::ClientError.from_response(e.response)
|
109
93
|
end
|
110
|
-
return self
|
111
94
|
end
|
112
95
|
|
113
96
|
# This needs to be a Nokogiri::XML::Builder
|
@@ -124,21 +107,7 @@ module ZohoInvoice
|
|
124
107
|
|
125
108
|
protected
|
126
109
|
|
127
|
-
|
128
|
-
self.class.process_error(request_result)
|
129
|
-
end
|
130
|
-
|
131
|
-
def self.process_error(request_result)
|
132
|
-
error = Error.new
|
133
|
-
response_body = request_result[:body]
|
134
|
-
error.status = response_body['Response']['status']
|
135
|
-
error.code = response_body['Response']['Code']
|
136
|
-
error.message = response_body['Response']['Message']
|
137
|
-
error.http_status = request_result[:status]
|
138
|
-
error
|
139
|
-
end
|
140
|
-
|
141
|
-
def self.camel_case(str)
|
110
|
+
def self.camel_case(str)
|
142
111
|
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
143
112
|
str.split('_').map{|e| e.capitalize}.join
|
144
113
|
end
|
@@ -167,5 +136,24 @@ module ZohoInvoice
|
|
167
136
|
end
|
168
137
|
end
|
169
138
|
|
139
|
+
private
|
140
|
+
|
141
|
+
def self.process_objects(client, objects_to_hydrate)
|
142
|
+
if objects_to_hydrate.nil?
|
143
|
+
return []
|
144
|
+
else
|
145
|
+
if objects_to_hydrate.is_a?(Hash) #Convert hash to array if only a single object is returned
|
146
|
+
objects_to_hydrate = [objects_to_hydrate]
|
147
|
+
end
|
148
|
+
objects_to_hydrate.map do |result|
|
149
|
+
new_hash = {}
|
150
|
+
result.each do |key, value|
|
151
|
+
new_hash[key.to_underscore.to_sym] = value if !value.is_a?(Hash) && !value.is_a?(Array)
|
152
|
+
end
|
153
|
+
self.new(client, new_hash)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
170
158
|
end
|
171
159
|
end
|
data/lib/zoho_invoice/error.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'zoho_invoice/error'
|
2
|
+
|
3
|
+
module ZohoInvoice
|
4
|
+
class Error
|
5
|
+
class ClientError < ZohoInvoice::Error
|
6
|
+
|
7
|
+
def self.from_response(response={})
|
8
|
+
self.parse_error(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.parse_error(response)
|
14
|
+
error = self.new
|
15
|
+
if !response[:body].nil?
|
16
|
+
response_body = response[:body]
|
17
|
+
error.response_status = response_body['Response']['status']
|
18
|
+
error.code = response_body['Response']['Code']
|
19
|
+
error.message = response_body['Response']['Message']
|
20
|
+
end
|
21
|
+
error.http_status = response[:status]
|
22
|
+
error
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/zoho_invoice/invoice.rb
CHANGED
@@ -21,5 +21,43 @@ module ZohoInvoice
|
|
21
21
|
|
22
22
|
has_many :invoice_items
|
23
23
|
|
24
|
+
def self.find_by_customer_id(client, id, options = {})
|
25
|
+
result_hash = client.get("/api/view/invoices/customer/#{id}").body
|
26
|
+
potential_objects = result_hash['Response']["Invoices"]
|
27
|
+
objects_to_hydrate = potential_objects["Invoice"] if potential_objects
|
28
|
+
self.process_objects(client, objects_to_hydrate)
|
29
|
+
rescue Faraday::Error::ClientError => e
|
30
|
+
if e.response[:body]
|
31
|
+
raise ZohoInvoice::Error::ClientError.from_response(e.response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find_by_multiple_customer_ids(client, ids, options={})
|
36
|
+
new_hash = {}
|
37
|
+
ids.each do |customer|
|
38
|
+
new_hash[customer] = self.find_by_customer_id(client, customer, options)
|
39
|
+
end
|
40
|
+
return new_hash
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.find_unpaid_by_customer_id(client, id, options = {})
|
44
|
+
result_hash = client.get("/api/view/invoices/unpaid/customer/#{id}").body
|
45
|
+
potential_objects = result_hash['Response']["Invoices"]
|
46
|
+
objects_to_hydrate = potential_objects["Invoice"] if potential_objects
|
47
|
+
self.process_objects(client, objects_to_hydrate)
|
48
|
+
rescue Faraday::Error::ClientError => e
|
49
|
+
if e.response[:body]
|
50
|
+
raise ZohoInvoice::Error::ClientError.from_response(e.response)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.find_unpaid_by_multiple_customer_ids(client, ids, options={})
|
55
|
+
new_hash = {}
|
56
|
+
ids.each do |customer|
|
57
|
+
new_hash[customer] = self.find_unpaid_by_customer_id(client, customer, options)
|
58
|
+
end
|
59
|
+
return new_hash
|
60
|
+
end
|
61
|
+
|
24
62
|
end
|
25
63
|
end
|
data/lib/zoho_invoice/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -22,6 +22,55 @@ RSpec.configure do |config|
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
def invoice_test(path, fixture_to_use, num_invoices, match_regex, method_to_test, *args)
|
26
|
+
stub_get(path).
|
27
|
+
with(:query => default_credentials).
|
28
|
+
to_return(:status => 200, :body => fixture(fixture_to_use), :headers => {:content_type => 'application/xml'})
|
29
|
+
result = ZohoInvoice::Invoice.send(method_to_test, args[0], args[1])
|
30
|
+
expect(a_get(path).with(:query => default_credentials)).to have_been_made
|
31
|
+
expect(result.class).to eq(Array)
|
32
|
+
expect(result.length).to eq(num_invoices)
|
33
|
+
if num_invoices > 0
|
34
|
+
result.each_with_index do |r, i|
|
35
|
+
expect(r.class).to eq(ZohoInvoice::Invoice)
|
36
|
+
expect(r.invoice_id).to eq((i+1).to_s)
|
37
|
+
expect(r.status).to match(match_regex)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def multiple_invoice_test(fixture_to_use, num_customers, method_to_test, method_to_stub, *args)
|
43
|
+
ZohoInvoice::Invoice.stub(method_to_stub).and_return([{'InvoiceID' => 1, 'CustomerName' => 'SampleName', 'Status' => 'Open', 'InvoiceDate' => 'January 1, 2013', 'Balance' => '$299.99'}])
|
44
|
+
|
45
|
+
result = ZohoInvoice::Invoice.send(method_to_test, args[0], args[1])
|
46
|
+
expect(result.class).to eq(Hash)
|
47
|
+
expect(result.length).to eq(num_customers)
|
48
|
+
if num_customers > 0
|
49
|
+
args[1].each do |id|
|
50
|
+
customer = result[id]
|
51
|
+
expect(customer.class).to eq(Array)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def error_test(path, fixture_to_use, method_to_test, message, code, response_status, http_status, *args)
|
57
|
+
stub_get(path).
|
58
|
+
with(:query => default_credentials).
|
59
|
+
to_return(:status => 500, :body => fixture(fixture_to_use), :headers => { :content_type => 'application/xml' })
|
60
|
+
expect { ZohoInvoice::Invoice.send(method_to_test, args[0], args[1]) }.to raise_error { |e|
|
61
|
+
error_expectations(e, message, code, response_status, http_status)
|
62
|
+
}
|
63
|
+
expect(a_get(path).with(query: default_credentials)).to have_been_made
|
64
|
+
end
|
65
|
+
|
66
|
+
def error_expectations(object, message, code, response_status, http_status)
|
67
|
+
expect(object.class).to eq(ZohoInvoice::Error::ClientError)
|
68
|
+
expect(object.message).to eq(message)
|
69
|
+
expect(object.code).to eq(code)
|
70
|
+
expect(object.response_status).to eq(response_status)
|
71
|
+
expect(object.http_status).to eq(http_status)
|
72
|
+
end
|
73
|
+
|
25
74
|
def stub_get(path)
|
26
75
|
stub_request(:get, ZohoInvoice::Defaults::URL + path)
|
27
76
|
end
|
@@ -109,7 +109,7 @@ describe ZohoInvoice::Base do
|
|
109
109
|
body_params = default_credentials.merge(:XMLString => @test_obj.to_xml)
|
110
110
|
stub_post('/api/somethings/create').
|
111
111
|
with(:body => body_params).
|
112
|
-
to_return(:status => 200, :body =>
|
112
|
+
to_return(:status => 200, :body => fixture('successful_something_response'), :headers => {:content_type => 'application/xml'})
|
113
113
|
@test_obj.save
|
114
114
|
expect(a_post('/api/somethings/create').with(:body => body_params)).to have_been_made
|
115
115
|
end
|
@@ -119,7 +119,7 @@ describe ZohoInvoice::Base do
|
|
119
119
|
body_params = default_credentials.merge(:XMLString => @test_obj.to_xml)
|
120
120
|
stub_post('/api/somethings/update').
|
121
121
|
with(:body => body_params).
|
122
|
-
to_return(:status => 200, :body =>
|
122
|
+
to_return(:status => 200, :body => fixture('successful_something_response'), :headers => {:content_type => 'application/xml'})
|
123
123
|
@test_obj.save
|
124
124
|
expect(a_post('/api/somethings/update').with(:body => body_params)).to have_been_made
|
125
125
|
end
|
@@ -129,7 +129,7 @@ describe ZohoInvoice::Base do
|
|
129
129
|
body_params = default_credentials.merge(:XMLString => @test_obj.to_xml)
|
130
130
|
stub_post('/api/somethings/create').
|
131
131
|
with(:body => body_params).
|
132
|
-
to_return(:status => 200, :body => successful_something_response
|
132
|
+
to_return(:status => 200, :body => fixture('successful_something_response'), :headers => { :content_type => 'application/xml' })
|
133
133
|
test_obj = Something.create(@client, :blah => '1234')
|
134
134
|
expect(a_post('/api/somethings/create').with(:body => body_params)).to have_been_made
|
135
135
|
expect(test_obj.something_id).to eq('1')
|
@@ -139,27 +139,24 @@ describe ZohoInvoice::Base do
|
|
139
139
|
@test_obj.blah = '1234'
|
140
140
|
body_params = default_credentials.merge(:XMLString => @test_obj.to_xml)
|
141
141
|
stub_post('/api/somethings/create').with(:body => body_params).to_return(:status => 500, :body => fixture('500_internal_server_error'), :headers => { :content_type => 'application/xml' })
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
error = test_obj.errors.first
|
146
|
-
expect(error.message).to eq("Invalid value passed for XMLString")
|
147
|
-
expect(error.code).to eq('2')
|
148
|
-
expect(error.status).to eq('0')
|
149
|
-
expect(error.http_status).to eq(500)
|
142
|
+
expect { Something.create(@client, :blah => '1234') }.to raise_error { |e|
|
143
|
+
error_expectations(e, 'Invalid value passed for XMLString', '2', '0', 500)
|
144
|
+
}
|
150
145
|
end
|
146
|
+
|
151
147
|
end
|
152
148
|
|
153
149
|
describe "searching" do
|
154
|
-
|
150
|
+
|
151
|
+
it "returns an array if it finds a single record" do
|
155
152
|
body_params = default_credentials.merge(:searchtext => '1234')
|
156
153
|
stub_get('/api/view/search/somethings').
|
157
154
|
with(:query => body_params).
|
158
|
-
to_return(:status => 200, :body =>
|
155
|
+
to_return(:status => 200, :body => fixture('successful_single_record_response'), :headers => {:content_type => 'application/xml'})
|
159
156
|
result = Something.search(@client, '1234')
|
160
157
|
expect(a_get('/api/view/search/somethings').with(query: body_params)).to have_been_made
|
161
158
|
expect(result.class).to eq(Array)
|
162
|
-
expect(result.length).to eq(
|
159
|
+
expect(result.length).to eq(1)
|
163
160
|
result.each_with_index do |r, i|
|
164
161
|
expect(r.class).to eq(Something)
|
165
162
|
expect(r.something_id).to eq((i+1).to_s)
|
@@ -167,41 +164,43 @@ describe ZohoInvoice::Base do
|
|
167
164
|
end
|
168
165
|
end
|
169
166
|
|
170
|
-
it "returns an
|
167
|
+
it "returns an array if it finds multiple records" do
|
171
168
|
body_params = default_credentials.merge(:searchtext => '1234')
|
172
169
|
stub_get('/api/view/search/somethings').
|
173
170
|
with(:query => body_params).
|
174
|
-
to_return(:status => 200, :body =>
|
171
|
+
to_return(:status => 200, :body => fixture('successful_multiple_record_response'), :headers => {:content_type => 'application/xml'})
|
175
172
|
result = Something.search(@client, '1234')
|
176
173
|
expect(a_get('/api/view/search/somethings').with(query: body_params)).to have_been_made
|
177
174
|
expect(result.class).to eq(Array)
|
178
|
-
expect(result.length).to eq(
|
175
|
+
expect(result.length).to eq(2)
|
176
|
+
result.each_with_index do |r, i|
|
177
|
+
expect(r.class).to eq(Something)
|
178
|
+
expect(r.something_id).to eq((i+1).to_s)
|
179
|
+
expect(r.blah).to eq('1234')
|
180
|
+
end
|
179
181
|
end
|
180
182
|
|
181
|
-
|
182
|
-
#
|
183
|
-
it "should return an empty array if theres an error" do
|
183
|
+
it "returns an empty array if it cant find anything" do
|
184
184
|
body_params = default_credentials.merge(:searchtext => '1234')
|
185
185
|
stub_get('/api/view/search/somethings').
|
186
186
|
with(:query => body_params).
|
187
|
-
to_return(:status =>
|
187
|
+
to_return(:status => 200, :body => fixture('successful_empty_response'), :headers => {:content_type => 'application/xml'})
|
188
188
|
result = Something.search(@client, '1234')
|
189
189
|
expect(a_get('/api/view/search/somethings').with(query: body_params)).to have_been_made
|
190
190
|
expect(result.class).to eq(Array)
|
191
191
|
expect(result.length).to eq(0)
|
192
192
|
end
|
193
|
-
end
|
194
|
-
|
195
|
-
def successful_something_response(blah_payload)
|
196
|
-
"<Something><SomethingID>1</SomethingID><Blah>#{blah_payload}</Blah></Something>"
|
197
|
-
end
|
198
|
-
|
199
|
-
def successful_multiple_record_response(payload)
|
200
|
-
"<Response><Somethings uri='/api/views/search/somethings'><Something><SomethingID>1</SomethingID><Blah>#{payload}</Blah></Something><Something><SomethingID>2</SomethingID><Blah>#{payload}</Blah></Something></Somethings></Response>"
|
201
|
-
end
|
202
193
|
|
203
|
-
|
204
|
-
|
194
|
+
it "should return an error if theres an error" do
|
195
|
+
body_params = default_credentials.merge(:searchtext => '1234')
|
196
|
+
stub_get('/api/view/search/somethings').
|
197
|
+
with(:query => body_params).
|
198
|
+
to_return(:status => 500, :body => fixture('500_internal_server_error'), :headers => {:content_type => 'application/xml'})
|
199
|
+
expect { Something.search(@client, '1234') }.to raise_error { |e|
|
200
|
+
error_expectations(e, 'Invalid value passed for XMLString', '2', '0', 500)
|
201
|
+
}
|
202
|
+
expect(a_get('/api/view/search/somethings').with(query: body_params)).to have_been_made
|
203
|
+
end
|
205
204
|
end
|
206
205
|
end
|
207
206
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZohoInvoice::Error::ClientError do
|
4
|
+
before do
|
5
|
+
@client = ZohoInvoice::Client.new(default_credentials)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should return a new error from a response" do
|
9
|
+
test_error = ZohoInvoice::Error::ClientError.from_response({:status=>500,
|
10
|
+
:headers=>{"content-type"=>"application/xml"},
|
11
|
+
:body=> {"Response"=>
|
12
|
+
{"Code"=>"2",
|
13
|
+
"Message"=>"Invalid value passed for XMLString",
|
14
|
+
"status"=>"0"}}})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to handle a reponse with no data" do
|
18
|
+
test_error = ZohoInvoice::Error::ClientError.from_response({:status=>500,
|
19
|
+
:headers=>{"content-type"=>"application/xml"},
|
20
|
+
:body=> {"Response"=>
|
21
|
+
{"Code"=>nil,
|
22
|
+
"Message"=>nil,
|
23
|
+
"status"=>nil}}})
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be able to handle a reponse with no body" do
|
27
|
+
test_error = ZohoInvoice::Error::ClientError.from_response({:status=>500,
|
28
|
+
:headers=>{"content-type"=>"application/xml"},
|
29
|
+
:body=> nil})
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ZohoInvoice::Invoice do
|
4
|
+
|
5
|
+
describe "searching by customer" do
|
6
|
+
before do
|
7
|
+
@client = ZohoInvoice::Client.new(default_credentials)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return an array if a customer has a single invoice" do
|
11
|
+
invoice_test('/api/view/invoices/customer/1234', 'successful_single_customer_response', 1, /Draft|Open|Closed|Overdue|Void/, :find_by_customer_id, @client, '1234')
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return an array if a customer has multiple invoices" do
|
15
|
+
invoice_test('/api/view/invoices/customer/1234', 'successful_multiple_customer_response', 2, /Draft|Open|Closed|Overdue|Void/, :find_by_customer_id, @client, '1234')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return an empty array if a customer doesn't have any invoices" do
|
19
|
+
invoice_test('/api/view/invoices/customer/1234', 'successful_empty_customer_response', 0, //, :find_by_customer_id, @client, '1234')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return an error if theres an error" do
|
23
|
+
error_test('/api/view/invoices/customer/1234', '500_internal_server_error', :find_by_customer_id, 'Invalid value passed for XMLString', '2', '0', 500, @client, '1234')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return a hash if multiple customers are searched for" do
|
27
|
+
multiple_invoice_test('invoice_array', 2, :find_by_multiple_customer_ids, :find_by_customer_id, @client, [1234, 5678])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "searching by customer (unpaid)" do
|
32
|
+
before do
|
33
|
+
@client = ZohoInvoice::Client.new(default_credentials)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return an array if a customer has a single unpaid invoice" do
|
37
|
+
invoice_test('/api/view/invoices/unpaid/customer/1234', 'successful_unpaid_single_customer_response', 1, /Open|Overdue/, :find_unpaid_by_customer_id, @client, '1234')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return an array if a customer has multiple unpaid invoices" do
|
41
|
+
invoice_test('/api/view/invoices/unpaid/customer/1234', 'successful_unpaid_multiple_customer_response', 2, /Open|Overdue/, :find_unpaid_by_customer_id, @client, '1234')
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return an empty array if a customer doesn't have any unpaid invoices" do
|
45
|
+
invoice_test('/api/view/invoices/unpaid/customer/1234', 'successful_unpaid_empty_customer_response', 0, //, :find_unpaid_by_customer_id, @client, '1234')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return an error if theres an error" do
|
49
|
+
error_test('/api/view/invoices/unpaid/customer/1234', '500_internal_server_error', :find_unpaid_by_customer_id, 'Invalid value passed for XMLString', '2', '0', 500, @client, '1234')
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return a hash if multiple customers are searched for" do
|
53
|
+
multiple_invoice_test('invoice_array', 2, :find_unpaid_by_multiple_customer_ids, :find_unpaid_by_customer_id, @client, [1234, 5678])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zoho_invoice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/zoho_invoice/customer.rb
|
118
118
|
- lib/zoho_invoice/defaults.rb
|
119
119
|
- lib/zoho_invoice/error.rb
|
120
|
+
- lib/zoho_invoice/error/client_error.rb
|
120
121
|
- lib/zoho_invoice/invoice.rb
|
121
122
|
- lib/zoho_invoice/invoice_item.rb
|
122
123
|
- lib/zoho_invoice/item.rb
|
@@ -129,12 +130,24 @@ files:
|
|
129
130
|
- spec/fixtures/invalid_user
|
130
131
|
- spec/fixtures/please_select_an_item
|
131
132
|
- spec/fixtures/successful_authtoken
|
133
|
+
- spec/fixtures/successful_empty_customer_response
|
134
|
+
- spec/fixtures/successful_empty_response
|
135
|
+
- spec/fixtures/successful_multiple_customer_response
|
136
|
+
- spec/fixtures/successful_multiple_record_response
|
137
|
+
- spec/fixtures/successful_single_customer_response
|
138
|
+
- spec/fixtures/successful_single_record_response
|
139
|
+
- spec/fixtures/successful_something_response
|
140
|
+
- spec/fixtures/successful_unpaid_empty_customer_response
|
141
|
+
- spec/fixtures/successful_unpaid_multiple_customer_response
|
142
|
+
- spec/fixtures/successful_unpaid_single_customer_response
|
132
143
|
- spec/spec_helper.rb
|
133
144
|
- spec/zoho_invoice/auth_token_spec.rb
|
134
145
|
- spec/zoho_invoice/base_spec.rb
|
135
146
|
- spec/zoho_invoice/client_spec.rb
|
136
147
|
- spec/zoho_invoice/collection_spec.rb
|
137
148
|
- spec/zoho_invoice/contact_spec.rb
|
149
|
+
- spec/zoho_invoice/error/client_error_spec.rb
|
150
|
+
- spec/zoho_invoice/invoice_spec.rb
|
138
151
|
- spec/zoho_invoice/string_spec.rb
|
139
152
|
- spec/zoho_invoice_spec.rb
|
140
153
|
- zoho_invoice.gemspec
|
@@ -171,11 +184,23 @@ test_files:
|
|
171
184
|
- spec/fixtures/invalid_user
|
172
185
|
- spec/fixtures/please_select_an_item
|
173
186
|
- spec/fixtures/successful_authtoken
|
187
|
+
- spec/fixtures/successful_empty_customer_response
|
188
|
+
- spec/fixtures/successful_empty_response
|
189
|
+
- spec/fixtures/successful_multiple_customer_response
|
190
|
+
- spec/fixtures/successful_multiple_record_response
|
191
|
+
- spec/fixtures/successful_single_customer_response
|
192
|
+
- spec/fixtures/successful_single_record_response
|
193
|
+
- spec/fixtures/successful_something_response
|
194
|
+
- spec/fixtures/successful_unpaid_empty_customer_response
|
195
|
+
- spec/fixtures/successful_unpaid_multiple_customer_response
|
196
|
+
- spec/fixtures/successful_unpaid_single_customer_response
|
174
197
|
- spec/spec_helper.rb
|
175
198
|
- spec/zoho_invoice/auth_token_spec.rb
|
176
199
|
- spec/zoho_invoice/base_spec.rb
|
177
200
|
- spec/zoho_invoice/client_spec.rb
|
178
201
|
- spec/zoho_invoice/collection_spec.rb
|
179
202
|
- spec/zoho_invoice/contact_spec.rb
|
203
|
+
- spec/zoho_invoice/error/client_error_spec.rb
|
204
|
+
- spec/zoho_invoice/invoice_spec.rb
|
180
205
|
- spec/zoho_invoice/string_spec.rb
|
181
206
|
- spec/zoho_invoice_spec.rb
|