Skip to content

Commit 494dd9c

Browse files
committed
Specテストの追加
1 parent 2d02d0d commit 494dd9c

File tree

12 files changed

+521
-19
lines changed

12 files changed

+521
-19
lines changed

Gemfile.lock

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
PATH
22
remote: .
33
specs:
4-
freee-api (0.0.4)
4+
freee-api (0.0.5)
55
faraday (~> 0.12.2)
66
faraday_middleware (~> 0.12.2)
77
oauth2 (~> 1.4.0)
88

99
GEM
1010
remote: https://rubygems.org/
1111
specs:
12+
addressable (2.5.2)
13+
public_suffix (>= 2.0.2, < 4.0)
1214
ast (2.4.0)
1315
byebug (10.0.2)
1416
coderay (1.1.2)
17+
crack (0.4.3)
18+
safe_yaml (~> 1.0.0)
1519
diff-lcs (1.3)
1620
faraday (0.12.2)
1721
multipart-post (>= 1.2, < 3)
1822
faraday_middleware (0.12.2)
1923
faraday (>= 0.7.4, < 1.0)
24+
hashdiff (0.3.7)
2025
jaro_winkler (1.5.1)
2126
jwt (1.5.6)
2227
method_source (0.9.0)
@@ -39,33 +44,39 @@ GEM
3944
pry-byebug (3.6.0)
4045
byebug (~> 10.0)
4146
pry (~> 0.10)
47+
public_suffix (3.0.3)
4248
rack (2.0.5)
4349
rainbow (3.0.0)
4450
rake (10.5.0)
45-
rspec (3.7.0)
46-
rspec-core (~> 3.7.0)
47-
rspec-expectations (~> 3.7.0)
48-
rspec-mocks (~> 3.7.0)
49-
rspec-core (3.7.1)
50-
rspec-support (~> 3.7.0)
51-
rspec-expectations (3.7.0)
51+
rspec (3.8.0)
52+
rspec-core (~> 3.8.0)
53+
rspec-expectations (~> 3.8.0)
54+
rspec-mocks (~> 3.8.0)
55+
rspec-core (3.8.0)
56+
rspec-support (~> 3.8.0)
57+
rspec-expectations (3.8.1)
5258
diff-lcs (>= 1.2.0, < 2.0)
53-
rspec-support (~> 3.7.0)
54-
rspec-mocks (3.7.0)
59+
rspec-support (~> 3.8.0)
60+
rspec-mocks (3.8.0)
5561
diff-lcs (>= 1.2.0, < 2.0)
56-
rspec-support (~> 3.7.0)
57-
rspec-support (3.7.1)
58-
rubocop (0.58.1)
62+
rspec-support (~> 3.8.0)
63+
rspec-support (3.8.0)
64+
rubocop (0.58.2)
5965
jaro_winkler (~> 1.5.1)
6066
parallel (~> 1.10)
6167
parser (>= 2.5, != 2.5.1.1)
6268
powerpack (~> 0.1)
6369
rainbow (>= 2.2.2, < 4.0)
6470
ruby-progressbar (~> 1.7)
6571
unicode-display_width (~> 1.0, >= 1.0.1)
66-
ruby-progressbar (1.9.0)
72+
ruby-progressbar (1.10.0)
73+
safe_yaml (1.0.4)
6774
unicode-display_width (1.4.0)
68-
yard (0.9.15)
75+
webmock (3.4.2)
76+
addressable (>= 2.3.6)
77+
crack (>= 0.3.2)
78+
hashdiff
79+
yard (0.9.16)
6980

7081
PLATFORMS
7182
ruby
@@ -77,6 +88,7 @@ DEPENDENCIES
7788
rake (~> 10.0)
7889
rspec (~> 3.0)
7990
rubocop (~> 0.58.1)
91+
webmock (~> 3.4.2)
8092
yard (~> 0.9.15)
8193

8294
BUNDLED WITH

freee-api.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
2828
spec.add_development_dependency 'pry-byebug', '~> 3.6.0'
2929
spec.add_development_dependency 'rubocop', '~> 0.58.1'
3030
spec.add_development_dependency 'yard', '~> 0.9.15'
31+
spec.add_development_dependency 'webmock', '~> 3.4.2'
3132

3233
spec.add_dependency 'oauth2', '~> 1.4.0'
3334
spec.add_dependency 'faraday', '~> 0.12.2'

lib/freee/api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Freee
44
module Api
5-
VERSION = '0.0.4'
5+
VERSION = '0.0.5'
66
end
77
end

lib/freee/deals/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def create_deal(access_token, params)
3737
when 401
3838
raise 'Unauthorized'
3939
end
40+
response
4041
end
4142
end
4243
end

lib/freee/partners/client.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def create_partner(access_token, params)
5050
when 401
5151
raise 'Unauthorized'
5252
end
53+
response
5354
end
5455

5556
# 取引先の更新
@@ -71,6 +72,7 @@ def update_partner(access_token, params)
7172
when 401
7273
raise 'Unauthorized'
7374
end
75+
response
7476
end
7577
end
7678
end

