tsubaiso-sdk 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a427717922d3d59b6816207cffd61f417e78ddf
4
- data.tar.gz: 93becc79ecf8a3cbb692707cdfa536f60c409b00
3
+ metadata.gz: 51bc572f3dcb791e79cb2f38327bd643137599be
4
+ data.tar.gz: 6f3ec294f25b4b37fad5f8e7d089907bd9e0fb6f
5
5
  SHA512:
6
- metadata.gz: c2376f73fe25ff678949e42baf73c991d0dc21ee829d8ceb592a0c66010fcaec176fc62d024c0e80745ecc21b8f5717cb8bb2fe04988f7c285be99b002b0085f
7
- data.tar.gz: fdf3f55f2847df47042ca9ef8f7badd9c032cc2f9781b42fba06394cacdea0da1a157a81625bbc06f7871b494bf22c7d875e1b73ac70535e670d2b756ee82817
6
+ metadata.gz: 0a03738989532ee52b04da7307da90f4229f859bbf6378447d3590a3e455c6bde2883f2a7e357757fa7e914f4adba1f2a26e8126f93a33ab8822fe7d425e0e84
7
+ data.tar.gz: cc316c260e39d0dea3976a452d8efcb55402ae3349e0fd397868704056bd7746da3ce9d52c939df9f15bf3de3447d2b42ddc4235a7e4d063880f165ccbeafaf0
data/lib/tsubaiso_sdk.rb CHANGED
@@ -19,7 +19,7 @@ class TsubaisoSDK
19
19
  def list_sales_and_account_balances(year, month, options = {})
20
20
  params = { "year" => year,
21
21
  "month" => month,
22
- "customer_master_code" => options[:customer_master_code],
22
+ "customer_master_id" => options[:customer_master_id],
23
23
  "ar_segment" => options[:ar_segment],
24
24
  "format" => "json"
25
25
  }
@@ -119,7 +119,7 @@ class TsubaisoSDK
119
119
  "start_created_at" => options[:start_created_at],
120
120
  "finish_created_at" => options[:finish_created_at],
121
121
  "timestamp_order" => options[:timestamp_order],
122
- "account_code" => options[:account_code],
122
+ "account_codes" => options[:account_codes],
123
123
  "price" => options[:price],
124
124
  "memo" => options[:memo],
125
125
  "dept_code" => options[:dept_code],
@@ -429,39 +429,33 @@ class TsubaisoSDK
429
429
  api_request(uri, "POST", params)
430
430
  end
431
431
 
