rexpense 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +22 -0
  3. data/.coveralls.yml +1 -0
  4. data/.gitignore +24 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +54 -0
  7. data/.travis.yml +9 -0
  8. data/CHANGELOG.md +1 -0
  9. data/Gemfile +4 -0
  10. data/Gemfile.lock +97 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +195 -0
  13. data/Rakefile +6 -0
  14. data/bin/console +14 -0
  15. data/bin/rspec +21 -0
  16. data/bin/setup +7 -0
  17. data/lib/rexpense/client.rb +39 -0
  18. data/lib/rexpense/configuration.rb +13 -0
  19. data/lib/rexpense/entities/activity.rb +11 -0
  20. data/lib/rexpense/entities/activity_collection.rb +14 -0
  21. data/lib/rexpense/entities/advancement.rb +14 -0
  22. data/lib/rexpense/entities/advancement_collection.rb +14 -0
  23. data/lib/rexpense/entities/advancement_devolution.rb +13 -0
  24. data/lib/rexpense/entities/attachment.rb +13 -0
  25. data/lib/rexpense/entities/attachment_collection.rb +14 -0
  26. data/lib/rexpense/entities/base.rb +9 -0
  27. data/lib/rexpense/entities/collection.rb +65 -0
  28. data/lib/rexpense/entities/comment.rb +13 -0
  29. data/lib/rexpense/entities/comment_collection.rb +14 -0
  30. data/lib/rexpense/entities/expense.rb +22 -0
  31. data/lib/rexpense/entities/expense_collection.rb +14 -0
  32. data/lib/rexpense/entities/membership.rb +10 -0
  33. data/lib/rexpense/entities/membership_collection.rb +14 -0
  34. data/lib/rexpense/entities/organization.rb +14 -0
  35. data/lib/rexpense/entities/organization_collection.rb +14 -0
  36. data/lib/rexpense/entities/pre_expense.rb +17 -0
  37. data/lib/rexpense/entities/pre_expense_collection.rb +14 -0
  38. data/lib/rexpense/entities/reimbursement.rb +14 -0
  39. data/lib/rexpense/entities/reimbursement_collection.rb +14 -0
  40. data/lib/rexpense/entities/tag.rb +8 -0
  41. data/lib/rexpense/entities/tag_collection.rb +14 -0
  42. data/lib/rexpense/entities/user.rb +14 -0
  43. data/lib/rexpense/entities/user_collection.rb +14 -0
  44. data/lib/rexpense/entities/webhook.rb +10 -0
  45. data/lib/rexpense/entities/webhook_collection.rb +14 -0
  46. data/lib/rexpense/exception.rb +11 -0
  47. data/lib/rexpense/http.rb +41 -0
  48. data/lib/rexpense/request.rb +56 -0
  49. data/lib/rexpense/resources/activity.rb +24 -0
  50. data/lib/rexpense/resources/advancement.rb +20 -0
  51. data/lib/rexpense/resources/advancement_devolution.rb +36 -0
  52. data/lib/rexpense/resources/base.rb +52 -0
  53. data/lib/rexpense/resources/expense.rb +39 -0
  54. data/lib/rexpense/resources/nested_endpoints/attachment.rb +48 -0
  55. data/lib/rexpense/resources/nested_endpoints/comment.rb +84 -0
  56. data/lib/rexpense/resources/nested_endpoints/membership.rb +74 -0
  57. data/lib/rexpense/resources/nested_endpoints/participant.rb +43 -0
  58. data/lib/rexpense/resources/organization.rb +31 -0
  59. data/lib/rexpense/resources/pre_expense.rb +56 -0
  60. data/lib/rexpense/resources/reimbursement.rb +20 -0
  61. data/lib/rexpense/resources/resource_base.rb +105 -0
  62. data/lib/rexpense/resources/tag.rb +82 -0
  63. data/lib/rexpense/resources/webhook.rb +82 -0
  64. data/lib/rexpense/response.rb +43 -0
  65. data/lib/rexpense/version.rb +3 -0
  66. data/lib/rexpense.rb +19 -0
  67. data/rexpense.gemspec +48 -0
  68. data/spec/lib/rexpense/client_spec.rb +47 -0
  69. data/spec/lib/rexpense/configuration_spec.rb +26 -0
  70. data/spec/lib/rexpense/entities/activity_collection_spec.rb +5 -0
  71. data/spec/lib/rexpense/entities/activity_spec.rb +9 -0
  72. data/spec/lib/rexpense/entities/advancement_collection_spec.rb +5 -0
  73. data/spec/lib/rexpense/entities/advancement_devolution_spec.rb +9 -0
  74. data/spec/lib/rexpense/entities/advancement_spec.rb +10 -0
  75. data/spec/lib/rexpense/entities/base_spec.rb +28 -0
  76. data/spec/lib/rexpense/entities/collection_spec.rb +70 -0
  77. data/spec/lib/rexpense/entities/comment_collection_spec.rb +5 -0
  78. data/spec/lib/rexpense/entities/comment_spec.rb +10 -0
  79. data/spec/lib/rexpense/entities/expense_collection_spec.rb +5 -0
  80. data/spec/lib/rexpense/entities/expense_spec.rb +14 -0
  81. data/spec/lib/rexpense/entities/membership_collection_spec.rb +5 -0
  82. data/spec/lib/rexpense/entities/membership_spec.rb +7 -0
  83. data/spec/lib/rexpense/entities/organization_collection_spec.rb +5 -0
  84. data/spec/lib/rexpense/entities/organization_spec.rb +8 -0
  85. data/spec/lib/rexpense/entities/pre_expense_collection_spec.rb +5 -0
  86. data/spec/lib/rexpense/entities/pre_expense_spec.rb +10 -0
  87. data/spec/lib/rexpense/entities/reimbursement_collection_spec.rb +5 -0
  88. data/spec/lib/rexpense/entities/reimbursement_spec.rb +10 -0
  89. data/spec/lib/rexpense/entities/user_collection_spec.rb +5 -0
  90. data/spec/lib/rexpense/entities/user_spec.rb +10 -0
  91. data/spec/lib/rexpense/entities/webhook_collection_spec.rb +5 -0
  92. data/spec/lib/rexpense/entities/webhook_spec.rb +7 -0
  93. data/spec/lib/rexpense/http_spec.rb +37 -0
  94. data/spec/lib/rexpense/request_spec.rb +29 -0
  95. data/spec/lib/rexpense/resources/activity_spec.rb +16 -0
  96. data/spec/lib/rexpense/resources/advancement_devolution_spec.rb +29 -0
  97. data/spec/lib/rexpense/resources/advancement_spec.rb +207 -0
  98. data/spec/lib/rexpense/resources/expense_spec.rb +227 -0
  99. data/spec/lib/rexpense/resources/organization_spec.rb +162 -0
  100. data/spec/lib/rexpense/resources/pre_expense_spec.rb +83 -0
  101. data/spec/lib/rexpense/resources/reimbursement_spec.rb +207 -0
  102. data/spec/lib/rexpense/resources/tag_specs.rb +77 -0
  103. data/spec/lib/rexpense/resources/webhook_spec.rb +51 -0
  104. data/spec/lib/rexpense/response_spec.rb +91 -0
  105. data/spec/lib/rexpense_spec.rb +34 -0
  106. data/spec/spec_helper.rb +39 -0
  107. data/spec/support/attachments/logo.png +0 -0
  108. data/spec/support/client.rb +3 -0
  109. data/spec/support/matchers/have_attr_accessor.rb +18 -0
  110. data/spec/support/shared_examples/entity_attributes.rb +9 -0
  111. data/spec/support/shared_examples/entity_collection.rb +19 -0
  112. data/spec/support/shared_examples/http_request_methods.rb +35 -0
  113. data/spec/support/vcr.rb +7 -0
  114. metadata +390 -0
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rexpense::Resources::Advancement, vcr: true do
4
+ let(:advancement_klass) { Rexpense::Entities::Advancement }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.advancements.find_all }
9
+
10
+ it "show all advancements successfully" do
11
+ expect(subject.class).to eq(Rexpense::Entities::AdvancementCollection)
12
+ expect(subject.collection.first.class).to eq(advancement_klass)
13
+ end
14
+ end
15
+
16
+ it "find advancements by attributes" do
17
+ params = { currency_in: ["USD"] }
18
+ result = client.advancements.find_all(params)
19
+
20
+ expect(result).to be_a(Rexpense::Entities::AdvancementCollection)
21
+ expect(result.collection[0]).to be_a(advancement_klass)
22
+ expect(result.collection[0].currency).to eq("USD")
23
+ expect(result.collection[1].currency).to eq("USD")
24
+ expect(result.collection[2].currency).to eq("USD")
25
+ end
26
+
27
+ context "when error" do
28
+ let(:client) { Rexpense.client("") }
29
+
30
+ it "raises Rexpense::RequestError with 401 status code" do
31
+ expect { client.advancements.find_all({}) }.to raise_error(Rexpense::RequestError) do |error|
32
+ expect(error.code).to eq(401)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "#find" do
39
+ context "with success" do
40
+ subject { client.advancements.find(40) }
41
+
42
+ it "returns a category successfully" do
43
+ expect(subject.class).to eq(advancement_klass)
44
+ expect(subject.id).to eq(40)
45
+ end
46
+ end
47
+
48
+ context "with error" do
49
+ it "raises Rexpense::RequestError with 404 status code" do
50
+ expect { client.advancements.find(000000) }.to raise_error(Rexpense::RequestError) do |error|
51
+ expect(error.code).to eq(404)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#create" do
58
+ let(:params) do
59
+ {
60
+ amount: 129.65,
61
+ date: '2017-09-04',
62
+ payer: {
63
+ id: 144,
64
+ type: 'Organization'
65
+ },
66
+ receiver: {
67
+ id: 2,
68
+ type: 'User'
69
+ }
70
+ }
71
+ end
72
+
73
+ context "with success" do
74
+ it "creates a category successfully" do
75
+ result = client.advancements.create(params)
76
+ expect(result).to be_a(advancement_klass)
77
+ expect(result.amount).to eq(129.65)
78
+ end
79
+ end
80
+
81
+ context "with error" do
82
+ it "raises Rexpense::RequestError with 422 status code" do
83
+ expect { client.advancements.create({}) }.to raise_error(Rexpense::RequestError) do |error|
84
+ expect(error.code).to eq(422)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "#update" do
91
+ context "with success" do
92
+ it "updates a category successfully" do
93
+ expect(client.advancements.update(40, { amount: 152.00 })).to be_a(advancement_klass)
94
+ end
95
+ end
96
+
97
+ context "with error" do
98
+ it "raises Rexpense::RequestError with 404 status code" do
99
+ expect { client.advancements.update(88888888, {}) }.to raise_error(Rexpense::RequestError) do |error|
100
+ expect(error.code).to eq(404)
101
+ end
102
+ end
103
+
104
+ it "raises Rexpense::RequestError with 422 status core" do
105
+ expect { client.advancements.update(40, { date: '' }) }.to raise_error(Rexpense::RequestError) do |error|
106
+ expect(error.code).to eq(422)
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ describe "#destroy" do
113
+ context "with success" do
114
+ it "destroy a category successfully" do
115
+ expect(client.advancements.destroy(52)).to be_truthy
116
+ end
117
+ end
118
+
119
+ context "with error" do
120
+ it "raises Rexpense::RequestError with 404 status code" do
121
+ expect { client.advancements.destroy(88888888) }.to raise_error(Rexpense::RequestError) do |error|
122
+ expect(error.code).to eq(404)
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ context 'Comments' do
129
+ let(:comment_klass) { Rexpense::Entities::Comment }
130
+
131
+ describe '#comments' do
132
+ context "with success" do
133
+ subject { client.advancements.comments(4) }
134
+
135
+ it "show all advancement comments successfully" do
136
+ expect(subject.class).to eq(Rexpense::Entities::CommentCollection)
137
+ expect(subject.collection.first.class).to eq(comment_klass)
138
+ end
139
+ end
140
+ end
141
+
142
+ describe '#find_comment' do
143
+ context "with success" do
144
+ subject { client.advancements.find_comment(4, 295) }
145
+
146
+ it "show all advancement comments successfully" do
147
+ expect(subject.class).to eq(comment_klass)
148
+ expect(subject.id).to eq(295)
149
+ end
150
+ end
151
+ end
152
+
153
+ describe '#create_comment' do
154
+ context "with success" do
155
+ subject { client.advancements.create_comment(4, { content: 'Loren ipsun dollor' }) }
156
+
157
+ it "create a comment" do
158
+ expect(subject.class).to eq(comment_klass)
159
+ expect(subject.id).to eq(673)
160
+ end
161
+ end
162
+ end
163
+
164
+ describe '#update_comment' do
165
+ context "with success" do
166
+ subject { client.advancements.update_comment(4, 673, { content: 'Foo bar' }) }
167
+
168
+ it "update comment" do
169
+ expect(subject.class).to eq(comment_klass)
170
+ expect(subject.id).to eq(673)
171
+ expect(subject.content).to eq('Foo bar')
172
+ end
173
+ end
174
+ end
175
+
176
+ describe '#destroy_comment' do
177
+ subject { client.advancements.destroy_comment(4, 673) }
178
+
179
+ it "destroy comment" do
180
+ expect(subject).to be_truthy
181
+ end
182
+ end
183
+ end
184
+
185
+ context 'Participants' do
186
+ let(:user_klass) { Rexpense::Entities::User }
187
+
188
+ describe "#participants" do
189
+ context "with success" do
190
+ subject { client.advancements.participants(51) }
191
+
192
+ it "show all advancements successfully" do
193
+ expect(subject.class).to eq(Rexpense::Entities::UserCollection)
194
+ expect(subject.collection.first.class).to eq(user_klass)
195
+ end
196
+ end
197
+ end
198
+
199
+ describe '#leave_participant' do
200
+ subject { client.advancements.leave_participant(49) }
201
+
202
+ it "show all advancements successfully" do
203
+ expect(subject).to be_truthy
204
+ end
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,227 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rexpense::Resources::Expense, vcr: true do
4
+ let(:expense_klass) { Rexpense::Entities::Expense }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.expenses.find_all }
9
+
10
+ it "show all expenses successfully" do
11
+ expect(subject.class).to eq(Rexpense::Entities::ExpenseCollection)
12
+ expect(subject.collection.first.class).to eq(expense_klass)
13
+ end
14
+ end
15
+
16
+ context "when error" do
17
+ let(:client) { Rexpense.client("") }
18
+
19
+ it "raises Rexpense::RequestError with 401 status code" do
20
+ expect { client.expenses.find_all({}) }.to raise_error(Rexpense::RequestError) do |error|
21
+ expect(error.code).to eq(401)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "#find" do
28
+ context "with success" do
29
+ subject { client.expenses.find(949) }
30
+
31
+ it "returns a category successfully" do
32
+ expect(subject.class).to eq(expense_klass)
33
+ expect(subject.id).to eq(949)
34
+ end
35
+ end
36
+
37
+ context "with error" do
38
+ it "raises Rexpense::RequestError with 404 status code" do
39
+ expect { client.expenses.find(000000) }.to raise_error(Rexpense::RequestError) do |error|
40
+ expect(error.code).to eq(404)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#create" do
47
+ let(:params) do
48
+ {
49
+ amount: 129.65,
50
+ kind: 'monetary',
51
+ occurred_at: '2017-09-04',
52
+ payer: {
53
+ id: 144,
54
+ type: 'Organization'
55
+ },
56
+ receiver: {
57
+ id: 2,
58
+ type: 'User'
59
+ }
60
+ }
61
+ end
62
+
63
+ context "with success" do
64
+ it "creates a category successfully" do
65
+ result = client.expenses.create(params)
66
+ expect(result).to be_a(expense_klass)
67
+ expect(result.amount).to eq(129.65)
68
+ end
69
+ end
70
+
71
+ context "with error" do
72
+ it "raises Rexpense::RequestError with 422 status code" do
73
+ expect { client.expenses.create({}) }.to raise_error(Rexpense::RequestError) do |error|
74
+ expect(error.code).to eq(422)
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "#update" do
81
+ context "with success" do
82
+ it "updates a category successfully" do
83
+ expect(client.expenses.update(949, { amount: 152.00 })).to be_a(expense_klass)
84
+ end
85
+ end
86
+
87
+ context "with error" do
88
+ it "raises Rexpense::RequestError with 404 status code" do
89
+ expect { client.expenses.update(88888888, {}) }.to raise_error(Rexpense::RequestError) do |error|
90
+ expect(error.code).to eq(404)
91
+ end
92
+ end
93
+
94
+ it "raises Rexpense::RequestError with 422 status core" do
95
+ expect { client.expenses.update(949, { occurred_at: '' }) }.to raise_error(Rexpense::RequestError) do |error|
96
+ expect(error.code).to eq(422)
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ describe "#destroy" do
103
+ context "with success" do
104
+ it "destroy a category successfully" do
105
+ expect(client.expenses.destroy(949)).to be_truthy
106
+ end
107
+ end
108
+
109
+ context "with error" do
110
+ it "raises Rexpense::RequestError with 404 status code" do
111
+ expect { client.expenses.destroy(88888888) }.to raise_error(Rexpense::RequestError) do |error|
112
+ expect(error.code).to eq(404)
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ context 'Comments' do
119
+ let(:comment_klass) { Rexpense::Entities::Comment }
120
+
121
+ describe '#comments' do
122
+ context "with success" do
123
+ subject { client.expenses.comments(808) }
124
+
125
+ it "show all expense comments successfully" do
126
+ expect(subject.class).to eq(Rexpense::Entities::CommentCollection)
127
+ expect(subject.collection.first.class).to eq(comment_klass)
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '#find_comment' do
133
+ context "with success" do
134
+ subject { client.expenses.find_comment(808, 654) }
135
+
136
+ it "show a expense comment successfully" do
137
+ expect(subject.class).to eq(comment_klass)
138
+ expect(subject.id).to eq(654)
139
+ end
140
+ end
141
+ end
142
+
143
+ describe '#create_comment' do
144
+ context "with success" do
145
+ subject { client.expenses.create_comment(808, { content: 'Loren ipsun dollor' }) }
146
+
147
+ it "create a comment" do
148
+ expect(subject.class).to eq(comment_klass)
149
+ expect(subject.id).to eq(679)
150
+ end
151
+ end
152
+ end
153
+
154
+ describe '#update_comment' do
155
+ context "with success" do
156
+ subject { client.expenses.update_comment(808, 679, { content: 'Foo bar' }) }
157
+
158
+ it "update comment" do
159
+ expect(subject.class).to eq(comment_klass)
160
+ expect(subject.id).to eq(679)
161
+ expect(subject.content).to eq('Foo bar')
162
+ end
163
+ end
164
+ end
165
+
166
+ describe '#destroy_comment' do
167
+ subject { client.expenses.destroy_comment(808, 679) }
168
+
169
+ it "destroy comment" do
170
+ expect(subject).to be_truthy
171
+ end
172
+ end
173
+ end
174
+
175
+ context 'Participants' do
176
+ let(:user_klass) { Rexpense::Entities::User }
177
+
178
+ describe "#participants" do
179
+ context "with success" do
180
+ subject { client.expenses.participants(973) }
181
+
182
+ it "show all expenses successfully" do
183
+ expect(subject.class).to eq(Rexpense::Entities::UserCollection)
184
+ expect(subject.collection.first.class).to eq(user_klass)
185
+ end
186
+ end
187
+ end
188
+
189
+ describe '#leave_participant' do
190
+ subject { client.expenses.leave_participant(940) }
191
+
192
+ it "show all expenses successfully" do
193
+ expect(subject).to be_truthy
194
+ end
195
+ end
196
+ end
197
+
198
+ context 'Attachments' do
199
+ let(:attachment_klass) { Rexpense::Entities::Attachment }
200
+
201
+ describe '#attachments' do
202
+ subject { client.expenses.attachments(974) }
203
+
204
+ it 'return expenses attachments' do
205
+ expect(subject.class).to eq(Rexpense::Entities::AttachmentCollection)
206
+ expect(subject.collection.first.class).to eq(attachment_klass)
207
+ end
208
+ end
209
+
210
+ describe '#find_attachments' do
211
+ subject { client.expenses.find_attachment(974, 635) }
212
+
213
+ it 'return attachment' do
214
+ expect(subject.class).to eq(Rexpense::Entities::Attachment)
215
+ expect(subject.id).to eq(635)
216
+ end
217
+ end
218
+
219
+ describe '#destroy_attachments' do
220
+ subject { client.expenses.destroy_attachment(974, 635) }
221
+
222
+ it 'destroy attachment' do
223
+ expect(subject).to be_truthy
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,162 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rexpense::Resources::Organization, vcr: true do
4
+ let(:organization_klass) { Rexpense::Entities::Organization }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.organizations.find_all }
9
+
10
+ it "show all organizations successfully" do
11
+ expect(subject.class).to eq(Rexpense::Entities::OrganizationCollection)
12
+ expect(subject.collection.first.class).to eq(organization_klass)
13
+ end
14
+ end
15
+
16
+ context "when error" do
17
+ let(:client) { Rexpense.client("") }
18
+
19
+ it "raises Rexpense::RequestError with 401 status code" do
20
+ expect { client.organizations.find_all({}) }.to raise_error(Rexpense::RequestError) do |error|
21
+ expect(error.code).to eq(401)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "#find" do
28
+ context "with success" do
29
+ subject { client.organizations.find(35) }
30
+
31
+ it "returns a category successfully" do
32
+ expect(subject.class).to eq(organization_klass)
33
+ expect(subject.id).to eq(35)
34
+ end
35
+ end
36
+
37
+ context "with error" do
38
+ it "raises Rexpense::RequestError with 404 status code" do
39
+ expect { client.organizations.find(000000) }.to raise_error(Rexpense::RequestError) do |error|
40
+ expect(error.code).to eq(404)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#update" do
47
+ context "with success" do
48
+ it "updates a organization name successfully" do
49
+ expect(client.organizations.update(16, { name: "Game of words" })).to be_a(organization_klass)
50
+ end
51
+ end
52
+
53
+ context "with error" do
54
+ it "raises Rexpense::RequestError with 404 status code" do
55
+ expect { client.organizations.update(88888888, {}) }.to raise_error(Rexpense::RequestError) do |error|
56
+ expect(error.code).to eq(404)
57
+ end
58
+ end
59
+
60
+ it "raises Rexpense::RequestError with 422 status core" do
61
+ expect { client.organizations.update(16, { name: '' }) }.to raise_error(Rexpense::RequestError) do |error|
62
+ expect(error.code).to eq(422)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#destroy" do
69
+ context "with success" do
70
+ it "destroy a category successfully" do
71
+ expect(client.organizations.destroy(14)).to be_truthy
72
+ end
73
+ end
74
+
75
+ context "with error" do
76
+ it "raises Rexpense::RequestError with 404 status code" do
77
+ expect { client.organizations.destroy(88888888) }.to raise_error(Rexpense::RequestError) do |error|
78
+ expect(error.code).to eq(404)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#distances_rules' do
85
+ subject { client.organizations.distances_rules(35) }
86
+
87
+ it 'return organization distance rule' do
88
+ expect(subject).to eq({
89
+ 'id' => 3,
90
+ 'amount' => 6.0,
91
+ 'currency' => 'BRL',
92
+ 'distance_kind' => 'km',
93
+ 'organization_id' => 35
94
+ })
95
+ end
96
+ end
97
+
98
+ describe '#update_distances_rules' do
99
+ subject { client.organizations.update_distances_rules(35, { amount: 7.0 }) }
100
+
101
+ it 'return organization distance rule' do
102
+ expect(subject).to eq({
103
+ 'id' => 3,
104
+ 'amount' => 7.0,
105
+ 'currency' => 'BRL',
106
+ 'distance_kind' => 'km',
107
+ 'organization_id' => 35
108
+ })
109
+ end
110
+ end
111
+
112
+ context 'Memberships' do
113
+ let(:membership_klass) { Rexpense::Entities::Membership }
114
+
115
+ describe '#memberships' do
116
+ subject { client.organizations.memberships(35) }
117
+
118
+ it 'returns a collection of memberships' do
119
+ expect(subject.class).to eq(Rexpense::Entities::MembershipCollection)
120
+ expect(subject.collection.first.class).to eq(membership_klass)
121
+ end
122
+ end
123
+
124
+ describe '#find_membership' do
125
+ subject { client.organizations.find_membership(35, 64) }
126
+
127
+ it 'find a membership in organization' do
128
+ expect(subject.class).to eq(Rexpense::Entities::Membership)
129
+ expect(subject.user.id).to eq(64)
130
+ end
131
+ end
132
+
133
+ describe '#create_membership' do
134
+ subject { client.organizations.create_membership(35, { user: { email: 'dante.miranda@nexaas.com' }, role: 'member' }) }
135
+
136
+ it 'create a membership in organization' do
137
+ expect(subject).to eq({
138
+ "total_recipients" => 1,
139
+ "not_added_recipients" => [],
140
+ "added_recipients" => ["dante.miranda@nexaas.com"],
141
+ "invalid_recipients" => []
142
+ })
143
+ end
144
+ end
145
+
146
+ describe '#update_membership' do
147
+ subject { client.organizations.update_membership(35, 64, { role: 'admin' }) }
148
+
149
+ it 'update a membership' do
150
+ expect(subject.role).to eq('admin')
151
+ end
152
+ end
153
+
154
+ describe '#destroy_membership' do
155
+ subject { client.organizations.destroy_membership(35, 64) }
156
+
157
+ it 'update a membership' do
158
+ expect(subject).to be_truthy
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rexpense::Resources::PreExpense, vcr: true do
4
+ let(:pre_expense_klass) { Rexpense::Entities::PreExpense }
5
+
6
+ describe "#find_all" do
7
+ context "with success" do
8
+ subject { client.pre_expenses.find_all }
9
+
10
+ it "show all pre_expenses successfully" do
11
+ expect(subject.class).to eq(Rexpense::Entities::PreExpenseCollection)
12
+ expect(subject.collection.first.class).to eq(pre_expense_klass)
13
+ end
14
+ end
15
+
16
+ context "when error" do
17
+ let(:client) { Rexpense.client("") }
18
+
19
+ it "raises Rexpense::RequestError with 401 status code" do
20
+ expect { client.pre_expenses.find_all({}) }.to raise_error(Rexpense::RequestError) do |error|
21
+ expect(error.code).to eq(401)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "#ignore" do
28
+ context "with success" do
29
+ it "ignore a pre_expense" do
30
+ result = client.pre_expenses.ignore(4)
31
+ expect(result.ignored_at).to_not be_nil
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "#restore" do
37
+ context "with success" do
38
+ it "restore a pre_expense" do
39
+ result = client.pre_expenses.restore(4)
40
+ expect(result.ignored_at).to be_nil
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#convert" do
46
+ let(:params) do
47
+ { amount: 129.65, currency: 'BRL', payer_id: 35, liquidate_through_advancement: 0 }
48
+ end
49
+
50
+ context "with success" do
51
+ it "creates a category successfully" do
52
+ result = client.pre_expenses.convert(2, params)
53
+ expect(result).to be_a(Rexpense::Entities::Expense)
54
+ expect(result.amount).to eq(129.65)
55
+ expect(result.pre_expense_id).to eq(2)
56
+ end
57
+ end
58
+
59
+ context "with error" do
60
+ it "raises Rexpense::RequestError with 422 status code" do
61
+ expect { client.pre_expenses.convert(3, {}) }.to raise_error(Rexpense::RequestError) do |error|
62
+ expect(error.code).to eq(422)
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ describe "#destroy" do
69
+ context "with success" do
70
+ it "destroy a category successfully" do
71
+ expect(client.pre_expenses.destroy(3)).to be_truthy
72
+ end
73
+ end
74
+
75
+ context "with error" do
76
+ it "raises Rexpense::RequestError with 404 status code" do
77
+ expect { client.pre_expenses.destroy(88888888) }.to raise_error(Rexpense::RequestError) do |error|
78
+ expect(error.code).to eq(404)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end