freee 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +25 -1
- data/freee.gemspec +2 -0
- data/lib/freee/{account.rb → account_item.rb} +3 -3
- data/lib/freee/base.rb +13 -2
- data/lib/freee/company.rb +4 -0
- data/lib/freee/deal.rb +4 -2
- data/lib/freee/item.rb +4 -2
- data/lib/freee/obj/account_item.rb +5 -0
- data/lib/freee/obj/response.rb +1 -1
- data/lib/freee/obj/{account.rb → section.rb} +1 -1
- data/lib/freee/obj/{wallet.rb → tag.rb} +1 -1
- data/lib/freee/obj/{amount.rb → wallet_txn.rb} +1 -1
- data/lib/freee/partner.rb +4 -2
- data/lib/freee/section.rb +15 -0
- data/lib/freee/tag.rb +15 -0
- data/lib/freee/tax.rb +2 -2
- data/lib/freee/transfer.rb +4 -2
- data/lib/freee/version.rb +1 -1
- data/lib/freee/{wallet.rb → wallet_txn.rb} +5 -4
- data/lib/freee/walletable.rb +6 -0
- data/spec/account_item_spec.rb +44 -0
- data/spec/base_spec.rb +3 -9
- data/spec/company_spec.rb +53 -36
- data/spec/deal_spec.rb +150 -93
- data/spec/fixtures/account_items.json +20 -0
- data/spec/fixtures/companies.json +11 -0
- data/spec/fixtures/company.json +13 -0
- data/spec/fixtures/create_deal.json +1 -0
- data/spec/fixtures/create_item.json +6 -0
- data/spec/fixtures/create_partner.json +1 -0
- data/spec/fixtures/create_section.json +1 -0
- data/spec/fixtures/create_tag.json +1 -0
- data/spec/fixtures/create_transfer.json +1 -0
- data/spec/fixtures/create_wallet_txn.json +11 -0
- data/spec/fixtures/create_walletable.json +1 -0
- data/spec/fixtures/deal.json +34 -0
- data/spec/fixtures/deals.json +36 -0
- data/spec/fixtures/item.json +9 -0
- data/spec/fixtures/items.json +11 -0
- data/spec/fixtures/partner.json +9 -0
- data/spec/fixtures/partners.json +11 -0
- data/spec/fixtures/section.json +9 -0
- data/spec/fixtures/sections.json +11 -0
- data/spec/fixtures/tag.json +9 -0
- data/spec/fixtures/tags.json +11 -0
- data/spec/fixtures/taxes.json +8 -0
- data/spec/fixtures/taxes_with_code.json +9 -0
- data/spec/fixtures/transfer.json +13 -0
- data/spec/fixtures/transfers.json +37 -0
- data/spec/fixtures/user.json +10 -0
- data/spec/fixtures/user_with_companies.json +19 -0
- data/spec/fixtures/wallet_txn.json +14 -0
- data/spec/fixtures/wallet_txns.json +16 -0
- data/spec/fixtures/walletable.json +1 -0
- data/spec/fixtures/walletables.json +9 -0
- data/spec/item_spec.rb +74 -21
- data/spec/partner_spec.rb +59 -21
- data/spec/section_spec.rb +68 -0
- data/spec/setenv_spec.rb +0 -4
- data/spec/spec_helper.rb +41 -3
- data/spec/tag_spec.rb +68 -0
- data/spec/tax_spec.rb +63 -22
- data/spec/transfer_spec.rb +89 -34
- data/spec/user_spec.rb +47 -20
- data/spec/util_spec.rb +19 -10
- data/spec/wallet_txn_spec.rb +88 -0
- data/spec/walletable_spec.rb +74 -24
- metadata +109 -15
- data/lib/freee/amount.rb +0 -7
- data/spec/account_spec.rb +0 -34
- data/spec/amount_spec.rb +0 -26
- data/spec/wallet_spec.rb +0 -89
data/spec/deal_spec.rb
CHANGED
@@ -1,108 +1,165 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Freee::Deal do
|
4
|
-
let(:client_id) { get_client_id }
|
5
|
-
let(:secret_key) { get_secret_key }
|
6
|
-
let(:token) { get_token }
|
7
|
-
let(:company_id) { get_company_id }
|
8
|
-
let(:deal) { Freee::Deal }
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
Freee::Base.config(client_id, secret_key, token)
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'should can be able to create instance' do
|
15
|
-
subject { deal.list(company_id) }
|
16
|
-
it { is_expected.not_to be_nil }
|
17
|
-
it { is_expected.to be_instance_of(Freee::Response::Deal) }
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'should get deals for the company' do
|
21
|
-
subject { deal.list(company_id) }
|
22
|
-
|
23
|
-
it { is_expected.to include('deals') }
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'should get deal of first for the company' do
|
27
|
-
subject { deal.list(company_id)['deals'].first }
|
28
|
-
|
29
|
-
it { is_expected.not_to be_nil }
|
30
|
-
it { is_expected.to include('id') }
|
31
|
-
it { is_expected.to include('company_id') }
|
32
|
-
it { is_expected.to include('issue_date') }
|
33
|
-
it { is_expected.to include('due_date') }
|
34
|
-
it { is_expected.to include('amount') }
|
35
|
-
it { is_expected.to include('due_amount') }
|
36
|
-
it { is_expected.to include('type') }
|
37
|
-
it { is_expected.to include('partner_id') }
|
38
|
-
it { is_expected.to include('details') }
|
39
|
-
it { is_expected.to include('payments') }
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'should get details from deals for the company' do
|
43
|
-
subject { deal.list(company_id)['deals'].first['details'].first }
|
44
|
-
|
45
|
-
it { is_expected.not_to be_nil }
|
46
|
-
it { is_expected.to include('account_item_id') }
|
47
|
-
it { is_expected.to include('tax_id') }
|
48
|
-
it { is_expected.to include('item_id') }
|
49
|
-
it { is_expected.to include('amount') }
|
50
|
-
it { is_expected.to include('description') }
|
51
|
-
end
|
52
4
|
|
53
|
-
|
54
|
-
|
5
|
+
let(:company_id) { -1 }
|
6
|
+
let(:params) { fixture('create_deal.json') }
|
7
|
+
let(:json) { { params: params } }
|
55
8
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
it { is_expected.to include('from_walletable_id') }
|
60
|
-
it { is_expected.to include('amount') }
|
9
|
+
before do
|
10
|
+
Freee::Base.config(get_client_id, get_secret_key, get_token)
|
11
|
+
@client = Freee::Deal
|
61
12
|
end
|
62
13
|
|
63
|
-
describe '
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
14
|
+
describe 'deal' do
|
15
|
+
context '#list' do
|
16
|
+
before do
|
17
|
+
stub_get('/api/1/deals?company_id=-1').to_return(body: fixture('deals.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
18
|
+
@responses = @client.list(company_id)
|
19
|
+
end
|
20
|
+
after { WebMock.reset! }
|
21
|
+
|
22
|
+
it 'requests the correct resource' do
|
23
|
+
assert_request_requested a_get('/api/1/deals?company_id=-1')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should can be able to create instance' do
|
27
|
+
expect(@responses).to include('deals')
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'should get deal of first for the company' do
|
31
|
+
subject { @responses['deals'].first }
|
32
|
+
|
33
|
+
it { is_expected.not_to be_nil }
|
34
|
+
it { is_expected.to include('id') }
|
35
|
+
it { is_expected.to include('company_id') }
|
36
|
+
it { is_expected.to include('issue_date') }
|
37
|
+
it { is_expected.to include('due_date') }
|
38
|
+
it { is_expected.to include('amount') }
|
39
|
+
it { is_expected.to include('due_amount') }
|
40
|
+
it { is_expected.to include('type') }
|
41
|
+
it { is_expected.to include('partner_id') }
|
42
|
+
it { is_expected.to include('details') }
|
43
|
+
it { is_expected.to include('payments') }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'should get details from deals for the company' do
|
47
|
+
subject { @responses['deals'].first['details'].first }
|
48
|
+
|
49
|
+
it { is_expected.not_to be_nil }
|
50
|
+
it { is_expected.to include('account_item_id') }
|
51
|
+
it { is_expected.to include('tax_id') }
|
52
|
+
it { is_expected.to include('item_id') }
|
53
|
+
it { is_expected.to include('amount') }
|
54
|
+
it { is_expected.to include('description') }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe 'should get payments from deals for the company' do
|
58
|
+
subject { @responses['deals'].first['payments'].first }
|
59
|
+
|
60
|
+
it { is_expected.not_to be_nil }
|
61
|
+
it { is_expected.to include('date') }
|
62
|
+
it { is_expected.to include('from_walletable_type') }
|
63
|
+
it { is_expected.to include('from_walletable_id') }
|
64
|
+
it { is_expected.to include('amount') }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'should can be able to create instance' do
|
68
|
+
subject { @responses }
|
69
|
+
it { is_expected.to be_instance_of(Freee::Response::Deal) }
|
70
|
+
end
|
74
71
|
end
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
73
|
+
context '#list_income' do
|
74
|
+
before do
|
75
|
+
stub_get('/api/1/deals?company_id=-1&type=income').to_return(body: fixture('deals.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
76
|
+
@responses = @client.list_income(company_id)
|
77
|
+
end
|
78
|
+
after { WebMock.reset! }
|
79
|
+
|
80
|
+
it 'requests the correct resource' do
|
81
|
+
assert_request_requested a_get('/api/1/deals?company_id=-1&type=income')
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should can be able to create instance' do
|
85
|
+
expect(@responses).to include('deals')
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'should can be able to create instance' do
|
89
|
+
subject { @responses }
|
90
|
+
it { is_expected.to be_instance_of(Freee::Response::Deal) }
|
91
|
+
end
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
94
|
+
context '#list_expense' do
|
95
|
+
before do
|
96
|
+
stub_get('/api/1/deals?company_id=-1&type=expense').to_return(body: fixture('deals.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
97
|
+
@responses = @client.list_expense(company_id)
|
98
|
+
end
|
99
|
+
after { WebMock.reset! }
|
100
|
+
|
101
|
+
it 'requests the correct resource' do
|
102
|
+
assert_request_requested a_get('/api/1/deals?company_id=-1&type=expense')
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should can be able to create instance' do
|
106
|
+
expect(@responses).to include('deals')
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'should can be able to create instance' do
|
110
|
+
subject { @responses }
|
111
|
+
it { is_expected.to be_instance_of(Freee::Response::Deal) }
|
112
|
+
end
|
103
113
|
end
|
104
114
|
|
105
|
-
|
106
|
-
|
115
|
+
context '#create' do
|
116
|
+
before do
|
117
|
+
stub_post('/api/1/deals').
|
118
|
+
with(body: json).
|
119
|
+
to_return(body: fixture('deal.json'), headers: {content_type: 'application/json; charset=utf-8'} )
|
120
|
+
@responses = @client.create(params)
|
121
|
+
end
|
122
|
+
after { WebMock.reset! }
|
123
|
+
|
124
|
+
it 'requests the correct resource' do
|
125
|
+
assert_request_requested a_post('/api/1/deals').with(body: json)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should can be able to create instance' do
|
129
|
+
expect(@responses).to include('deal')
|
130
|
+
end
|
131
|
+
|
132
|
+
describe 'should can be able to create instance' do
|
133
|
+
subject { @responses }
|
134
|
+
it { is_expected.to be_instance_of(Freee::Response::Deal) }
|
135
|
+
end
|
136
|
+
|
137
|
+
describe 'should get deal of first for the company' do
|
138
|
+
subject { @responses['deal'] }
|
139
|
+
|
140
|
+
it { is_expected.not_to be_nil }
|
141
|
+
it { is_expected.to include('id') }
|
142
|
+
it { is_expected.to include('company_id') }
|
143
|
+
it { is_expected.to include('issue_date') }
|
144
|
+
it { is_expected.to include('due_date') }
|
145
|
+
it { is_expected.to include('amount') }
|
146
|
+
it { is_expected.to include('due_amount') }
|
147
|
+
it { is_expected.to include('type') }
|
148
|
+
it { is_expected.to include('partner_id') }
|
149
|
+
it { is_expected.to include('details') }
|
150
|
+
it { is_expected.to include('payments') }
|
151
|
+
end
|
152
|
+
|
153
|
+
describe 'should get details from deals for the company' do
|
154
|
+
subject { @responses['deal']['details'].first}
|
155
|
+
|
156
|
+
it { is_expected.not_to be_nil }
|
157
|
+
it { is_expected.to include('account_item_id') }
|
158
|
+
it { is_expected.to include('tax_id') }
|
159
|
+
it { is_expected.to include('item_id') }
|
160
|
+
it { is_expected.to include('amount') }
|
161
|
+
it { is_expected.to include('description') }
|
162
|
+
end
|
163
|
+
end
|
107
164
|
end
|
108
165
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"account_items" : [
|
3
|
+
{
|
4
|
+
"id" : 101,
|
5
|
+
"name" : "ソフトウェア",
|
6
|
+
"shortcut" : "SOFUTO",
|
7
|
+
"default_tax_id" : 12,
|
8
|
+
"default_tax_code" : 108,
|
9
|
+
"categories" : ["資産", "固定資産", "無形固定資産"]
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"id" : 102,
|
13
|
+
"name" : "ほげほげ",
|
14
|
+
"shortcut" : "HOGE",
|
15
|
+
"default_tax_id" : 12,
|
16
|
+
"default_tax_code" : 108,
|
17
|
+
"categories" : ["資産", "固定資産", "無形固定資産"]
|
18
|
+
}
|
19
|
+
]
|
20
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"company_id":-1,"issue_date":"2013-01-01","due_date":"2013-02-28","type":"expense","partner_id":201,"ref_number":"123-456","details":[{"account_item_id":803,"tax_code":6,"item_id":501,"section_id":1,"tag_ids":[1,2,3],"amount":5250,"description":"備考"}],"payments":[{"date":"2013-01-28","from_walletable_type":"bank_account","from_walletable_id":103,"amount":5250}]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"company_id":1,"name":"新しい取引先","shortcut1":"NEWPARTNER","shortcut2":"502"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"company_id":1,"name":"開発部門","shortcut1":"DEVELOPER","shortcut2":"123"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"company_id":1,"name":"メモタグ","shortcut1":"MEMOTAG","shortcut2":"123"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"company_id":-1,"date":"2013-01-01","amount":5000,"from_walletable_type":"bank_account","from_walletable_id":101,"to_walletable_type":"credit_card","to_walletable_id":201,"description":"備考"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"company_id":1,"type":"bank_account","name":"〇〇銀行","bank_id":123}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"deal" : {
|
3
|
+
"id" : 101,
|
4
|
+
"company_id" : -1,
|
5
|
+
"issue_date" : "2013-01-01",
|
6
|
+
"due_date" : "2013-02-28",
|
7
|
+
"amount" : 5250,
|
8
|
+
"due_amount" : 0,
|
9
|
+
"type" : "expense",
|
10
|
+
"partner_id" : 201,
|
11
|
+
"ref_number" : "123-456",
|
12
|
+
"details" : [
|
13
|
+
{
|
14
|
+
"account_item_id" : 803,
|
15
|
+
"tax_id" : 14, // deprecated
|
16
|
+
"tax_code" : 6,
|
17
|
+
"item_id" : 501,
|
18
|
+
"section_id" : 1,
|
19
|
+
"tag_ids" : [1, 2, 3],
|
20
|
+
"amount" : 5250, // 税込
|
21
|
+
"vat" : 250,
|
22
|
+
"description" : "備考"
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"payments" : [
|
26
|
+
{
|
27
|
+
"date" : "2013-01-28",
|
28
|
+
"from_walletable_type" : "bank_account",
|
29
|
+
"from_walletable_id" : 103,
|
30
|
+
"amount" : 5250
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"deals" : [
|
3
|
+
{
|
4
|
+
"id" : 101,
|
5
|
+
"company_id" : 1,
|
6
|
+
"issue_date" : "2013-01-01",
|
7
|
+
"due_date" : "2013-02-28",
|
8
|
+
"amount" : 5250,
|
9
|
+
"due_amount" : 0,
|
10
|
+
"type" : "expense",
|
11
|
+
"partner_id" : 201,
|
12
|
+
"ref_number" : "123-456",
|
13
|
+
"details" : [
|
14
|
+
{
|
15
|
+
"account_item_id" : 803,
|
16
|
+
"tax_id" : 14, // deprecated
|
17
|
+
"tax_code" : 2,
|
18
|
+
"item_id" : 501,
|
19
|
+
"section_id" : 1,
|
20
|
+
"tag_ids" : [1, 2, 3],
|
21
|
+
"amount" : 5250,
|
22
|
+
"vat" : 250,
|
23
|
+
"description" : "備考"
|
24
|
+
}
|
25
|
+
],
|
26
|
+
"payments" : [
|
27
|
+
{
|
28
|
+
"date" : "2013-01-28",
|
29
|
+
"from_walletable_type" : "bank_account",
|
30
|
+
"from_walletable_id" : 103,
|
31
|
+
"amount" : 5250
|
32
|
+
}
|
33
|
+
]
|
34
|
+
}
|
35
|
+
]
|
36
|
+
}
|