432
- def update_sale(options)
433
- params = { "price_including_tax" => options[:price_including_tax],
434
- "realization_timestamp" => options[:realization_timestamp],
435
- "customer_master_code" => options[:customer_master_code],
436
- "dept_code" => options[:dept_code],
437
- "reason_master_code" => options[:reason_master_code],
438
- "dc" => options[:dc],
432
+ def create_journal_distribution(options)
433
+ params = { "format" => "json",
434
+ "search_conditions" => {
435
+ "start_date" => options[:start_date],
436
+ "finish_date" => options[:finish_date],
437
+ "account_codes" => options[:account_codes],
438
+ "dept_code" => options[:dept_code],
439
+ "tag_list" => options[:tag_list]
440
+ },
441
+ "target_timestamp" => options[:target_timestamp],
439
442
  "memo" => options[:memo],
440
- "tax_code" => options[:tax_code],
441
- "sales_tax" => options[:sales_tax],
442
- "scheduled_memo" => options[:scheduled_memo],
443
- "scheduled_receive_timestamp" => options[:scheduled_receive_timestamp],
444
- "tag_list" => options[:tag_list],
445
- "data_partner" => options[:data_partner],
446
- "format" => "json"
443
+ "criteria" => options[:criteria],
444
+ "distribution_conditions" => options[:distribution_conditions],
445
+ "title" => options[:title]
447
446
  }
447
+ uri = URI.parse(@base_url + '/journal_distributions/create/')
448
+ api_request(uri, "POST", params)
449
+ end
450
+
451
+ def update_sale(options)
452
+ params = options.merge({"format" => "json"})
448
453
  uri = URI.parse(@base_url + "/ar/update/#{options[:id]}")
449
454
  api_request(uri, "POST", params)
450
455
  end
451
456
 
452
457
  def update_purchase(options)
453
- params = { "price_including_tax" => options[:price_including_tax],
454
- "accrual_timestamp" => options[:accrual_timestamp],
455
- "customer_master_code" => options[:customer_master_code],
456
- "dept_code" => options[:dept_code],
457
- "reason_master_code" => options[:reason_master_code],
458
- "dc" => options[:dc],
459
- "memo" => options[:memo],
460
- "tax_code" => options[:tax_code],
461
- "port_type" => options[:port_type],
462
- "tag_list" => options[:tag_list],
463
- "data_partner" => options[:data_partner],
464
- "format" => "json"}
458
+ params = options.merge({"format" => "json"})
465
459
 
466
460
  uri = URI.parse(@base_url + "/ap_payments/update/#{options[:id]}")
467
461
  api_request(uri, "POST", params)
@@ -624,6 +618,12 @@ class TsubaisoSDK
624
618
  api_request(uri, "POST", params)
625
619
  end
626
620
 
621
+ def destroy_journal_distribution(journal_distribution_id)
622
+ params = { "format" => "json" }
623
+ uri = URI.parse(@base_url + "/journal_distributions/destroy/#{journal_distribution_id}")
624
+ api_request(uri, "POST", params)
625
+ end
626
+
627
627
  private
628
628
 
629
629
  def api_request(uri, http_verb, params)
@@ -642,10 +642,10 @@ class TsubaisoSDK
642
642
  begin
643
643
  {:status => response.code, :json => recursive_symbolize_keys(JSON.load(response.body))}
644
644
  rescue
645
- response.body
645
+ {:status => response.code, :body => response.body}
646
646
  end
647
647
  else
648
- response.code
648
+ {:status => response.code}
649
649
  end
650
650
  end
651
651
 
@@ -1,9 +1,41 @@
1
1
  # encoding: utf-8
2
- require 'minitest/autorun'
2
+ require 'test/unit'
3
3
  require 'time'
4
4
  require './lib/tsubaiso_sdk'
5
5
 
6
- class TsubaisoSDKTest < MiniTest::Test
6
+ class TsubaisoSDKTest < Test::Unit::TestCase
7
+
8
+ class <<self
9
+ def startup
10
+ @sdk = TsubaisoSDK.new({ base_url: ENV["SDK_BASE_URL"], access_token: ENV["SDK_ACCESS_TOKEN"] })
11
+
12
+ # Master data prepare
13
+
14
+ # Customer master
15
+ customer_101 = { name: "取引先101", name_kana: "イチマルイチ", code: "101",
16
+ tax_type_for_remittance_charge: "3", used_in_ar: 1, used_in_ap: 1, is_valid: 1}
17
+ # ar_account_code: "135~999" , ap_account_code: "310~999" }
18
+
19
+ customer_102 = { name: "取引先102", name_kana: "トリヒキサキニ", code: "102",
20
+ tax_type_for_remittance_charge: "3", used_in_ar: 1, used_in_ap: 1, is_valid: 1}
21
+ # ar_account_code: "135~999" , ap_account_code: "310~999" }
22
+
23
+ customer_105 = { name: "取引先105", name_kana: "トリヒキサキご", code: "105",
24
+ tax_type_for_remittance_charge: "3", used_in_ar: 1, used_in_ap: 1, is_valid: 1}
25
+ # ar_account_code: "135~999" , ap_account_code: "310~999" }
26
+
27
+ @res_101 = @sdk.create_customer(customer_101)
28
+ @res_102 = @sdk.create_customer(customer_102)
29
+ @res_105 = @sdk.create_customer(customer_105)
30
+
31
+ end
32
+
33
+ def shutdown
34
+ @sdk.destroy_customer(@res_101[:json][:id]) if @res_101 && @res_101[:status].to_i == 200
35
+ @sdk.destroy_customer(@res_102[:json][:id]) if @res_102 && @res_102[:status].to_i == 200
36
+ @sdk.destroy_customer(@res_105[:json][:id]) if @res_105 && @res_105[:status].to_i == 200
37
+ end
38
+ end
7
39
 
8
40
  def setup
9
41
  @api = TsubaisoSDK.new({ base_url: ENV["SDK_BASE_URL"], access_token: ENV["SDK_ACCESS_TOKEN"] })
@@ -18,21 +50,23 @@ class TsubaisoSDKTest < MiniTest::Test
18
50
 
19
51
  @customer_1000 = { name: "テスト株式会社", name_kana: "テストカブシキガイシャ", code: "10000", tax_type_for_remittance_charge: "3", used_in_ar: 1, used_in_ap: 1, is_valid: 1 }
20
52
  @staff_data_1 = { code: "QUALIFICATION", value: "TOEIC", start_timestamp: "2016-01-01", no_finish_timestamp: "1", memo: "First memo" }
21
- @reimbursement_1 = { applicant: "Irfan", application_term: "2016-03-01", staff_code: "EP2000", memo: "aaaaaaaa" }
22
- @reimbursement_2 = { applicant: "Matsuno", application_term: "2016-03-01", staff_code: "EP2000", memo: "aaaaaaaa" }
23
- @reimbursement_tx_1 = { transaction_timestamp: "2016-03-01", price_value: 10000, dc:"c", reason_code:"SUPPLIES", brief:"everyting going well", memo:"easy", data_partner: { link_url: "www.example.com/5", id_code: "5"} }
24
- @reimbursement_tx_2 = { transaction_timestamp: "2016-03-01", price_value: 20000, dc:"c", reason_code:"SUPPLIES", brief:"not well", memo:"hard", data_partner: { link_url: "www.example.com/6", id_code: "6"} }
53
+ @reimbursement_1 = { applicant: "Irfan", application_term: "2016-03-01", memo: "aaaaaaaa" }
54
+ @reimbursement_2 = { applicant: "Matsuno", application_term: "2016-03-01", memo: "aaaaaaaa" }
55
+ @reimbursement_tx_1 = { transaction_timestamp: "2016-03-01", price_value: 10000, dc:"c", reason_code:"MEETING", brief:"everyting going well", memo:"easy", data_partner: { link_url: "www.example.com/5", id_code: "5"} }
56
+ @reimbursement_tx_2 = { transaction_timestamp: "2016-03-01", price_value: 20000, dc:"c", reason_code:"MEETING", brief:"not well", memo:"hard", data_partner: { link_url: "www.example.com/6", id_code: "6"} }
25
57
  @manual_journal_1 = {journal_timestamp: "2016-04-01", journal_dcs: [
26
- debit: {account_code: 100, price_including_tax: 1000, tax_type: 1, sales_tax: 100},
27
- credit: {account_code: 135, price_including_tax: 1000, tax_type: 1, sales_tax: 100} ], data_partner: { link_url: "www.example.com/7", id_code: "7"} }
58
+ debit: {account_code: 110, price_including_tax: 1000, tax_type: 1, sales_tax: 100},
59
+ credit: {account_code: 130, price_including_tax: 1000, tax_type: 1, sales_tax: 100} ], data_partner: { link_url: "www.example.com/7", id_code: "7"} }
28
60
  @dept_1= {sort_no: 12345678, code: 'test_code', name: 'テスト部門', name_abbr: 'テストブモン', color: '#ffffff', memo: 'テストメモ', start_date: '2016-01-01', finish_date: '2016-01-02'}
