freee 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +25 -1
  4. data/freee.gemspec +2 -0
  5. data/lib/freee/{account.rb → account_item.rb} +3 -3
  6. data/lib/freee/base.rb +13 -2
  7. data/lib/freee/company.rb +4 -0
  8. data/lib/freee/deal.rb +4 -2
  9. data/lib/freee/item.rb +4 -2
  10. data/lib/freee/obj/account_item.rb +5 -0
  11. data/lib/freee/obj/response.rb +1 -1
  12. data/lib/freee/obj/{account.rb → section.rb} +1 -1
  13. data/lib/freee/obj/{wallet.rb → tag.rb} +1 -1
  14. data/lib/freee/obj/{amount.rb → wallet_txn.rb} +1 -1
  15. data/lib/freee/partner.rb +4 -2
  16. data/lib/freee/section.rb +15 -0
  17. data/lib/freee/tag.rb +15 -0
  18. data/lib/freee/tax.rb +2 -2
  19. data/lib/freee/transfer.rb +4 -2
  20. data/lib/freee/version.rb +1 -1
  21. data/lib/freee/{wallet.rb → wallet_txn.rb} +5 -4
  22. data/lib/freee/walletable.rb +6 -0
  23. data/spec/account_item_spec.rb +44 -0
  24. data/spec/base_spec.rb +3 -9
  25. data/spec/company_spec.rb +53 -36
  26. data/spec/deal_spec.rb +150 -93
  27. data/spec/fixtures/account_items.json +20 -0
  28. data/spec/fixtures/companies.json +11 -0
  29. data/spec/fixtures/company.json +13 -0
  30. data/spec/fixtures/create_deal.json +1 -0
  31. data/spec/fixtures/create_item.json +6 -0
  32. data/spec/fixtures/create_partner.json +1 -0
  33. data/spec/fixtures/create_section.json +1 -0
  34. data/spec/fixtures/create_tag.json +1 -0
  35. data/spec/fixtures/create_transfer.json +1 -0
  36. data/spec/fixtures/create_wallet_txn.json +11 -0
  37. data/spec/fixtures/create_walletable.json +1 -0
  38. data/spec/fixtures/deal.json +34 -0
  39. data/spec/fixtures/deals.json +36 -0
  40. data/spec/fixtures/item.json +9 -0
  41. data/spec/fixtures/items.json +11 -0
  42. data/spec/fixtures/partner.json +9 -0
  43. data/spec/fixtures/partners.json +11 -0
  44. data/spec/fixtures/section.json +9 -0
  45. data/spec/fixtures/sections.json +11 -0
  46. data/spec/fixtures/tag.json +9 -0
  47. data/spec/fixtures/tags.json +11 -0
  48. data/spec/fixtures/taxes.json +8 -0
  49. data/spec/fixtures/taxes_with_code.json +9 -0
  50. data/spec/fixtures/transfer.json +13 -0
  51. data/spec/fixtures/transfers.json +37 -0
  52. data/spec/fixtures/user.json +10 -0
  53. data/spec/fixtures/user_with_companies.json +19 -0
  54. data/spec/fixtures/wallet_txn.json +14 -0
  55. data/spec/fixtures/wallet_txns.json +16 -0
  56. data/spec/fixtures/walletable.json +1 -0
  57. data/spec/fixtures/walletables.json +9 -0
  58. data/spec/item_spec.rb +74 -21
  59. data/spec/partner_spec.rb +59 -21
  60. data/spec/section_spec.rb +68 -0
  61. data/spec/setenv_spec.rb +0 -4
  62. data/spec/spec_helper.rb +41 -3
  63. data/spec/tag_spec.rb +68 -0
  64. data/spec/tax_spec.rb +63 -22
  65. data/spec/transfer_spec.rb +89 -34
  66. data/spec/user_spec.rb +47 -20
  67. data/spec/util_spec.rb +19 -10
  68. data/spec/wallet_txn_spec.rb +88 -0
  69. data/spec/walletable_spec.rb +74 -24
  70. metadata +109 -15
  71. data/lib/freee/amount.rb +0 -7
  72. data/spec/account_spec.rb +0 -34
  73. data/spec/amount_spec.rb +0 -26
  74. data/spec/wallet_spec.rb +0 -89