spec/freee/account_items_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Freee::Api::AccountItems do
4+
subject do
5+
described_class.new
6+
end
7+
8+
describe '#get_account_items' do
9+
context '勘定科目一覧の取得' do
10+
before do
11+
WebMock.stub_request(:get, 'https://api.freee.co.jp/api/1/account_items').to_return(
12+
body: JSON.generate(
13+
account_items: [
14+
{
15+
id: 101,
16+
name: 'ソフトウェア',
17+
shortcut: 'SOFUTO',
18+
shortcut_num: '123',
19+
default_tax_id: 12,
20+
default_tax_code: 108,
21+
categories: %w[資産 固定資産 無形固定資産]
22+
}
23+
]
24+
),
25+
status: 200,
26+
headers: { 'Content-Type' => 'application/json' }
27+
)
28+
end
29+
it '200' do
30+
params = { company_id: 1 }
31+
response = subject.get_account_items('access_token', params)
32+
expect(response.body['account_items'][0]['id']).to eq 101
33+
expect(response.body['account_items'][0]['name']).to eq 'ソフトウェア'
34+
expect(response.body['account_items'][0]['shortcut']).to eq 'SOFUTO'
35+
expect(response.body['account_items'][0]['shortcut_num']).to eq '123'
36+
expect(response.body['account_items'][0]['default_tax_id']).to eq 12
37+
expect(response.body['account_items'][0]['default_tax_code']).to eq 108
38+
expect(response.body['account_items'][0]['categories']).to include('資産', '固定資産', '無形固定資産')
39+
end
40+
it '必要なパラメータが不足' do
41+
params = { company_id_dummy: 1 }
42+
expect { subject.get_account_items('', params) }.to raise_error(RuntimeError, 'アクセストークンが設定されていません')
43+
expect { subject.get_account_items('access_token', params) }.to raise_error(RuntimeError, '事業所IDが設定されていません')
44+
end
45+
end
46+
end
47+
end

spec/freee/deals_spec.rb

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe Freee::Api::Deals do
4+
subject do
5+
described_class.new
6+
end
7+
8+
describe '#create_deal' do
9+
context '取引(収入/支出)の作成' do
10+
before do
11+
WebMock.stub_request(:post, 'https://api.freee.co.jp/api/1/deals').to_return(
12+
body: JSON.generate(
13+
deal: [
14+
{
15+
id: 101,
16+
company_id: 1,
17+
issue_date: '2013-01-01',
18+
due_date: '2013-02-28',
19+
amount: 5250,
20+
due_amount: 0,
21+
type: 'expense',
22+
partner_id: 201,
23+
ref_number: '123-456',
24+
details: [
25+
{
26+
account_item_id: 803,
27+
tax_code: 6,
28+
item_id: 501,
29+
section_id: 1,
30+
tag_ids: [1, 2, 3],
31+
amount: 5250,
32+
vat: 250,
33+
description: '備考'
34+
}
35+
],
36+
paymenrs: [
37+
{
38+
date: '2013-01-28',
39+
from_walletable_type: 'bank_account',
40+
from_walletable_id: 103,
41+
amount: 5250
42+
}
43+
]
44+
}
45+
]
46+
),
47+
status: 200,
48+
headers: { 'Content-Type' => 'application/json' }
49+
)
50+
end
51+
it '200' do
52+
params = {
53+
company_id: 1,
54+
issue_date: '2013-01-01',
55+
due_date: '2013-02-28',
56+
type: 'expense',
57+
partner_id: 201,
58+
ref_number: '123-456',
59+
details: [
60+
{
61+
account_item_id: 803,
62+
tax_code: 6,
63+
item_id: 501,
64+
section_id: 1,
65+
tag_ids: [1, 2, 3],
66+
amount: 5250,
67+
description: '備考'
68+
}
69+
],
70+
paymenrs: [
71+
{
72+
date: '2013-01-28',
73+
from_walletable_type: 'bank_account',
74+
from_walletable_id: 103,
75+
amount: 5250
76+
}
77+
]
78+
}
79+
response = subject.create_deal('access_token', params)
80+
expect(response.body['deal'][0]['id']).to eq 101
81+
expect(response.body['deal'][0]['company_id']).to eq 1
82+
expect(response.body['deal'][0]['issue_date']).to eq '2013-01-01'
83+
end
84+
it '必要なパラメータが不足' do
85+
params = { issue_date: '2013-01-01', type: 'expense', company_id: 1 }
86+
non_issue_params = { issue_date_dummy: 1 }
87+
non_type_params = { issue_date: '2013-01-01' }
88+
non_company_params = { issue_date: '2013-01-01', type: 'expense' }
89+
expect { subject.create_deal('', params) }.to raise_error(RuntimeError, 'アクセストークンが設定されていません')
90+
expect { subject.create_deal('access_token', non_issue_params) }.to raise_error(RuntimeError, '収入・支出の発生日が指定されていません')
91+
expect { subject.create_deal('access_token', non_type_params) }.to raise_error(RuntimeError, '収支区分が指定されていません')
92+
expect { subject.create_deal('access_token', non_company_params) }.to raise_error(RuntimeError, '事業所IDが設定されていません')
93+
end
94+
end
95+
end
96+
end

0 commit comments

Comments
 (0)