29
61
  @tag_1 = {code: 'test_code', name: 'テストタグ', sort_no: 10000, tag_group_code: "DEFAULT", start_ymd: '2016-01-01', finish_ymd: '2016-12-31'}
62
+ @journal_distribution_1 = { start_date: "2016-09-01", finish_date: "2016-09-30", account_codes: ["135~999","604"], dept_code: "SETSURITSU", memo: "",
63
+ title: "テスト表題" ,criteria: "dept", target_timestamp: "2017-02-01",
64
+ distribution_conditions: { "SETSURITSU" => "1", "SYSTEM" => "1" } }
30
65
  end
31
66
 
32
67
  def test_failed_request
33
68
  @api_fail = TsubaisoSDK.new({ base_url: ENV["SDK_BASE_URL"], access_token: "fake token" })
34
69
  sale = @api_fail.create_sale(@sale_201608)
35
-
36
70
  assert_equal 401, sale[:status].to_i, sale.inspect
37
71
  assert_equal "Bad credentials", sale[:json][:error]
38
72
  end
@@ -44,7 +78,7 @@ class TsubaisoSDKTest < MiniTest::Test
44
78
  assert_equal @customer_1000[:name], customer[:json][:name]
45
79
 
46
80
  ensure
47
- @api.destroy_customer(customer[:json][:id]) if customer[:json][:id]
81
+ @api.destroy_customer(customer[:json][:id]) if successful?(customer)
48
82
  end
49
83
 
50
84
  def test_create_sale
@@ -55,7 +89,7 @@ class TsubaisoSDKTest < MiniTest::Test
55
89
  assert_equal @sale_201608[:data_partner][:id_code], sale[:json][:data_partner][:id_code]
56
90
 
57
91
  ensure
58
- @api.destroy_sale("AR#{sale[:json][:id]}") if sale[:json][:id]
92
+ @api.destroy_sale("AR#{sale[:json][:id]}") if successful?(sale)
59
93
  end
60
94
 
61
95
  def test_create_purchase
@@ -66,7 +100,7 @@ class TsubaisoSDKTest < MiniTest::Test
66
100
  assert_equal @purchase_201608[:data_partner][:id_code], purchase[:json][:data_partner][:id_code]
67
101
 
68
102
  ensure
69
- @api.destroy_purchase("AP#{purchase[:json][:id]}") if purchase[:json][:id]
103
+ @api.destroy_purchase("AP#{purchase[:json][:id]}") if successful?(purchase)
70
104
  end
71
105
 
72
106
  def test_create_staff_data
@@ -80,7 +114,7 @@ class TsubaisoSDKTest < MiniTest::Test
80
114
  assert_equal @staff_data_1[:value], staff_data[:json][:value]
81
115
 
82
116
  ensure
83
- @api.destroy_staff_data(staff_data[:json][:id]) if staff_data[:json][:id]
117
+ @api.destroy_staff_data(staff_data[:json][:id]) if successful?(staff_data)
84
118
  end
85
119
 
86
120
  def test_create_manual_journal
@@ -92,7 +126,7 @@ class TsubaisoSDKTest < MiniTest::Test
92
126
  assert_equal @manual_journal_1[:data_partner][:id_code], manual_journal[:json][:data_partner][:id_code]
93
127
 
94
128
  ensure
95
- @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal[:status])
129
+ @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal)
96
130
  end
97
131
  end
98
132
 
@@ -102,7 +136,7 @@ class TsubaisoSDKTest < MiniTest::Test
102
136
  assert_equal @reimbursement_1[:applicant], reimbursement[:json][:applicant]
103
137
 
104
138
  ensure
105
- @api.destroy_reimbursement(reimbursement[:json][:id]) if reimbursement[:json][:id]
139
+ @api.destroy_reimbursement(reimbursement[:json][:id]) if successful?(reimbursement)
106
140
  end
107
141
 
108
142
  def test_create_reimbursement_transaction
@@ -114,8 +148,8 @@ class TsubaisoSDKTest < MiniTest::Test
114
148
  assert_equal @reimbursement_tx_1[:data_partner][:id_code], reimbursement_transaction[:json][:data_partner][:id_code]
115
149
 
116
150
  ensure
117
- @api.destroy_reimbursement_transaction(reimbursement_transaction[:json][:id]) if reimbursement_transaction[:json][:id]
118
- @api.destroy_reimbursement(reimbursement[:json][:id]) if reimbursement[:json][:id]
151
+ @api.destroy_reimbursement_transaction(reimbursement_transaction[:json][:id]) if successful?(reimbursement_transaction)
152
+ @api.destroy_reimbursement(reimbursement[:json][:id]) if successful?(reimbursement)
119
153
  end
120
154
 
121
155
  def test_create_dept
@@ -124,7 +158,7 @@ class TsubaisoSDKTest < MiniTest::Test
124
158
  assert_equal @dept_1[:code], dept[:json][:code]
125
159
 
126
160
  ensure
127
- @api.destroy_dept(dept[:json][:id]) if dept[:json][:id]
161
+ @api.destroy_dept(dept[:json][:id]) if successful?(dept)
128
162
  end
129
163
 
130
164
  def test_create_tag
@@ -133,7 +167,31 @@ class TsubaisoSDKTest < MiniTest::Test
133
167
  assert_equal @tag_1[:code], tag[:json][:code]
134
168
 
135
169
  ensure