@@ -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
- describe 'should get payments from deals for the company' do
54
- subject { deal.list(company_id)['deals'].first['payments'].first }
5
+ let(:company_id) { -1 }
6
+ let(:params) { fixture('create_deal.json') }
7
+ let(:json) { { params: params } }
55
8
 
56
- it { is_expected.not_to be_nil }
57
- it { is_expected.to include('date') }
58
- it { is_expected.to include('from_walletable_type') }
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 'should get payments from deals for the company with start_due_date' do
64
- subject do
65
- result = deal.list(company_id, start_due_date: '2014-06-25')['deals']
66
- __memoize = result
67
-
68
- result.select! { |x| x['due_date'] >= '2014-06-25' }
69
- result.map! { |x| x['due_date'] }
70
-
71
- __memoize.map! { |x| x['due_date'] }
72
-
73
- result.length == __memoize.length
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
- it { is_expected.not_to be_nil }
77
- it { is_expected.to be_truthy }
78
- end
79
-
80
- describe 'should get payments from future deals for the company with start_due_date' do
81
- subject { deal.list(company_id, start_due_date: '2099-12-31')['deals'] }
82
-
83
- it { is_expected.not_to be_nil }
84
- it { is_expected.to eq [] }
85
- end
86
-
87
- describe 'should get payments for deals with income' do
88
- subject do
89
- result = deal.list_income(company_id)['deals']
90
- result.map! { |x| x['type'] == 'income' }
91
- Set.new(result).length
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
- it { is_expected.not_to be_nil }
95
- it { is_expected.to eq 1 }
96
- end
97
-
98
- describe 'should get payments for deals with outcome' do
99
- subject do
100
- result = deal.list_expense(company_id)['deals']
101
- result.map! { |x| x['type'] == 'expense' }
102
- Set.new(result).length
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
- it { is_expected.not_to be_nil }
106
- it { is_expected.to eq 1 }
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,11 @@
1
+ {
2
+ "companies" : [
3
+ {
4
+ "id" : 101,
5
+ "name" : "freee事務所",
6
+ "name_kana" : "フリージムショ",
7
+ "display_name" : "freee事務所",
8
+ "role" : "admin"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "company" : {
3
+ "id" : 1,
4
+ "name" : "freee事務所",
5
+ "name_kana" : "フリージムショ",
6
+ "display_name" : "freee事務所",
7
+ "role" : "admin",
8
+ "account_items" : [],
9
+ "taxes" : [],
10
+ "items" : [],
11
+ "partners" : []
12
+ }
13
+ }
@@ -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,6 @@
1
+ {
2
+ "company_id" : 1,
3
+ "name" : "新しい品目",
4
+ "shortcut1" : "NEWITEM",
5
+ "shortcut2" : "202"
6
+ }
@@ -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,11 @@
1
+ {
2
+ "company_id" : 1,
3
+ "date" : "2013-01-01",
4
+ "amount" : 5000,
5
+ "due_amount" : 0,
6
+ "balance" : 10000,
7
+ "entry_side" : "income",
8
+ "walletable_type" : "bank_account",
9
+ "walletable_id" : 101,
10
+ "description" : "振込 カ)ABC"
11
+ }
@@ -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
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "item" : {
3
+ "id" : 102,
4
+ "company_id" : 1,
5
+ "name" : "新しい品目",
6
+ "shortcut1" : "NEWITEM",
7
+ "shortcut2" : "202"
8
+ }
9
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "items" : [
3
+ {
4
+ "id" : 101,
5
+ "company_id" : 1,
6
+ "name" : "タクシー代",
7
+ "shortcut1" : "TAXI",
8
+ "shortcut2" : "201"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "partner" : {
3
+ "id" : 102,
4
+ "company_id" : 1,
5
+ "name" : "新しい取引先",
6
+ "shortcut1" : "NEWPARTNER",
7
+ "shortcut2" : "502"
8
+ }
9
+ }