tsubaiso-sdk 1.2.6 → 1.2.7

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -2
  3. data/lib/tsubaiso_sdk.rb +550 -118
  4. data/test/stubbings/stub_register.rb +196 -0
  5. data/test/tsubaiso_sdk/common_setup_and_teardown.rb +23 -0
  6. data/test/tsubaiso_sdk/test_ap_reason_masters.rb +26 -0
  7. data/test/tsubaiso_sdk/test_api_history.rb +27 -0
  8. data/test/tsubaiso_sdk/test_ar_reason_masters.rb +26 -0
  9. data/test/tsubaiso_sdk/test_bank_account.rb +34 -0
  10. data/test/tsubaiso_sdk/test_bank_account_master.rb +119 -0
  11. data/test/tsubaiso_sdk/test_bank_account_transaction.rb +61 -0
  12. data/test/tsubaiso_sdk/test_bank_reason_master.rb +90 -0
  13. data/test/tsubaiso_sdk/test_bonus.rb +26 -0
  14. data/test/tsubaiso_sdk/test_bulk_scheduled_dates.rb +24 -0
  15. data/test/tsubaiso_sdk/test_corporate_master.rb +27 -0
  16. data/test/tsubaiso_sdk/test_customer.rb +71 -0
  17. data/test/tsubaiso_sdk/test_dept.rb +66 -0
  18. data/test/tsubaiso_sdk/test_fixed_assets.rb +18 -0
  19. data/test/tsubaiso_sdk/test_journal.rb +53 -0
  20. data/test/tsubaiso_sdk/test_journal_distribution.rb +29 -0
  21. data/test/tsubaiso_sdk/test_manual_journal.rb +84 -0
  22. data/test/tsubaiso_sdk/test_payrolles.rb +26 -0
  23. data/test/tsubaiso_sdk/test_petty_cash_reason_master.rb +72 -0
  24. data/test/tsubaiso_sdk/test_physical_inventory_master.rb +84 -0
  25. data/test/tsubaiso_sdk/test_purchase.rb +120 -0
  26. data/test/tsubaiso_sdk/test_reimbursement_reason_master.rb +27 -0
  27. data/test/tsubaiso_sdk/test_reimbursements.rb +63 -0
  28. data/test/tsubaiso_sdk/test_reimbursements_transactions.rb +75 -0
  29. data/test/tsubaiso_sdk/test_sale.rb +125 -0
  30. data/test/tsubaiso_sdk/test_scheduled_dates.rb +16 -0
  31. data/test/tsubaiso_sdk/test_staff.rb +26 -0
  32. data/test/tsubaiso_sdk/test_staff_data.rb +71 -0
  33. data/test/tsubaiso_sdk/test_staff_datum_master.rb +37 -0
  34. data/test/tsubaiso_sdk/test_tag.rb +53 -0
  35. data/test/tsubaiso_sdk/test_tax_master.rb +25 -0
  36. metadata +35 -5
  37. data/test/test_tsubaiso_sdk.rb +0 -964