136
- @api.destroy_tag(tag[:json][:id]) if tag[:json][:id]
170
+ @api.destroy_tag(tag[:json][:id]) if successful?(tag)
171
+ end
172
+
173
+ def test_create_journal_distribution
174
+
175
+ sale = @api.create_sale(@sale_201609)
176
+
177
+ options = { start_date: @journal_distribution_1[:target_timestamp], finish_date: @journal_distribution_1[:target_timestamp] }
178
+
179
+ journals_list_before = @api.list_journals(options)
180
+ records_before_count = journals_list_before[:json][:records].count
181
+ assert_equal 200, journals_list_before[:status].to_i, journals_list_before.inspect
182
+
183
+ journal_distribution = @api.create_journal_distribution(@journal_distribution_1)
184
+ assert_equal 200, journal_distribution[:status].to_i, journal_distribution.inspect
185
+ assert_equal Time.parse(@journal_distribution_1[:target_timestamp]), Time.parse(journal_distribution[:json][:target_ym])
186
+
187
+ journals_list_after = @api.list_journals(options)
188
+ records_after_count = journals_list_after[:json][:records].count
189
+ assert_equal 200, journals_list_after[:status].to_i, journals_list_after.inspect
190
+ assert (records_before_count != records_after_count)
191
+
192
+ ensure
193
+ @api.destroy_journal_distribution(journal_distribution[:json][:id]) if successful?(journal_distribution)
194
+ @api.destroy_sale("AR#{sale[:json][:id]}") if successful?(sale)
137
195
  end
138
196
 
139
197
  def test_update_sale
@@ -144,16 +202,17 @@ class TsubaisoSDKTest < MiniTest::Test
144
202
  data_partner: { id_code: "100" } }
145
203
 
146
204
  updated_sale = @api.update_sale(options)
147
- assert_equal 200, updated_sale[:status].to_i
205
+ assert_equal 200, updated_sale[:status].to_i, updated_sale[:json]
148
206
  assert_equal options[:id], updated_sale[:json][:id]
149
207
  assert_equal options[:memo], updated_sale[:json][:memo]
150
208
  assert_equal options[:price_including_tax], updated_sale[:json][:price_including_tax]
151
209
  assert_equal options[:data_partner][:id_code], updated_sale[:json][:data_partner][:id_code]
152
210
 
153
211
  ensure
154
- @api.destroy_sale("AP#{sale[:json][:id]}") if sale[:json][:id]
212
+ @api.destroy_sale("AP#{sale[:json][:id]}") if successful?(sale)
155
213
  end
156
214
 
215
+
157
216
  def test_update_purchase
158
217
  purchase = @api.create_purchase(@purchase_201608)
159
218
  options = { id: purchase[:json][:id],
@@ -169,7 +228,7 @@ class TsubaisoSDKTest < MiniTest::Test
169
228
  assert_equal options[:data_partner][:id_code], updated_purchase[:json][:data_partner][:id_code]
170
229
 
171
230
  ensure
172
- @api.destroy_purchase("AP#{purchase[:json][:id]}") if purchase[:json][:id]
231
+ @api.destroy_purchase("AP#{purchase[:json][:id]}") if successful?(purchase)
173
232
  end
174
233
 
175
234
  def test_update_customer
@@ -183,7 +242,7 @@ class TsubaisoSDKTest < MiniTest::Test
183
242
  assert_equal "New Customer Name", updated_customer[:json][:name]
184
243
 
185
244
  ensure
186
- @api.destroy_customer(customer[:json][:id]) if customer[:json][:id]
245
+ @api.destroy_customer(customer[:json][:id]) if successful?(customer)
187
246
  end
188
247
 
189
248
  def test_update_staff_data
@@ -202,7 +261,7 @@ class TsubaisoSDKTest < MiniTest::Test
202
261
  assert_equal "Programmer", updated_staff_data[:json][:value]
203
262
 
204
263
  ensure
205
- @api.destroy_staff_data(staff_data[:json][:id]) if staff_data[:json][:id]
264
+ @api.destroy_staff_data(staff_data[:json][:id]) if successful?(staff_data)
206
265
  end
207
266
 
208
267
  def test_update_reimbursement
@@ -217,14 +276,14 @@ class TsubaisoSDKTest < MiniTest::Test
217
276
  assert_equal options[:dept_code], updated_reimbursement[:json][:dept_code]
218
277
 
219
278
  ensure
220
- @api.destroy_reimbursement(updated_reimbursement[:json][:id] || reimbursement[:json][:id]) if updated_reimbursement[:json][:id] || reimbursement[:json][:id]
279
+ @api.destroy_reimbursement(updated_reimbursement[:json][:id] || reimbursement[:json][:id]) if successful?(updated_reimbursement) || successful?(reimbursement)
221
280
  end
222
281
 
223
282
  def test_update_reimbursement_transaction
224
283
  reimbursement = @api.create_reimbursement(@reimbursement_1)
225
284
  options = @reimbursement_tx_1.merge({ :reimbursement_id => reimbursement[:json][:id].to_i })
226
285
  reimbursement_transaction = @api.create_reimbursement_transaction(options)
227
- updates = { :id => reimbursement_transaction[:json][:id], :price_value => 9999, :reason_code => "SUPPLIES", :data_partner => { :id_code => "500" } }
286
+ updates = { :id => reimbursement_transaction[:json][:id], :price_value => 9999, :reason_code => "RENTS", :data_partner => { :id_code => "500" } }
228
287
 
229
288
  updated_reimbursement_transaction = @api.update_reimbursement_transaction(updates)
230
289
  assert_equal 200, updated_reimbursement_transaction[:status].to_i, updated_reimbursement_transaction.inspect
@@ -234,8 +293,8 @@ class TsubaisoSDKTest < MiniTest::Test
234
293
  assert_equal updates[:data_partner][:id_code], updated_reimbursement_transaction[:json][:data_partner][:id_code]
235
294
 
236
295
  ensure
237
- @api.destroy_reimbursement_transaction(reimbursement_transaction[:json][:id]) if reimbursement_transaction[:json][:id]
238
- @api.destroy_reimbursement(reimbursement[:json][:id]) if reimbursement[:json][:id]
296
+ @api.destroy_reimbursement_transaction(reimbursement_transaction[:json][:id]) if successful?(reimbursement_transaction)
297
+ @api.destroy_reimbursement(reimbursement[:json][:id]) if successful?(reimbursement)
239
298
  end
240
299
 
241
300
  def test_update_manual_journal
@@ -253,7 +312,7 @@ class TsubaisoSDKTest < MiniTest::Test
253
312
  assert_equal options[:data_partner][:id_code], updated_manual_journal[:json][:data_partner][:id_code]
254
313
 
255
314
  ensure
256
- @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal[:status])
315
+ @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal)
257
316
  end
