xeroizer 2.17.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +246 -213
- data/lib/xeroizer/connection.rb +49 -0
- data/lib/xeroizer/exceptions.rb +4 -0
- data/lib/xeroizer/generic_application.rb +13 -5
- data/lib/xeroizer/http.rb +7 -80
- data/lib/xeroizer/http_response.rb +154 -0
- data/lib/xeroizer/models/bank_account.rb +1 -0
- data/lib/xeroizer/models/bank_transaction.rb +1 -0
- data/lib/xeroizer/models/batch_payment.rb +27 -0
- data/lib/xeroizer/models/branding_theme.rb +49 -9
- data/lib/xeroizer/models/contact.rb +12 -6
- data/lib/xeroizer/models/contact_group.rb +45 -0
- data/lib/xeroizer/models/credit_note.rb +24 -22
- data/lib/xeroizer/models/currency.rb +14 -2
- data/lib/xeroizer/models/from_bank_account.rb +1 -0
- data/lib/xeroizer/models/history_record.rb +72 -0
- data/lib/xeroizer/models/invoice.rb +17 -3
- data/lib/xeroizer/models/item.rb +2 -1
- data/lib/xeroizer/models/item_purchase_details.rb +1 -1
- data/lib/xeroizer/models/line_item.rb +17 -5
- data/lib/xeroizer/models/manual_journal.rb +2 -1
- data/lib/xeroizer/models/online_invoice.rb +37 -0
- data/lib/xeroizer/models/option.rb +1 -1
- data/lib/xeroizer/models/organisation.rb +2 -0
- data/lib/xeroizer/models/payment_service.rb +22 -0
- data/lib/xeroizer/models/payroll/address.rb +53 -0
- data/lib/xeroizer/models/payroll/bank_account.rb +18 -6
- data/lib/xeroizer/models/payroll/benefit_line.rb +26 -0
- data/lib/xeroizer/models/payroll/benefit_type.rb +45 -0
- data/lib/xeroizer/models/payroll/deduction_line.rb +32 -0
- data/lib/xeroizer/models/payroll/deduction_type.rb +49 -0
- data/lib/xeroizer/models/payroll/earnings_line.rb +39 -0
- data/lib/xeroizer/models/payroll/earnings_type.rb +53 -0
- data/lib/xeroizer/models/payroll/employee.rb +30 -8
- data/lib/xeroizer/models/payroll/leave_application.rb +27 -0
- data/lib/xeroizer/models/payroll/leave_line.rb +30 -0
- data/lib/xeroizer/models/payroll/leave_period.rb +15 -0
- data/lib/xeroizer/models/payroll/pay_items.rb +22 -0
- data/lib/xeroizer/models/payroll/pay_run.rb +33 -0
- data/lib/xeroizer/models/payroll/pay_schedule.rb +40 -0
- data/lib/xeroizer/models/payroll/pay_template.rb +24 -0
- data/lib/xeroizer/models/payroll/payment_method.rb +24 -0
- data/lib/xeroizer/models/payroll/paystub.rb +44 -0
- data/lib/xeroizer/models/payroll/reimbursement_line.rb +21 -0
- data/lib/xeroizer/models/payroll/reimbursement_type.rb +22 -0
- data/lib/xeroizer/models/payroll/salary_and_wage.rb +29 -0
- data/lib/xeroizer/models/payroll/super_line.rb +40 -0
- data/lib/xeroizer/models/payroll/tax_declaration.rb +50 -0
- data/lib/xeroizer/models/payroll/time_off_line.rb +20 -0
- data/lib/xeroizer/models/payroll/time_off_type.rb +32 -0
- data/lib/xeroizer/models/payroll/work_location.rb +25 -0
- data/lib/xeroizer/models/prepayment.rb +1 -0
- data/lib/xeroizer/models/purchase_order.rb +6 -6
- data/lib/xeroizer/models/quote.rb +76 -0
- data/lib/xeroizer/models/schedule.rb +1 -0
- data/lib/xeroizer/models/tax_component.rb +1 -0
- data/lib/xeroizer/models/to_bank_account.rb +1 -0
- data/lib/xeroizer/oauth.rb +12 -1
- data/lib/xeroizer/oauth2.rb +82 -0
- data/lib/xeroizer/oauth2_application.rb +49 -0
- data/lib/xeroizer/payroll_application.rb +8 -3
- data/lib/xeroizer/record/base.rb +11 -2
- data/lib/xeroizer/record/base_model.rb +1 -1
- data/lib/xeroizer/record/base_model_http_proxy.rb +37 -17
- data/lib/xeroizer/record/model_definition_helper.rb +1 -1
- data/lib/xeroizer/record/payroll_base.rb +4 -0
- data/lib/xeroizer/record/record_association_helper.rb +4 -4
- data/lib/xeroizer/record/validators/associated_validator.rb +1 -0
- data/lib/xeroizer/record/xml_helper.rb +18 -18
- data/lib/xeroizer/report/aged_receivables_by_contact.rb +1 -1
- data/lib/xeroizer/report/cell_xml_helper.rb +13 -13
- data/lib/xeroizer/response.rb +22 -17
- data/lib/xeroizer/version.rb +1 -1
- data/lib/xeroizer.rb +34 -4
- data/test/acceptance/about_creating_bank_transactions_test.rb +89 -81
- data/test/acceptance/about_creating_prepayment_test.rb +25 -30
- data/test/acceptance/about_fetching_bank_transactions_test.rb +12 -12
- data/test/acceptance/about_online_invoice_test.rb +25 -0
- data/test/acceptance/acceptance_test.rb +28 -26
- data/test/acceptance/bank_transfer_test.rb +12 -17
- data/test/acceptance/bulk_operations_test.rb +18 -16
- data/test/acceptance/connections_test.rb +11 -0
- data/test/stub_responses/bad_request.json +6 -0
- data/test/stub_responses/connections.json +16 -0
- data/test/stub_responses/expired_oauth2_token.json +6 -0
- data/test/stub_responses/generic_response_error.json +6 -0
- data/test/stub_responses/invalid_oauth2_request_token.json +6 -0
- data/test/stub_responses/invalid_tenant_header.json +6 -0
- data/test/stub_responses/object_not_found.json +6 -0
- data/test/stub_responses/organisations.xml +10 -0
- data/test/stub_responses/payment_service.xml +15 -0
- data/test/test_helper.rb +17 -12
- data/test/unit/generic_application_test.rb +21 -10
- data/test/unit/http_test.rb +282 -10
- data/test/unit/models/address_test.rb +2 -2
- data/test/unit/models/bank_transaction_model_parsing_test.rb +2 -2
- data/test/unit/models/bank_transaction_test.rb +1 -1
- data/test/unit/models/bank_transaction_validation_test.rb +1 -1
- data/test/unit/models/contact_test.rb +20 -11
- data/test/unit/models/credit_note_test.rb +8 -8
- data/test/unit/models/employee_test.rb +4 -4
- data/test/unit/models/invoice_test.rb +12 -12
- data/test/unit/models/journal_line_test.rb +6 -6
- data/test/unit/models/journal_test.rb +4 -4
- data/test/unit/models/line_item_sum_test.rb +1 -1
- data/test/unit/models/line_item_test.rb +29 -37
- data/test/unit/models/manual_journal_test.rb +3 -3
- data/test/unit/models/organisation_test.rb +16 -2
- data/test/unit/models/payment_service_test.rb +29 -0
- data/test/unit/models/phone_test.rb +7 -7
- data/test/unit/models/prepayment_test.rb +4 -4
- data/test/unit/models/repeating_invoice_test.rb +3 -3
- data/test/unit/models/tax_rate_test.rb +2 -2
- data/test/unit/oauth2_test.rb +171 -0
- data/test/unit/oauth_config_test.rb +1 -1
- data/test/unit/record/base_model_test.rb +13 -13
- data/test/unit/record/base_test.rb +73 -4
- data/test/unit/record/block_validator_test.rb +1 -1
- data/test/unit/record/connection_test.rb +60 -0
- data/test/unit/record/model_definition_test.rb +36 -36
- data/test/unit/record/parse_params_test.rb +59 -0
- data/test/unit/record/parse_where_hash_test.rb +13 -13
- data/test/unit/record/record_association_test.rb +14 -14
- data/test/unit/record/validators_test.rb +43 -43
- data/test/unit/record_definition_test.rb +7 -7
- data/test/unit/report_definition_test.rb +7 -7
- data/test/unit/report_test.rb +20 -20
- data/test/unit_test_helper.rb +16 -0
- metadata +117 -27
- data/lib/xeroizer/models/payroll/home_address.rb +0 -24
- data/lib/xeroizer/partner_application.rb +0 -51
- data/lib/xeroizer/private_application.rb +0 -25
- data/lib/xeroizer/public_application.rb +0 -21
- data/test/unit/oauth_test.rb +0 -118
- data/test/unit/private_application_test.rb +0 -20
data/test/unit/http_test.rb
CHANGED
@@ -1,18 +1,290 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
|
-
class HttpTest <
|
3
|
+
class HttpTest < UnitTestCase
|
4
4
|
include TestHelper
|
5
5
|
|
6
|
-
|
7
|
-
@
|
8
|
-
@application = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :default_headers => @headers)
|
6
|
+
setup do
|
7
|
+
@uri = "https://api.xero.com/path"
|
9
8
|
end
|
10
9
|
|
11
|
-
context "
|
12
|
-
|
13
|
-
Xeroizer::
|
14
|
-
|
10
|
+
context "errors" do
|
11
|
+
setup do
|
12
|
+
@application = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET, tenant_id: TENANT_ID, access_token: ACCESS_TOKEN)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "400" do
|
16
|
+
setup do
|
17
|
+
status_code = 400
|
18
|
+
@body = get_file_as_string("credit_note_not_found_error.xml")
|
19
|
+
stub_request(:get, @uri).to_return(status: status_code, body: @body)
|
20
|
+
end
|
21
|
+
|
22
|
+
should "raise an ApiException" do
|
23
|
+
error = assert_raises(Xeroizer::ApiException) { @application.http_get(@application.client, @uri) }
|
24
|
+
assert_equal ": \n Generated by the following XML: \n #{@body}", error.message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "401" do
|
29
|
+
setup do
|
30
|
+
@status_code = 401
|
31
|
+
end
|
32
|
+
|
33
|
+
context "token_expired" do
|
34
|
+
setup do
|
35
|
+
body = get_file_as_string("token_expired")
|
36
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
37
|
+
end
|
38
|
+
|
39
|
+
should "raise an OAuth::TokenExpired" do
|
40
|
+
error = assert_raises(Xeroizer::OAuth::TokenExpired) { @application.http_get(@application.client, @uri) }
|
41
|
+
assert_equal "Unexpected token", error.message
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "token_rejected" do
|
46
|
+
setup do
|
47
|
+
body = "oauth_problem_advice=some advice&oauth_problem=token_rejected"
|
48
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
49
|
+
end
|
50
|
+
|
51
|
+
should "raise an OAuth::TokenInvalid" do
|
52
|
+
error = assert_raises(Xeroizer::OAuth::TokenInvalid) { @application.http_get(@application.client, @uri) }
|
53
|
+
assert_equal "some advice", error.message
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "rate limit exceeded" do
|
58
|
+
setup do
|
59
|
+
body = get_file_as_string("rate_limit_exceeded")
|
60
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "raise an OAuth::RateLimitExceeded" do
|
64
|
+
error = assert_raises(Xeroizer::OAuth::RateLimitExceeded) { @application.http_get(@application.client, @uri) }
|
65
|
+
assert_equal "please wait before retrying the xero api\n", error.message
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "consumer_key_unknown" do
|
70
|
+
setup do
|
71
|
+
body = "oauth_problem_advice=some more advice&oauth_problem=consumer_key_unknown"
|
72
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
73
|
+
end
|
74
|
+
|
75
|
+
should "raise an OAuth::ConsumerKeyUnknown" do
|
76
|
+
error = assert_raises(Xeroizer::OAuth::ConsumerKeyUnknown) { @application.http_get(@application.client, @uri) }
|
77
|
+
assert_equal "some more advice", error.message
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "nonce_used" do
|
82
|
+
setup do
|
83
|
+
body = get_file_as_string("nonce_used")
|
84
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
85
|
+
end
|
86
|
+
|
87
|
+
should "raise an OAuth::NonceUsed" do
|
88
|
+
error = assert_raises(Xeroizer::OAuth::NonceUsed) { @application.http_get(@application.client, @uri) }
|
89
|
+
assert_equal "The nonce value \"potatocakes\" has already been used ", error.message
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "organisation offline" do
|
94
|
+
setup do
|
95
|
+
body = "oauth_problem_advice=organisational advice&oauth_problem=organisation offline"
|
96
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
97
|
+
end
|
98
|
+
|
99
|
+
should "raise an OAuth::OrganisationOffline" do
|
100
|
+
error = assert_raises(Xeroizer::OAuth::OrganisationOffline) { @application.http_get(@application.client, @uri) }
|
101
|
+
assert_equal "organisational advice", error.message
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "unknown error" do
|
106
|
+
setup do
|
107
|
+
body = "oauth_problem_advice=unknown advice&oauth_problem=unknown error"
|
108
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
109
|
+
end
|
110
|
+
|
111
|
+
should "raise an OAuth::UnknownError" do
|
112
|
+
error = assert_raises(Xeroizer::OAuth::UnknownError) { @application.http_get(@application.client, @uri) }
|
113
|
+
assert_equal "unknown error:unknown advice", error.message
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "404" do
|
119
|
+
setup do
|
120
|
+
@status_code = 404
|
121
|
+
end
|
122
|
+
|
123
|
+
context "invoices" do
|
124
|
+
setup do
|
125
|
+
@uri = "https://api.xero.com/Invoices"
|
126
|
+
body = get_file_as_string("invoice_not_found_error.xml")
|
127
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
128
|
+
end
|
129
|
+
|
130
|
+
should "raise an InvoiceNotFoundError" do
|
131
|
+
error = assert_raises(Xeroizer::InvoiceNotFoundError) { @application.http_get(@application.client, @uri) }
|
132
|
+
assert_equal "Invoice not found in Xero.", error.message
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "credit notes" do
|
137
|
+
setup do
|
138
|
+
@uri = "https://api.xero.com/CreditNotes"
|
139
|
+
body = get_file_as_string("credit_note_not_found_error.xml")
|
140
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
141
|
+
end
|
142
|
+
|
143
|
+
should "raise an CreditNoteNotFoundError" do
|
144
|
+
error = assert_raises(Xeroizer::CreditNoteNotFoundError) { @application.http_get(@application.client, @uri) }
|
145
|
+
assert_equal "Credit Note not found in Xero.", error.message
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "anything else" do
|
150
|
+
setup do
|
151
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: "body")
|
152
|
+
end
|
153
|
+
|
154
|
+
should "raise an ObjectNotFound" do
|
155
|
+
error = assert_raises(Xeroizer::ObjectNotFound) { @application.http_get(@application.client, @uri) }
|
156
|
+
assert_equal "Couldn't find object for API Endpoint #{@uri}", error.message
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "429" do
|
162
|
+
setup do
|
163
|
+
@status_code = 429
|
164
|
+
end
|
165
|
+
|
166
|
+
context "rate_limit_exceeded" do
|
167
|
+
setup do
|
168
|
+
stub_request(:get, @uri).to_return(
|
169
|
+
status: @status_code,
|
170
|
+
body: "",
|
171
|
+
headers: {
|
172
|
+
"x-daylimit-remaining" => "328",
|
173
|
+
"retry-after" => "42",
|
174
|
+
}
|
175
|
+
)
|
176
|
+
end
|
177
|
+
|
178
|
+
should "raise an OAuth::RateLimitExceeded" do
|
179
|
+
error = assert_raises(Xeroizer::OAuth::RateLimitExceeded){ @application.http_get(@application.client, @uri) }
|
180
|
+
assert_match /rate limit exceeded/i, error.message
|
181
|
+
assert_match /328 requests left for the day/i, error.message
|
182
|
+
assert_match /42 seconds until you can make another request/i, error.message
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context "503" do
|
188
|
+
setup do
|
189
|
+
@status_code = 503
|
190
|
+
end
|
191
|
+
|
192
|
+
context "token_expired" do
|
193
|
+
setup do
|
194
|
+
body = get_file_as_string("token_expired")
|
195
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
196
|
+
end
|
197
|
+
|
198
|
+
should "raise an OAuth::TokenExpired" do
|
199
|
+
error = assert_raises(Xeroizer::OAuth::TokenExpired) { @application.http_get(@application.client, @uri) }
|
200
|
+
assert_equal "Unexpected token", error.message
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "token_rejected" do
|
205
|
+
setup do
|
206
|
+
body = "oauth_problem_advice=some advice&oauth_problem=token_rejected"
|
207
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
208
|
+
end
|
209
|
+
|
210
|
+
should "raise an OAuth::TokenInvalid" do
|
211
|
+
error = assert_raises(Xeroizer::OAuth::TokenInvalid) { @application.http_get(@application.client, @uri) }
|
212
|
+
assert_equal "some advice", error.message
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "rate limit exceeded" do
|
217
|
+
setup do
|
218
|
+
body = get_file_as_string("rate_limit_exceeded")
|
219
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
220
|
+
end
|
221
|
+
|
222
|
+
should "raise an OAuth::RateLimitExceeded" do
|
223
|
+
error = assert_raises(Xeroizer::OAuth::RateLimitExceeded) { @application.http_get(@application.client, @uri) }
|
224
|
+
assert_equal "please wait before retrying the xero api\n", error.message
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context "consumer_key_unknown" do
|
229
|
+
setup do
|
230
|
+
body = "oauth_problem_advice=some more advice&oauth_problem=consumer_key_unknown"
|
231
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
232
|
+
end
|
233
|
+
|
234
|
+
should "raise an OAuth::ConsumerKeyUnknown" do
|
235
|
+
error = assert_raises(Xeroizer::OAuth::ConsumerKeyUnknown) { @application.http_get(@application.client, @uri) }
|
236
|
+
assert_equal "some more advice", error.message
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context "nonce_used" do
|
241
|
+
setup do
|
242
|
+
body = get_file_as_string("nonce_used")
|
243
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
244
|
+
end
|
245
|
+
|
246
|
+
should "raise an OAuth::NonceUsed" do
|
247
|
+
error = assert_raises(Xeroizer::OAuth::NonceUsed) { @application.http_get(@application.client, @uri) }
|
248
|
+
assert_equal "The nonce value \"potatocakes\" has already been used ", error.message
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
context "organisation offline" do
|
253
|
+
setup do
|
254
|
+
body = "oauth_problem_advice=organisational advice&oauth_problem=organisation offline"
|
255
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
256
|
+
end
|
257
|
+
|
258
|
+
should "raise an OAuth::OrganisationOffline" do
|
259
|
+
error = assert_raises(Xeroizer::OAuth::OrganisationOffline) { @application.http_get(@application.client, @uri) }
|
260
|
+
assert_equal "organisational advice", error.message
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context "unknown error" do
|
265
|
+
setup do
|
266
|
+
body = "oauth_problem_advice=unknown advice&oauth_problem=unknown error"
|
267
|
+
stub_request(:get, @uri).to_return(status: @status_code, body: body)
|
268
|
+
end
|
269
|
+
|
270
|
+
should "raise an OAuth::UnknownError" do
|
271
|
+
error = assert_raises(Xeroizer::OAuth::UnknownError) { @application.http_get(@application.client, @uri) }
|
272
|
+
assert_equal "unknown error:unknown advice", error.message
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "other status" do
|
278
|
+
setup do
|
279
|
+
body = get_file_as_string("token_expired")
|
280
|
+
stub_request(:get, @uri).to_return(status: 418, body: body)
|
281
|
+
end
|
282
|
+
|
283
|
+
should "raise an BadRespone" do
|
284
|
+
error = assert_raises(Xeroizer::BadResponse) { @application.http_get(@application.client, @uri) }
|
285
|
+
assert_equal "Unknown response code: 418", error.message
|
286
|
+
end
|
287
|
+
|
15
288
|
end
|
16
289
|
end
|
17
290
|
end
|
18
|
-
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class AddressTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@client = Xeroizer::
|
7
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
8
8
|
@contact = @client.Contact.build
|
9
9
|
end
|
10
10
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class BankTransactionModelParsingTest < Test::Unit::TestCase
|
4
4
|
def setup
|
@@ -33,7 +33,7 @@ class BankTransactionModelParsingTest < Test::Unit::TestCase
|
|
33
33
|
assert_equal "Inclusive", the_bank_transaction.line_amount_types
|
34
34
|
|
35
35
|
assert_equal(Time.parse("2008-02-20T12:19:56.657Z"), the_bank_transaction.updated_date_utc)
|
36
|
-
|
36
|
+
|
37
37
|
assert_equal Date.parse("2010-07-30T00:00:00"), the_bank_transaction.fully_paid_on_date
|
38
38
|
assert_equal "d20b6c54-7f5d-4ce6-ab83-55f609719126", the_bank_transaction.bank_transaction_id
|
39
39
|
assert_equal "SPEND", the_bank_transaction.type
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class ContactTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
5
|
|
6
6
|
def setup
|
7
|
-
@client = Xeroizer::
|
7
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
8
8
|
end
|
9
9
|
|
10
10
|
context "contact validators" do
|
@@ -21,6 +21,24 @@ class ContactTest < Test::Unit::TestCase
|
|
21
21
|
assert_equal(0, contact.errors.size)
|
22
22
|
end
|
23
23
|
|
24
|
+
should "be able to have no name if it has a contact_id" do
|
25
|
+
contact = @client.Contact.build
|
26
|
+
|
27
|
+
assert_equal(false, contact.valid?)
|
28
|
+
contact.contact_id = "1-2-3"
|
29
|
+
assert_equal(true, contact.valid?)
|
30
|
+
assert_equal(0, contact.errors.size)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "be able to have no name if it has a contact_number" do
|
34
|
+
contact = @client.Contact.build
|
35
|
+
|
36
|
+
assert_equal(false, contact.valid?)
|
37
|
+
contact.contact_number = "abc123"
|
38
|
+
assert_equal(true, contact.valid?)
|
39
|
+
assert_equal(0, contact.errors.size)
|
40
|
+
end
|
41
|
+
|
24
42
|
should "not allow invalid addresses" do
|
25
43
|
contact = @client.Contact.build(name: "SOMETHING")
|
26
44
|
address = contact.add_address(:type => "INVALID_TYPE")
|
@@ -66,15 +84,6 @@ class ContactTest < Test::Unit::TestCase
|
|
66
84
|
assert_equal(contact.attributes.keys, keys)
|
67
85
|
end
|
68
86
|
|
69
|
-
should "be able to have no name if has a contact_id" do
|
70
|
-
contact = @client.Contact.build
|
71
|
-
|
72
|
-
assert_equal(false, contact.valid?)
|
73
|
-
contact.contact_id = "1-2-3"
|
74
|
-
assert_equal(true, contact.valid?)
|
75
|
-
assert_equal(0, contact.errors.size)
|
76
|
-
end
|
77
|
-
|
78
87
|
it "parses extra attributes when present" do
|
79
88
|
@instance = Xeroizer::Record::ContactModel.new(nil, "Contact")
|
80
89
|
some_xml = get_record_xml("contact_with_details")
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class CreditNoteTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
|
-
|
5
|
+
|
6
6
|
def setup
|
7
|
-
@client = Xeroizer::
|
7
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
8
8
|
mock_api("CreditNotes")
|
9
9
|
@credit_note = @client.CreditNote.first
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
context "credit note totals" do
|
13
|
-
|
13
|
+
|
14
14
|
should "raise error when trying to set totals directly" do
|
15
15
|
assert_raises Xeroizer::SettingTotalDirectlyNotSupported do
|
16
16
|
@credit_note.sub_total = 500.0
|
@@ -22,7 +22,7 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
22
22
|
@credit_note.total = 550.0
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
should "large-scale testing from API XML" do
|
27
27
|
credit_notes = @client.CreditNote.all
|
28
28
|
credit_notes.each do | credit_note |
|
@@ -31,7 +31,7 @@ class CreditNoteTest < Test::Unit::TestCase
|
|
31
31
|
assert_equal(credit_note.attributes[:total], credit_note.total)
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class EmployeeTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
5
|
include Xeroizer::Record
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
|
-
@client = Xeroizer::
|
8
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
9
9
|
@employee = @client.Employee.build
|
10
10
|
|
11
11
|
@employee.employee_id = 'GUID'
|
@@ -25,7 +25,7 @@ class EmployeeTest < Test::Unit::TestCase
|
|
25
25
|
@employee.employee_group_name = "TEAM A"
|
26
26
|
@doc = Nokogiri::XML(@employee.to_xml)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should render" do
|
30
30
|
assert_equal "GUID", @doc.xpath("//EmployeeID").text
|
31
31
|
assert_equal "ACTIVE", @doc.xpath("//Status").text
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class InvoiceTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
|
-
|
5
|
+
|
6
6
|
def setup
|
7
|
-
@client = Xeroizer::
|
7
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
8
8
|
mock_api('Invoices')
|
9
9
|
@invoice = @client.Invoice.first
|
10
10
|
end
|
@@ -26,7 +26,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
context "invoice types" do
|
29
|
-
|
29
|
+
|
30
30
|
should "have helpers to determine invoice type" do
|
31
31
|
@invoice.type = 'ACCREC'
|
32
32
|
assert_equal(true, @invoice.accounts_receivable?)
|
@@ -36,11 +36,11 @@ class InvoiceTest < Test::Unit::TestCase
|
|
36
36
|
assert_equal(false, @invoice.accounts_receivable?)
|
37
37
|
assert_equal(true, @invoice.accounts_payable?)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
context "invoice totals" do
|
43
|
-
|
43
|
+
|
44
44
|
should "large-scale testing from API XML" do
|
45
45
|
invoices = @client.Invoice.all
|
46
46
|
invoices.each do | invoice |
|
@@ -51,7 +51,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
context "invoice validations" do
|
56
56
|
|
57
57
|
should "build an invalid invoice if there are no attributes" do
|
@@ -59,7 +59,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
should "build a valid DRAFT invoice with minimal attributes" do
|
62
|
-
invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "ABC Limited" }
|
62
|
+
invoice = @client.Invoice.build :type => "ACCREC", :date => Date.today, :contact => { :name => "ABC Limited" }
|
63
63
|
assert_equal(true, invoice.valid?)
|
64
64
|
end
|
65
65
|
|
@@ -105,7 +105,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
105
105
|
end
|
106
106
|
|
107
107
|
context "contact shortcuts" do
|
108
|
-
|
108
|
+
|
109
109
|
should "have valid #contact_name and #contact_id without downloading full invoice" do
|
110
110
|
invoices = @client.Invoice.all
|
111
111
|
invoices.each do |invoice|
|
@@ -114,13 +114,13 @@ class InvoiceTest < Test::Unit::TestCase
|
|
114
114
|
assert_equal(false, invoice.complete_record_downloaded?)
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
end
|
119
119
|
|
120
120
|
context "updated date" do
|
121
121
|
should "get the updated date as utc" do
|
122
122
|
invoices = @client.Invoice.all
|
123
|
-
|
123
|
+
|
124
124
|
assert_equal(Time.parse("2008-9-16T10:28:51.5Z"), invoices[0].updated_date_utc)
|
125
125
|
|
126
126
|
invoices.each do |invoice|
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class JournalLineTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
5
|
include Xeroizer::Record
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
|
-
@client = Xeroizer::
|
8
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "journal_line tracking specified correctly" do
|
12
12
|
journal = @client.Journal.build
|
13
13
|
journal_line = journal.add_journal_line({})
|
14
|
-
|
14
|
+
|
15
15
|
journal_line.add_tracking_category(:name => "Name 1", :option => "Option 1")
|
16
16
|
journal_line.add_tracking_category(:name => "Name 2", :option => "Option 2")
|
17
|
-
|
17
|
+
|
18
18
|
doc = Nokogiri::XML(journal_line.to_xml)
|
19
19
|
assert_equal 2, doc.xpath("/JournalLine/TrackingCategories/TrackingCategory").size
|
20
20
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class JournalTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
5
|
include Xeroizer::Record
|
6
|
-
|
6
|
+
|
7
7
|
def setup
|
8
|
-
@client = Xeroizer::
|
8
|
+
@client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
|
9
9
|
|
10
10
|
@journal = @client.Journal.build
|
11
11
|
@journal.journal_id = "0d926df3-459f-4264-a3a3-49ac065eb0ed"
|
@@ -39,6 +39,6 @@ class JournalTest < Test::Unit::TestCase
|
|
39
39
|
it "should render date" do
|
40
40
|
assert_equal "2015-01-01", @doc.xpath("//JournalDate").text
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
43
43
|
|
44
44
|
end
|