@@ -0,0 +1,196 @@
1
+ require "json"
2
+ require 'webmock'
3
+ require 'active_support'
4
+ require_relative '../../lib/tsubaiso_sdk.rb'
5
+
6
+ include WebMock::API
7
+
8
+ class StubRegister
9
+ include TsubaisoSDK::UrlBuilder
10
+
11
+ def initialize(resource, root_url, token)
12
+ @common_request_headers = {
13
+ 'Accept'=>'*/*',
14
+ 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
15
+ 'Content-Type'=>'application/json',
16
+ 'User-Agent'=>'Ruby'
17
+ }
18
+ @root_url = root_url
19
+ @common_request_headers.merge!( {"Access-Token" => token} )
20
+ @created_records = []
21
+
22
+ stub_create(resource)
23
+ stub_destroy(resource)
24
+ stub_list(resource)
25
+ resource == 'api_histories' ? stub_index(resource) : stub_show(resource)
26
+ stub_balance(resource)
27
+ stub_update(resource)
28
+ stub_find_or_create(resource)
29
+ stub_calc(resource)
30
+ end
31
+
32
+ private
33
+
34
+ def load_json(resource, method, req_or_res = 'request')
35
+ path = "test/stubbings/fixtures/#{resource}_#{method}_#{req_or_res}.json"
36
+ return nil unless File.exist?(path)
37
+ JSON.load(File.read(path))
38
+ end
39
+
40
+ def add_attrs(record, index, resource)
41
+ return_params = record ? record.dup : {}
42
+
43
+ new_attributes = load_json(resource, 'create' ,'response')
44
+ return_params.deep_merge!(new_attributes) if new_attributes
45
+
46
+ return_params.merge!({
47
+ :id => index.to_s,
48
+ :created_at => Time.now.to_s,
49
+ :updated_at => Time.now.to_s
50
+ })
51
+
52
+ return_params['tag_list'] = record['tag_list'].split(',') if record['tag_list']&.kind_of?(String)
53
+ return_params
54
+ end
55
+
56
+ def stub_calc(resource)
57
+ return unless load_json(resource, 'calc')
58
+ stub_requests(:get, url(@root_url, resource, 'calc'), {'scheduled_date': '2019-01-10'}, load_json(resource, 'calc'))
59
+ end
60
+
61
+ def stub_balance(resource)
62
+ if load_json(resource, 'balance')
63
+ expect_param = load_json(resource, 'balance')
64
+ return_body = load_json(resource, 'balance', 'response')
65
+ stub_requests(:get, url(@root_url, resource, 'balance'), return_body, expect_param)
66
+ stub_requests(:get, url(@root_url, resource, 'balance'), return_body, expect_param.merge({customer_master_id: 101})) { |record| record['customer_master_code'] == '101'}
67
+ end
68
+ end
69
+
70
+ def stub_find_or_create(resource)
71
+ # NOTE: This stub support ar_receipts, ap_payments
72
+ if load_json(resource, 'find_or_create')
73
+ expected_param = load_json(resource, 'find_or_create')
74
+ return_body = add_attrs(expected_param, 99, resource)
75
+ stub_requests(:post, url(@root_url, resource, 'find_or_create'), return_body, expected_param)
76
+ @created_records << return_body
77
+ end
78
+ end
79
+
80
+ def stub_update(resource)
81
+ if load_json(resource, 'update')
82
+ param = load_json(resource, 'update')
83
+ stub_requests(:post, url(@root_url, resource, 'update') + '/0', @created_records[0].merge(param), param)
84
+ end
85
+ end
86
+
87
+ def stub_show(resource)
88
+ @created_records.each do |record|
89
+ stub_requests(:get, url(@root_url, resource, "show") + '/' + record[:id], record) unless resource == 'journals' || resource == 'corporate_masters'
90
+
91
+ case resource
92
+ when 'customer_masters', 'staff_datum_masters'
93
+ # NOTE: Serch by Code (support customer_master_show & staff_datum_master_show & corporate_masters)
94
+ stub_requests(:get, url(@root_url, resource, 'show'), record, { code: record['code'] })
95
+ when 'staff_data'
96
+ # NOTE: Serch by code and staff_id (support staff_data)
97
+ expected_body = {
98
+ staff_id: record['staff_id'],
99
+ code: record['code'],
100
+ time: record['start_timestamp']
101
+ }
102
+ stub_requests(:get, url(@root_url, resource, 'show'), record, expected_body)
103
+ when 'corporate_masters'
104
+ stub_requests(:get, url(@root_url, resource, 'show') + '/' + record[:id], record, { ccode: record['corporate_code'] })
105
+ stub_requests(:get, url(@root_url, resource, 'show') + '/' + record[:id], record, { ccode: nil })
106
+ stub_requests(:get, url(@root_url, resource, 'show'), record, { ccode: record['corporate_code'] })
107
+ when 'journals'
108
+ stub_requests(:get, url(@root_url, resource, 'show') + '/' + record[:id], { 'record': record })
109
+ end
110
+ end
111
+ end
112
+
113
+ def stub_requests(http_method, url, created_records, expected_body = {}, &condition)
114
+ response_body = condition ? created_records.select(&condition) : created_records
115
+
116
+ stub_request(http_method, url)
117
+ .with(
118
+ { headers: @common_request_headers }.merge({ body: expected_body.merge(format: 'json') })
119
+ )
120
+ .to_return(
121
+ { status: 200 }.merge( { body: response_body.to_json } )
122
+ )
123
+ end
124
+
125
+ def stub_index(resource)
126
+ # NOTE: for api_history
127
+ stub_requests(:get, url(@root_url, resource, 'index'), load_json(resource, 'index', 'response'))
128
+ end
129
+
130
+ def stub_list(resource)
131
+ if @created_records.size == 0
132
+ # This conditions is for modules which support only list & show.
133
+ load_json(resource,'list','response')&.each_with_index do |record, i|
134
+ @created_records << add_attrs(record, i, resource)
135
+ end
136
+ end
137
+
138
+ case resource
139
+ when 'bank_accounts'
140
+ stub_requests(:get, url(@root_url, resource, 'list', 2016, 8), @created_records)
141
+ when 'manual_journals'
142
+ stub_requests(:get, url(@root_url, resource, 'list', 2016, 4), @created_records)
143
+ when 'payrolls'
144
+ stub_requests(:get, url(@root_url, resource, 'list', 2017, 2), @created_records)
145
+ when 'ar'
146
+ stub_requests(:get, url(@root_url, resource, 'list', 2016, 8), @created_records){ |record| record['realization_timestamp'] =~ /2016-08-\d{2}/}
147
+ when 'ap_payments'
148
+ stub_requests(:get, url(@root_url, resource, 'list', 2016, 8), @created_records){ |record| record['accrual_timestamp'] =~ /2016-08-\d{2}/}
149
+ when 'staff_data'
150
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records, { staff_id: 300 })
151
+ when 'bank_account_transactions'
152
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records, { bank_account_id: 0})
153
+ when 'reimbursements'
154
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records, { year: 2016, month: 3})
155
+ when 'api_histories'
156
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records, { year: 2019, month: 12}){ |record| record['access_timestamp'] =~ /2019\/12\/\d{2}/}
157
+ when 'reimbursement_transactions'
158
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records, { id: 300 }) { |record| record['reimbursement_id'] == 300 }
159
+ when 'tags'
160
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records.group_by{ |record| record['tag_group_code'] })
161
+ when 'bonuses'
162
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records, { target_year: 2016, bonus_no: 1 })
163
+ when 'journals'
164
+ stub_requests(:get, url(@root_url, resource, 'list'), {'records': @created_records}, { 'start_date': '2019-12-01', 'finish_date': '2019-12-31'} )
165
+ stub_requests(:get, url(@root_url, resource, 'list'), {'records': @created_records}, { 'price_min': 10800, 'price_max': 10800} )
166
+ stub_requests(:get, url(@root_url, resource, 'list'), {'records': @created_records}, { 'dept_code': 'SETSURITSU' } )
167
+ else
168
+ stub_requests(:get, url(@root_url, resource, 'list'), @created_records)
169
+ end
170
+ end
171
+
172
+ def stub_destroy(resource)
173
+ @created_records.each_with_index do |record, index|
174
+ stub_request(:post, url(@root_url, resource, 'destroy') + "/" + record[:id])
175
+ .with(
176
+ headers: @common_request_headers
177
+ )
178
+ .to_return(
179
+ status: 204
180
+ )
181
+ end
182
+ end
183
+
184
+ def stub_create(resource)
185
+ load_json(resource, 'create')&.each_with_index do |record, i|
186
+ if resource == 'journal_distributions'
187
+ return_body = add_attrs({}, i, resource)
188
+ else
189
+ return_body = add_attrs(record, i, resource)
190
+ end
191
+ stub_requests(:post, url(@root_url, resource, 'create'), return_body, record)
192
+ @created_records << return_body
193
+ end
194
+ end
195
+ end
196
+
@@ -0,0 +1,23 @@
1
+ module CommonSetupAndTeardown
2
+ require 'time'
3
+ require_relative '../../lib/tsubaiso_sdk'
4
+ require_relative '../stubbings/stub_register.rb'
5
+
6
+ include WebMock::API
7
+
8
+ def setup(resouce)
9
+ WebMock.enable!
10
+ WebMock.disable_net_connect!
11
+ @api = TsubaisoSDK.new({ base_url: ENV['SDK_BASE_URL'], access_token: ENV['SDK_ACCESS_TOKEN'] })
12
+ StubRegister.new(
13
+ resouce,
14
+ @api.instance_variable_get(:@base_url),
15
+ @api.instance_variable_get(:@access_token)
16
+ )
17
+ end
18
+
19
+ def teardown
20
+ WebMock.disable!
21
+ end
22
+
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'minitest/autorun'
2
+ require_relative './common_setup_and_teardown.rb'
3
+
4
+ class ApReasonMasterTest < Minitest::Test
5
+ include CommonSetupAndTeardown
6
+
7
+ def setup
8
+ super("ap_reason_masters")
9
+ end
10
+
11
+ def test_show_ap_reason_master
12
+ ap_reason_masters = @api.list_ap_reason_masters
13
+ first_ap_reason_master = ap_reason_masters[:json].first
14
+ ap_reason_master = @api.show_ap_reason_master(first_ap_reason_master[:id])
15
+
16
+ assert_equal 200, ap_reason_master[:status].to_i, ap_reason_master.inspect
17
+ assert_equal first_ap_reason_master[:reason_code], ap_reason_master[:json][:reason_code]
18
+ end
19
+
20
+ def test_list_ap_reason_masters
21
+ ap_reason_masters_list = @api.list_ap_reason_masters
22
+ assert_equal 200, ap_reason_masters_list[:status].to_i, ap_reason_masters_list.inspect
23
+ assert ap_reason_masters_list[:json]
24
+ assert !ap_reason_masters_list[:json].empty?
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require 'minitest/autorun'
2
+ require_relative './common_setup_and_teardown.rb'
3
+
4
+ class ApiHistoryTest < Minitest::Test
5
+ include CommonSetupAndTeardown
6
+
7
+ def setup
8
+ super("api_histories")
9
+ end
10
+
11
+ def test_index_api_history
12
+ index = @api.index_api_history
13
+ assert_equal 200, index[:status].to_i, index.inspect
14
+ assert !index[:json].empty?
15
+ end
16
+
17
+ def test_list_api_history
18
+ options = {
19
+ month: 12,
20
+ year: 2019
21
+ }
22
+ list = @api.list_api_history(options)
23
+ assert_equal 200, list[:status].to_i, list.inspect
24
+ assert_equal list[:json].first[:controller], 'reimbursements'
25
+ assert_equal list[:json].first[:method], 'create'
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'minitest/autorun'
2
+ require_relative './common_setup_and_teardown.rb'
3
+
4
+ class ArReasonMasterTest < Minitest::Test
5
+ include CommonSetupAndTeardown
6
+
7
+ def setup
8
+ super("ar_reason_masters")
9
+ end
10
+
11
+ def test_list_ar_reason_masters
12
+ ar_reason_masters_list = @api.list_ar_reason_masters
13
+ assert_equal 200, ar_reason_masters_list[:status].to_i, ar_reason_masters_list.inspect
14
+ assert ar_reason_masters_list[:json]
15
+ assert !ar_reason_masters_list[:json].empty?
16
+ end
17
+
18
+ def test_show_ar_reason_master
19
+ ar_reason_masters = @api.list_ar_reason_masters
20
+ ar_reason_master_id = ar_reason_masters[:json].first[:id]
21
+ ar_reason_master = @api.show_ar_reason_master(ar_reason_master_id)
22
+
23
+ assert_equal 200, ar_reason_master[:status].to_i, ar_reason_master.inspect
24
+ assert_equal ar_reason_master[:json][:id], ar_reason_master_id
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+ require_relative './common_setup_and_teardown.rb'
3
+
4
+ class BankAccountTest < Minitest::Test
5
+ include CommonSetupAndTeardown
6
+
7
+ def setup
8
+ super("bank_accounts")
9
+ end
10
+
11
+ def test_create_bank_account
12
+ options = {
13
+ bank_account_master_id: "1",
14
+ start_timestamp: "2016-07-30",
15
+ finish_timestamp: "2016-08-30",
16
+ }
17
+ new_bank_account = @api.create_bank_account(options)
18
+
19
+ assert_equal 200, new_bank_account[:status].to_i, new_bank_account.inspect
20
+ serch_options = {
21
+ year: 2016,
22
+ month: 8
23
+ }
24
+ listed_bank_accounts = @api.list_bank_account(serch_options)
25
+ assert_equal 200, listed_bank_accounts[:status].to_i, listed_bank_accounts.inspect
26
+ target_bank_account = listed_bank_accounts[:json].find{ |bank_account| bank_account[:id] == new_bank_account[:json][:id]}
27
+
28
+ assert_equal Time.parse(options[:start_timestamp]), Time.parse(target_bank_account[:start_timestamp])
29
+ assert_equal Time.parse(options[:finish_timestamp]), Time.parse(target_bank_account[:finish_timestamp])
30
+ assert_equal options[:bank_account_master_id], target_bank_account[:bank_account_master_id]
31
+ end
32
+
33
+ end
34
+
@@ -0,0 +1,119 @@
1
+ require 'minitest/autorun'
2
+ require_relative './common_setup_and_teardown.rb'
3
+
4
+ class BankAccountMasterTest < Minitest::Test
5
+ include CommonSetupAndTeardown
6
+
7
+ def setup
8
+ @bank_account_master_1 = {
9
+ name: "ANZ Bank",
10
+ account_type: "1",
11
+ account_number: "66667777",
12
+ nominee: "tsubaiso taro",
13
+ memo: "",
14
+ start_ymd: "2019-06-01",
15
+ finish_ymd: nil,
16
+ zengin_bank_code: "7777",
17
+ zengin_branch_code: "777",
18
+ zengin_client_code_sogo: "9999999999",
19
+ currency_code: "",
20
+ currency_rate_master_code: nil
21
+ }
22
+
23
+ @bank_account_master_2 = {
24
+ name: "NSW Bank",
25
+ account_type: "1",
26
+ account_number: "66665555",
27
+ nominee: "tsubaiso jiro",
28
+ memo: "",
29
+ start_ymd: "2019-06-02",
30
+ finish_ymd: nil,
31
+ zengin_bank_code: "8888",
32
+ zengin_branch_code: "777",
33
+ zengin_client_code_sogo: "8888888888",
34
+ currency_code: "",
35
+ currency_rate_master_code: nil
36
+ }
37
+
38
+ @bank_account_master_3 = {
39
+ name: "Bank of Melbourne",
40
+ account_type: "1",
41
+ account_number: "66664444",
42
+ nominee: "tsubaiso saburo",
43
+ memo: "",
44
+ start_ymd: "2019-06-03",
45
+ finish_ymd: nil,
46
+ zengin_bank_code: "9999",
47
+ zengin_branch_code: "999",
48
+ zengin_client_code_sogo: "7777777777",
49
+ currency_code: "",
50
+ currency_rate_master_code: nil
51
+ }
52
+ super("bank_account_masters")
53
+ end
54
+
55
+ def test_create_bank_account_master
56
+ created_bank_account_master = @api.create_bank_account_master(@bank_account_master_1)
57
+
58
+ assert_equal 200, created_bank_account_master[:status].to_i, created_bank_account_master.inspect
59
+ assert_equal @bank_account_master_1[:name], created_bank_account_master[:json][:name]
60
+ assert_equal @bank_account_master_1[:account_number], created_bank_account_master[:json][:account_number]
61
+ assert_equal @bank_account_master_1[:zengin_bank_code], created_bank_account_master[:json][:zengin_bank_code]
62
+ assert_equal @bank_account_master_1[:zengin_branch_code], created_bank_account_master[:json][:zengin_branch_code]
63
+ end
64
+
65
+ def test_show_bank_account_master
66
+ created_bank_account_master = @api.create_bank_account_master(@bank_account_master_1)
67
+ shown_bank_account_master = @api.show_bank_account_master(created_bank_account_master[:json][:id])
68
+
69
+ assert_equal @bank_account_master_1[:nominee], shown_bank_account_master[:json][:nominee]
70
+ assert_equal @bank_account_master_1[:name], shown_bank_account_master[:json][:name]
71
+ assert_equal @bank_account_master_1[:account_number], shown_bank_account_master[:json][:account_number]
72
+ end
73
+
74
+ def test_list_bank_account_masters
75
+ created_bank_account_master_1 = @api.create_bank_account_master(@bank_account_master_1)
76
+ created_bank_account_master_2 = @api.create_bank_account_master(@bank_account_master_2)
77
+ created_bank_account_master_3 = @api.create_bank_account_master(@bank_account_master_3)
78
+
79
+ assert_equal 200, created_bank_account_master_1[:status].to_i
80
+ assert_equal 200, created_bank_account_master_2[:status].to_i
81
+ assert_equal 200, created_bank_account_master_3[:status].to_i
82
+
83
+ created_master_id_1 = created_bank_account_master_1[:json][:id]
84
+ created_master_id_2 = created_bank_account_master_2[:json][:id]
85
+ created_master_id_3 = created_bank_account_master_3[:json][:id]
86
+
87
+ bank_account_master_list = @api.list_bank_account_masters
88
+ assert_equal 200, bank_account_master_list[:status].to_i, bank_account_master_list.inspect
89
+ assert(bank_account_master_list[:json].any? { |x| x[:id] == created_master_id_1 })
90
+ assert(bank_account_master_list[:json].any? { |x| x[:id] == created_master_id_2 })
91
+ assert(bank_account_master_list[:json].any? { |x| x[:id] == created_master_id_3 })
92
+ end
93
+
94
+ def test_update_bank_account_master
95
+ created_bank_account_master = @api.create_bank_account_master(@bank_account_master_1)
96
+ assert_equal 200, created_bank_account_master[:status].to_i
97
+
98
+ updating_options = {
99
+ id: created_bank_account_master[:json][:id],
100
+ name: "Westpac",
101
+ account_type: "3",
102
+ nominee: "Hatagaya Taro",
103
+ memo: "This is updatting test"
104
+ }
105
+
106
+ updated_bank_account_master = @api.update_bank_account_master(updating_options)
107
+ assert_equal 200, updated_bank_account_master[:status].to_i
108
+ assert_equal updating_options[:name], updated_bank_account_master[:json][:name]
109
+ assert_equal updating_options[:memo], updated_bank_account_master[:json][:memo]
110
+ assert_equal updating_options[:nominee], updated_bank_account_master[:json][:nominee]
111
+ assert_equal updating_options[:account_type], updated_bank_account_master[:json][:account_type]
112
+
113
+ assert_equal @bank_account_master_1[:account_number], updated_bank_account_master[:json][:account_number]
114
+ assert_equal @bank_account_master_1[:zengin_bank_code], updated_bank_account_master[:json][:zengin_bank_code]
115
+ assert_equal @bank_account_master_1[:zengin_branch_code], updated_bank_account_master[:json][:zengin_branch_code]
116
+ end
117
+
118
+ end
119
+