258
317
 
259
318
  def test_update_dept
@@ -272,7 +331,7 @@ class TsubaisoSDKTest < MiniTest::Test
272
331
  assert_equal options[:name_abbr], updated_dept[:json][:name_abbr]
273
332
 
274
333
  ensure
275
- @api.destroy_dept(updated_dept[:json][:id] || dept[:json][:id]) if updated_dept[:json][:id] || dept[:json][:id]
334
+ @api.destroy_dept(updated_dept[:json][:id] || dept[:json][:id]) if successful?(updated_dept) || successful?(dept)
276
335
  end
277
336
 
278
337
  def test_update_tag
@@ -287,7 +346,7 @@ class TsubaisoSDKTest < MiniTest::Test
287
346
  assert_equal options[:code], updated_tag[:json][:code]
288
347
 
289
348
  ensure
290
- @api.destroy_tag(updated_tag[:json][:id] || tag[:json][:id]) if updated_tag[:json][:id] || tag[:json][:id]
349
+ @api.destroy_tag(updated_tag[:json][:id] || tag[:json][:id]) if successful?(updated_tag) || successful?(tag)
291
350
  end
292
351
 
293
352
  def test_show_sale
@@ -298,7 +357,7 @@ class TsubaisoSDKTest < MiniTest::Test
298
357
  assert_equal sale[:json][:price_including_tax], get_sale[:json][:price_including_tax]
299
358
 
300
359
  ensure
301
- @api.destroy_sale("AR#{sale[:json][:id]}") if sale[:json][:id]
360
+ @api.destroy_sale("AR#{sale[:json][:id]}") if successful?(sale)
302
361
  end
303
362
 
304
363
  def test_show_purchase
@@ -309,7 +368,7 @@ class TsubaisoSDKTest < MiniTest::Test
309
368
  assert_equal purchase[:json][:id], get_purchase[:json][:id]
310
369
 
311
370
  ensure
312
- @api.destroy_purchase("AP#{purchase[:json][:id]}") if purchase[:json][:id]
371
+ @api.destroy_purchase("AP#{purchase[:json][:id]}") if successful?(purchase)
313
372
  end
314
373
 
315
374
  def test_show_customer
@@ -320,7 +379,7 @@ class TsubaisoSDKTest < MiniTest::Test
320
379
  assert_equal customer[:json][:id], get_customer[:json][:id]
321
380
 
322
381
  ensure
323
- @api.destroy_customer(customer[:json][:id]) if customer[:json][:id]
382
+ @api.destroy_customer(customer[:json][:id]) if successful?(customer)
324
383
  end
325
384
 
326
385
  def test_show_staff
@@ -355,7 +414,7 @@ class TsubaisoSDKTest < MiniTest::Test
355
414
  assert_equal staff_data[:json][:id], get_staff_data_2[:json][:id]
356
415
 
357
416
  ensure
358
- @api.destroy_staff_data(staff_data[:json][:id]) if staff_data[:json][:id]
417
+ @api.destroy_staff_data(staff_data[:json][:id]) if successful?(staff_data)
359
418
  end
360
419
 
361
420
  def test_show_staff_datum_master
@@ -386,7 +445,7 @@ class TsubaisoSDKTest < MiniTest::Test
386
445
  assert_equal 200, reimbursement[:status].to_i, reimbursement.inspect
387
446
  assert_equal @reimbursement_1[:applicant], reimbursement[:json][:applicant]
388
447
  ensure
389
- @api.destroy_reimbursement(reimbursement[:json][:id])
448
+ @api.destroy_reimbursement(reimbursement[:json][:id]) if successful?(reimbursement)
390
449
  end
391
450
 
392
451
  def test_show_reimbursement_reason_master
@@ -408,8 +467,8 @@ class TsubaisoSDKTest < MiniTest::Test
408
467
  assert_equal options[:reimbursement_id], reimbursement_transaction[:json][:reimbursement_id]
409
468
 
410
469
  ensure
411
- @api.destroy_reimbursement_transaction(reimbursement_transaction[:json][:id]) if reimbursement_transaction[:json][:id]
412
- @api.destroy_reimbursement(reimbursement[:json][:id]) if reimbursement[:json][:id]
470
+ @api.destroy_reimbursement_transaction(reimbursement_transaction[:json][:id]) if successful?(reimbursement_transaction)
471
+ @api.destroy_reimbursement(reimbursement[:json][:id]) if successful?(reimbursement)
413
472
  end
414
473
 
415
474
  def test_show_manual_journal
@@ -422,7 +481,7 @@ class TsubaisoSDKTest < MiniTest::Test
422
481
  assert_equal first_manual_journal_id, manual_journal[:json][:id]
423
482
 
424
483
  ensure
425
- @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal[:status])
484
+ @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal)
426
485
  end
427
486
 
428
487
  def test_show_journal
@@ -435,7 +494,7 @@ class TsubaisoSDKTest < MiniTest::Test
435
494
  assert_equal first_journal_id, journal[:json][:records][:id]
436
495
 
437
496
  ensure
438
- @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal[:status])
497
+ @api.destroy_manual_journal(manual_journal[:json][:id]) if successful?(manual_journal)
439
498
  end
440
499
 
441
500
  def test_show_dept
@@ -445,7 +504,7 @@ class TsubaisoSDKTest < MiniTest::Test
445
504
  assert_equal 200, dept[:status].to_i, dept.inspect
446
505
  assert_equal @dept_1[:memo], dept[:json][:memo]
447
506
  ensure
448
- @api.destroy_dept(dept[:json][:id])
507
+ @api.destroy_dept(dept[:json][:id]) if successful?(dept)
449
508
  end
450
509
 
451
510
  def test_show_tag
@@ -455,7 +514,7 @@ class TsubaisoSDKTest < MiniTest::Test
455
514
  assert_equal 200, tag[:status].to_i, tag.inspect
456
515
  assert_equal @tag_1[:name], tag[:json][:name]
457
516
  ensure
458
- @api.destroy_tag(tag[:json][:id])
517
+ @api.destroy_tag(tag[:json][:id]) if successful?(tag)
459
518
  end
460
519
 
461
520
  def test_show_bonus
@@ -468,7 +527,7 @@ class TsubaisoSDKTest < MiniTest::Test
468
527
  end
469
528
 
470
529
  def test_show_payroll
471
- payrolls_list = @api.list_payrolls(2017, 1)
530
+ payrolls_list = @api.list_payrolls(2016, 2)
472
531
  first_payroll_id = payrolls_list[:json].first[:id]
473
532
 
474
533
  payroll = @api.show_payroll(first_payroll_id)
@@ -510,9 +569,9 @@ class TsubaisoSDKTest < MiniTest::Test
510
569
  assert !sales_list[:json].any?{ |x| x[:id] == september_sale_id }
511
570
 
512
571
  ensure
513
- @api.destroy_sale("AR#{august_sale_a[:json][:id]}") if august_sale_a[:json][:id]
514
- @api.destroy_sale("AR#{august_sale_b[:json][:id]}") if august_sale_b[:json][:id]
515
- @api.destroy_sale("AR#{september_sale[:json][:id]}") if september_sale[:json][:id]
572
+ @api.destroy_sale("AR#{august_sale_a[:json][:id]}") if successful?(august_sale_a)
573
+ @api.destroy_sale("AR#{august_sale_b[:json][:id]}") if successful?(august_sale_b)
574
+ @api.destroy_sale("AR#{september_sale[:json][:id]}") if successful?(september_sale)
516
575
  end
517
576
 
518
577
  def test_list_sales_and_account_balances
@@ -534,20 +593,15 @@ class TsubaisoSDKTest < MiniTest::Test
534
593
  customer_masters_list = @api.list_customers
535
594
  assert_equal 200, customer_masters_list[:status].to_i, customer_masters_list.inspect
536
595
  assert customer_masters_list[:json].any?{ |x| x[:code] == new_sale[:json][:customer_master_code] }
537
- filtered_customer_master = customer_masters_list[:json].select{ |x| x[:code] == new_sale[:json][:customer_master_code] }.first
538
- customer_master_code = filtered_customer_master[:code]
539
- ar_segment = filtered_customer_master[:used_in_ar]
596
+ filtered_cm = customer_masters_list[:json].select{ |x| x[:code] == new_sale[:json][:customer_master_code] }.first
540
597
 
541
598
  # With customer_master_id and ar_segment option parameters
542
- balance_list = @api.list_sales_and_account_balances(realization_timestamp.year, realization_timestamp.month, :customer_master_code => customer_master_code, :ar_segment => ar_segment)
599
+ balance_list = @api.list_sales_and_account_balances(realization_timestamp.year, realization_timestamp.month, :customer_master_id => filtered_cm[:id], :ar_segment => filtered_cm[:used_in_ar])
543
600
  assert_equal 200, balance_list[:status].to_i, balance_list.inspect
544
601
  assert(balance_list[:json].count > 0)
545
- balance_list[:json].each do |x|
546
- assert x[:customer_master_code] == customer_master_code, "#{x} customer_master_code is right"
547
- assert x[:ar_segment] == ar_segment, "ar_segment is not right"
548
- end
602
+ assert balance_list[:json].all?{ |x| x[:customer_master_code] == filtered_cm[:code] && x[:ar_segment] == filtered_cm[:used_in_ar] }
549
603
  ensure
550
- @api.destroy_sale("AR#{new_sale[:json][:id]}") if new_sale[:json][:id]
604
+ @api.destroy_sale("AR#{new_sale[:json][:id]}") if successful?(new_sale)
551
605
  end
552
606
 
553
607
  def test_list_purchases
@@ -566,9 +620,9 @@ class TsubaisoSDKTest < MiniTest::Test
566
620
  assert !purchase_list[:json].any?{ |x| x[:id] == september_purchase_id }
567
621
 
568
622
  ensure
569
- @api.destroy_purchase("AP#{august_purchase_a[:json][:id]}") if august_purchase_a[:json][:id]
570
- @api.destroy_purchase("AP#{august_purchase_b[:json][:id]}") if august_purchase_b[:json][:id]
571
- @api.destroy_purchase("AP#{september_purchase[:json][:id]}") if september_purchase[:json][:id]
623
+ @api.destroy_purchase("AP#{august_purchase_a[:json][:id]}") if successful?(august_purchase_a)
624
+ @api.destroy_purchase("AP#{august_purchase_b[:json][:id]}") if successful?(august_purchase_b)
625
+ @api.destroy_purchase("AP#{september_purchase[:json][:id]}") if successful?(september_purchase)
572
626
  end
573
627
 
574
628
  def test_list_purchases_and_account_balances
@@ -600,7 +654,7 @@ class TsubaisoSDKTest < MiniTest::Test
600
654
  assert(balance_list[:json].count > 0)
601
655
  assert balance_list[:json].all?{ |x| x[:customer_master_id] == customer_master_id && x[:ap_segment] == ap_segment }
602
656
  ensure
603
- @api.destroy_purchase("AP#{new_purchase[:json][:id]}") if new_purchase[:json][:id]
657
+ @api.destroy_purchase("AP#{new_purchase[:json][:id]}") if successful?(new_purchase)
604
658
  end
605
659
 
606
660
  def test_list_customers
@@ -613,7 +667,7 @@ class TsubaisoSDKTest < MiniTest::Test
613
667
  assert customer_list[:json].any?{ |x| x[:id] == customer_1000_id }
614
668
 
615
669
  ensure
616
- @api.destroy_customer(customer_1000[:json][:id]) if customer_1000[:json][:id]
670
+ @api.destroy_customer(customer_1000[:json][:id]) if successful?(customer_1000)
617
671
  end
618
672
 
619
673
  def test_list_staff
@@ -653,9 +707,9 @@ class TsubaisoSDKTest < MiniTest::Test
653
707
  journals_list = @api.list_journals(options)
654
708
  records = journals_list[:json][:records]
655
709
  assert_equal 200, journals_list[:status].to_i, journals_list.inspect
656
- record_timestamps = records.map { |x| x[:journal_timestamp].split(" ")[0] }
657
- assert_includes record_timestamps, august_sale[:json][:realization_timestamp]
658
- assert_includes record_timestamps, august_purchase[:json][:accrual_timestamp]
710
+ record_timestamps = records.map { |x| Time.parse(x[:journal_timestamp]) }
711
+ assert_includes record_timestamps, Time.parse(august_sale[:json][:realization_timestamp])
712
+ assert_includes record_timestamps, Time.parse(august_purchase[:json][:accrual_timestamp])
659
713
 
660
714
  options = { price: 10800 }
661
715
  journals_list = @api.list_journals(options)
@@ -676,10 +730,10 @@ class TsubaisoSDKTest < MiniTest::Test
676
730
  assert_includes record_depts, september_purchase[:json][:dept_code]
677
731
 
678
732
  ensure
679
- @api.destroy_sale("AR#{august_sale[:json][:id]}") if august_sale[:json][:id]
680
- @api.destroy_sale("AR#{september_sale[:json][:id]}") if september_sale[:json][:id]
681
- @api.destroy_purchase("AP#{august_purchase[:json][:id]}") if august_purchase[:json][:id]
682
- @api.destroy_purchase("AP#{september_purchase[:json][:id]}") if september_purchase[:json][:id]
733
+ @api.destroy_sale("AR#{august_sale[:json][:id]}") if successful?(august_sale)
734
+ @api.destroy_sale("AR#{september_sale[:json][:id]}") if successful?(september_sale)
735
+ @api.destroy_purchase("AP#{august_purchase[:json][:id]}") if successful?(august_purchase)
736
+ @api.destroy_purchase("AP#{september_purchase[:json][:id]}") if successful?(september_purchase)
683
737
  end
684
738
 
685
739
  def test_list_reimbursements
@@ -718,9 +772,9 @@ class TsubaisoSDKTest < MiniTest::Test
718
772
  assert reimbursement_transactions[:json].any?{ |x| x[:id] == reimbursement_transaction_2[:json][:id] }
719
773
 
720
774
  ensure
721
- @api.destroy_reimbursement_transaction(reimbursement_transaction_1[:json][:id]) if reimbursement_transaction_1[:json][:id]
722
- @api.destroy_reimbursement_transaction(reimbursement_transaction_1[:json][:id]) if reimbursement_transaction_1[:json][:id]
723
- @api.destroy_reimbursement(reimbursement[:json][:id]) if reimbursement[:json][:id]
775
+ @api.destroy_reimbursement_transaction(reimbursement_transaction_1[:json][:id]) if successful?(reimbursement_transaction_1)
776
+ @api.destroy_reimbursement_transaction(reimbursement_transaction_2[:json][:id]) if successful?(reimbursement_transaction_2)
777
+ @api.destroy_reimbursement(reimbursement[:json][:id]) if successful?(reimbursement)
724
778
  end
725
779
 
726
780
  def test_list_depts
@@ -731,7 +785,7 @@ class TsubaisoSDKTest < MiniTest::Test
731
785
  assert depts[:json].any?{ |x| x[:id] == dept[:json][:id] }
732
786
 
733
787
  ensure
734
- @api.destroy_dept(dept[:json][:id]) if dept[:json][:id]
788
+ @api.destroy_dept(dept[:json][:id]) if successful?(dept)
735
789
  end
736
790
 
737
791
  def test_list_tags
@@ -742,7 +796,7 @@ class TsubaisoSDKTest < MiniTest::Test
742
796
  assert tags[:json][@tag_1[:tag_group_code].to_sym].any?{ |x| x[:id] == tag[:json][:id] }
743
797
 
744
798
  ensure
745
- @api.destroy_tag(tag[:json][:id]) if tag[:json][:id]
799
+ @api.destroy_tag(tag[:json][:id]) if successful?(tag)
746
800
  end
747
801
 
748
802
  def test_list_bonuses
@@ -756,7 +810,7 @@ class TsubaisoSDKTest < MiniTest::Test
756
810
  payrolls_list = @api.list_payrolls(2016, 2)
757
811
 
758
812
  assert_equal 200, payrolls_list[:status].to_i, payrolls_list.inspect
759
- assert(payrolls_list.size > 0)
813
+ assert(payrolls_list[:json].size > 0)
760
814
  end
761
815
 
762
816
  def test_list_ar_reason_masters
@@ -773,8 +827,127 @@ class TsubaisoSDKTest < MiniTest::Test
773
827
  assert(ap_reason_masters_list[:json].size > 0)
774
828
  end
775
829
 
830
+ def test_destroy_sale
831
+ sale = @api.create_sale(@sale_201608)
832
+
833
+ destroy_res = @api.destroy_sale("AR#{sale[:json][:id]}")
834
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
835
+
836
+ show_res = @api.show_res("AR#{sale[:json][:id]}")
837
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
838
+ end
839
+
840
+ def test_destroy_purchase
841
+ purchase = @api.create_purchase(@purchase_201608)
842
+
843
+ destroy_res = @api.destroy_purchase("AP#{purchase[:json][:id]}")
844
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
845
+
846
+ show_res = @api.show_purchase("AP#{purchase[:json][:id]}")
847
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
848
+ end
849
+
850
+ def test_destroy_customer
851
+ customer = @api.create_customer(@customer_1000)
852
+
853
+ destroy_res = @api.destroy_customer(customer[:json][:id])
854
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
855
+
856
+ show_res = @api.show_customer(customer[:json][:id])
857
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
858
+ end
859
+
860
+ def test_destroy_staff_data
861
+ staff_list = @api.list_staff
862
+ first_staff_id = staff_list[:json].first[:id]
863
+ @staff_data_1[:staff_id] = first_staff_id
864
+ staff_data = @api.create_staff_data(@staff_data_1)
865
+
866
+ destroy_res = @api.destroy_staff_data(staff_data[:json][:id])
867
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
868
+
869
+ show_res = @api.show_staff_data(staff_data[:json][:id])
870
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
871
+ end
872
+
873
+ def test_destroy_manual_journal
874
+ manual_journal = @api.create_manual_journal(@manual_journal_1)
875
+
876
+ destroy_res = @api.destroy_manual_journal(manual_journal[:json][:id])
877
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
878
+
879
+ show_res = @api.show_manual_journal(manual_journal[:json][:id])
880
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
881
+ end
882
+
883
+ def test_destroy_reimbursement
884
+ reimbursement = @api.create_reimbursement(@reimbursement_1)
885
+
886
+ destroy_res = @api.destroy_reimbursement(reimbursement[:json][:id])
887
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
888
+
889
+ show_res = @api.show_reimbursement(reimbursement[:json][:id])
890
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
891
+ end
892
+
893
+ def test_destroy_reimbursement_transaction
894
+ reimbursement = @api.create_reimbursement(@reimbursement_1)
895
+ options = @reimbursement_tx_1.merge({ :reimbursement_id => reimbursement[:json][:id] })
896
+ reimbursement_transaction = @api.create_reimbursement_transaction(options)
897
+
898
+ destroy_res = @api.destroy_reimbursement_transaction(reimbursement_transaction[:json][:id])
899
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
900
+
901
+ show_res = @api.show_reimbursement_transaction(reimbursement_transaction[:json][:id])
902
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
903
+
904
+ ensure
905
+ @api.destroy_reimbursement(reimbursement[:json][:id]) if successful?(reimbursement)
906
+ end
907
+
908
+ def test_destroy_dept
909
+ dept = @api.create_dept(@dept_1)
910
+
911
+ destroy_res = @api.destroy_dept(dept[:json][:id])
912
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
913
+
914
+ show_res = @api.show_dept(dept[:json][:id])
915
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
916
+ end
917
+
918
+ def test_destroy_tag
919
+ tag = @api.create_tag(@tag_1)
920
+
921
+ destroy_res = @api.destroy_tag(tag[:json][:id])
922
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
923
+
924
+ show_res = @api.show_tag(tag[:json][:id])
925
+ assert_equal 404, show_res[:status].to_i, show_res.inspect
926
+ end
927
+
928
+ def test_destroy_journal_distribution
929
+ sale = @api.create_sale(@sale_201609)
930
+ options = { start_date: @journal_distribution_1[:target_timestamp], finish_date: @journal_distribution_1[:target_timestamp] }
931
+ journals_list_before = @api.list_journals(options)
932
+ records_before_count = journals_list_before[:json][:records].count
933
+ journal_distribution = @api.create_journal_distribution(@journal_distribution_1)
934
+ journals_list_after = @api.list_journals(options)
935
+ records_after_count = journals_list_after[:json][:records].count
936
+ assert (records_before_count < records_after_count)
937
+
938
+ destroy_res = @api.destroy_journal_distribution(journal_distribution[:json][:id])
939
+ assert_equal 204, destroy_res[:status].to_i, destroy_res.inspect
940
+
941
+ journals_list_after_destroy = @api.list_journals(options)
942
+ records_count_after_destroy = journals_list_after_destroy[:json][:records].count
943
+ assert (records_before_count == records_count_after_destroy)
944
+
945
+ ensure
946
+ @api.destroy_sale("AR#{sale[:json][:id]}") if successful?(sale)
947
+ end
948
+
776
949
  private
777
- def successful?(status)
778
- status.to_i == 200
950
+ def successful?(response)
951
+ response && response[:status].to_i == 200
779
952
  end
780
953
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsubaiso-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tsubaiso, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -31,25 +31,25 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.8.3
33
33
  - !ruby/object:Gem::Dependency
34
- name: minitest
34
+ name: test-unit
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '5.4'
39
+ version: '3.0'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 5.4.3
42
+ version: 3.0.8
43
43
  type: :development
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '5.4'
49
+ version: '3.0'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 5.4.3
52
+ version: 3.0.8
53
53
  description: A library of methods that directly uses Tsubaiso API web endpoints.
54
54
  email: apisupport@tsubaiso.net
55
55
  executables: []
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project:
84
- rubygems_version: 2.4.8
84
+ rubygems_version: 2.6.12
85
85
  signing_key:
86
86
  specification_version: 4
87
87
  summary: SDK for the Tsubaiso API