freckle_io 0.0.3

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 (106) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +5 -0
  3. data/.env.sample +3 -0
  4. data/.env.test.sample +3 -0
  5. data/.gitignore +5 -0
  6. data/.rubocop.yml +67 -0
  7. data/.travis.yml +20 -0
  8. data/Gemfile +8 -0
  9. data/README.md +95 -0
  10. data/Rakefile +5 -0
  11. data/freckle-io.gemspec +37 -0
  12. data/icon.svg +192 -0
  13. data/lib/freckle_io/authentication.rb +26 -0
  14. data/lib/freckle_io/client/entries.rb +53 -0
  15. data/lib/freckle_io/client/project_groups.rb +36 -0
  16. data/lib/freckle_io/client/projects.rb +42 -0
  17. data/lib/freckle_io/client/tags.rb +33 -0
  18. data/lib/freckle_io/client/users.rb +35 -0
  19. data/lib/freckle_io/configuration.rb +48 -0
  20. data/lib/freckle_io/connection.rb +80 -0
  21. data/lib/freckle_io/errors/configuration.rb +5 -0
  22. data/lib/freckle_io/errors/connection.rb +9 -0
  23. data/lib/freckle_io/errors/params.rb +8 -0
  24. data/lib/freckle_io/paginator.rb +70 -0
  25. data/lib/freckle_io/params.rb +46 -0
  26. data/lib/freckle_io/request/multiple_pages.rb +62 -0
  27. data/lib/freckle_io/request/single_page.rb +73 -0
  28. data/lib/freckle_io/validator/entry.rb +57 -0
  29. data/lib/freckle_io/validator/project.rb +46 -0
  30. data/lib/freckle_io/validator/project_group.rb +30 -0
  31. data/lib/freckle_io/validator/restricted_hash.rb +11 -0
  32. data/lib/freckle_io/validator/tag.rb +30 -0
  33. data/lib/freckle_io/validator/user.rb +43 -0
  34. data/lib/freckle_io/validator/validation.yml +14 -0
  35. data/lib/freckle_io.rb +35 -0
  36. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +48 -0
  37. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/_all/returns_a_entry_for_each_response.yml +48 -0
  38. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/with_valid_params/params_should_be_valid.yml +48 -0
  39. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Entries/with_configuration/with_validator/call_entry_s_validator.yml +48 -0
  40. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +99 -0
  41. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/_all/returns_a_project_group_for_each_response.yml +99 -0
  42. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/with_valid_params/params_should_be_valid.yml +48 -0
  43. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_ProjectGroups/with_configuration/with_validator/call_project_group_s_validator.yml +99 -0
  44. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +491 -0
  45. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_all/returns_a_project_for_each_response.yml +491 -0
  46. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_show/get_a_spacific_project.yml +48 -0
  47. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/_show/raw_links_should_be_a_empty_array.yml +48 -0
  48. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/with_valid_params/params_should_be_valid.yml +48 -0
  49. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Projects/with_configuration/with_validator/call_project_s_validator.yml +491 -0
  50. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +48 -0
  51. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/_all/returns_a_tag_for_each_response.yml +48 -0
  52. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/with_valid_params/params_should_be_valid.yml +48 -0
  53. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Tags/with_configuration/with_validator/call_tag_s_validator.yml +48 -0
  54. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/_all/result_must_be_a_Request_MultiplePages.yml +99 -0
  55. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/_all/returns_a_user_for_each_response.yml +99 -0
  56. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/_show/get_a_spacific_user.yml +48 -0
  57. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/_show/raw_links_should_be_a_empty_array.yml +48 -0
  58. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/with_valid_params/params_should_be_valid.yml +48 -0
  59. data/spec/fixtures/vcr_cassettes/FreckleIO_Client_Users/with_configuration/with_validator/call_user_s_validator.yml +99 -0
  60. data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_a_valid_response/must_be_a_json_format.yml +51 -0
  61. data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_freckle_token_authentication/set_X-FreckleToken.yml +51 -0
  62. data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_header/set_user_agent.yml +51 -0
  63. data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_invalid_url/raises_a_resource_not_found_error_for_invalid_resource.yml +40 -0
  64. data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_page_param/response_must_be_success.yml +51 -0
  65. data/spec/fixtures/vcr_cassettes/FreckleIO_Connection/with_default_configuration/with_per_page_param/response_must_have_per_page_elements.yml +51 -0
  66. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_MultiplePages/with_configuration/_get/returns_an_array_of_faraday_response.yml +99 -0
  67. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_MultiplePages/with_configuration/_get/returns_freckle_default_per_page_elements.yml +99 -0
  68. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_MultiplePages/with_per_page/_get/return_per_page_number_elements.yml +148 -0
  69. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_first/next_page_should_be_a_SinglePage.yml +99 -0
  70. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_first/prev_page_should_be_nil.yml +51 -0
  71. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_first/when_get_last_page_from_the_first_page/next_should_be_nil.yml +99 -0
  72. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_get/returns_correct_raw_links_for_the_first_page.yml +51 -0
  73. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_last/next_page_should_be_nil.yml +99 -0
  74. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_last/returns_correct_raw_links_for_the_last_page.yml +99 -0
  75. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_last/when_get_prev_page_from_the_last_page/prev_should_be_nil.yml +147 -0
  76. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_next/previous_page_is_a_SinglePage.yml +147 -0
  77. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_next/previous_page_should_be_not_nil.yml +147 -0
  78. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_prev/next_page_is_a_SinglePage.yml +195 -0
  79. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_prev/when_get_prev_page_from_the_first_page/prev_should_be_nil.yml +147 -0
  80. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_total_page/with_first_page/returns_the_range_of_pages.yml +51 -0
  81. data/spec/fixtures/vcr_cassettes/FreckleIO_Request_SinglePage/with_configuration/_total_page/with_next_page/returns_an_empty_array.yml +99 -0
  82. data/spec/freckle_io/client/entries_spec.rb +359 -0
  83. data/spec/freckle_io/client/project_groups_spec.rb +132 -0
  84. data/spec/freckle_io/client/projects_spec.rb +183 -0
  85. data/spec/freckle_io/client/tags_spec.rb +132 -0
  86. data/spec/freckle_io/client/users_spec.rb +150 -0
  87. data/spec/freckle_io/configuration_spec.rb +70 -0
  88. data/spec/freckle_io/connection_spec.rb +116 -0
  89. data/spec/freckle_io/paginator_spec.rb +105 -0
  90. data/spec/freckle_io/params_spec.rb +15 -0
  91. data/spec/freckle_io/request/multiple_pages_spec.rb +39 -0
  92. data/spec/freckle_io/request/single_page_spec.rb +107 -0
  93. data/spec/spec_helper.rb +69 -0
  94. data/spec/support/anonymize/entries.rb +60 -0
  95. data/spec/support/anonymize/project_groups.rb +55 -0
  96. data/spec/support/anonymize/projects.rb +60 -0
  97. data/spec/support/anonymize/tags.rb +47 -0
  98. data/spec/support/anonymize/users.rb +59 -0
  99. data/spec/support/anonymize_interaction.rb +60 -0
  100. data/spec/support/entry_info.rb +19 -0
  101. data/spec/support/project_group_info.rb +13 -0
  102. data/spec/support/project_info.rb +26 -0
  103. data/spec/support/shared/links/raw_links.rb +13 -0
  104. data/spec/support/tag_info.rb +11 -0
  105. data/spec/support/user_info.rb +21 -0
  106. metadata +382 -0
@@ -0,0 +1,359 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe FreckleIO::Client::Entries do
4
+ context "with configuration", :vcr do
5
+ let(:params) do
6
+ {
7
+ updated_from: "2018-01-15T00:00:00Z",
8
+ updated_to: "2018-01-16T00:00:00Z"
9
+ }
10
+ end
11
+
12
+ describe "#all" do
13
+ let(:results) { subject.all(params) }
14
+ let(:first_response) { results.last_responses.first }
15
+
16
+ it "result must be a Request::MultiplePages" do
17
+ expect(results).to be_a(FreckleIO::Request::MultiplePages)
18
+ end
19
+
20
+ it "returns a entry for each response" do
21
+ results.last_responses.each do |last_response|
22
+ expect(last_response.body.first.keys).to eq ENTRY_KEYS
23
+ end
24
+ end
25
+ end
26
+
27
+ # not implemented ?
28
+ #
29
+ # describe "#show" do
30
+ # let(:result) { subject.show(ENV["REAL_FRECKLE_ENTRY_ID"]) }
31
+ # let(:response) { result.last_response }
32
+
33
+ # it "get a spacific entry" do
34
+ # expect(response.body.keys).to eq(ENTRY_KEYS)
35
+ # end
36
+
37
+ # it "raw links should be a empty array" do
38
+ # expect(result.raw_links).to be_empty
39
+ # end
40
+ # end
41
+
42
+ describe "with valid params" do
43
+ let(:params) do
44
+ {
45
+ user_ids: "1,2",
46
+ description: "aaa",
47
+ project_ids: "1,2",
48
+ tag_ids: "1,2",
49
+ tag_filter_type: "and",
50
+ from: "2018-01-01",
51
+ to: "2018-01-01",
52
+ updated_from: "2018-01-15T00:00:00Z",
53
+ updated_to: "2018-01-15T00:00:00Z",
54
+ billable: true,
55
+ approved_at_from: "2018-01-15T00:00:00Z",
56
+ approved_at_to: "2018-01-15T00:00:00Z",
57
+ approved_by_ids: "1,2",
58
+ per_page: 30
59
+ }
60
+ end
61
+
62
+ let(:results) { subject.all(params) }
63
+
64
+ it "params should be valid" do
65
+ expect do
66
+ results
67
+ end.not_to raise_error
68
+ end
69
+ end
70
+
71
+ describe "with unknow params" do
72
+ let(:params) do
73
+ {
74
+ invalid_params: "oh! oh!",
75
+ updated_from: "2018-01-15T00:00:00Z",
76
+ updated_to: "2018-01-16T00:00:00Z"
77
+ }
78
+ end
79
+
80
+ let(:results) { subject.all(params) }
81
+
82
+ it "raises a invalid params error" do
83
+ expect do
84
+ results
85
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
86
+ end
87
+ end
88
+
89
+ describe "with wrong user ids" do
90
+ let(:params) do
91
+ {
92
+ user_id: 1234,
93
+ updated_from: "2018-01-15T00:00:00Z",
94
+ updated_to: "2018-01-16T00:00:00Z"
95
+ }
96
+ end
97
+
98
+ let(:results) { subject.all(params) }
99
+
100
+ it "raises a invalid params error" do
101
+ expect do
102
+ results
103
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
104
+ end
105
+ end
106
+
107
+ describe "with wrong description" do
108
+ let(:params) do
109
+ {
110
+ description: 1234,
111
+ updated_from: "2018-01-15T00:00:00Z",
112
+ updated_to: "2018-01-16T00:00:00Z"
113
+ }
114
+ end
115
+
116
+ let(:results) { subject.all(params) }
117
+
118
+ it "raises a invalid params error" do
119
+ expect do
120
+ results
121
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
122
+ end
123
+ end
124
+
125
+ describe "with wrong project ids" do
126
+ let(:params) do
127
+ {
128
+ project_ids: 123,
129
+ updated_from: "2018-01-15T00:00:00Z",
130
+ updated_to: "2018-01-16T00:00:00Z"
131
+ }
132
+ end
133
+
134
+ let(:results) { subject.all(params) }
135
+
136
+ it "raises a invalid params error" do
137
+ expect do
138
+ results
139
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
140
+ end
141
+ end
142
+
143
+ describe "with wrong tag ids" do
144
+ let(:params) do
145
+ {
146
+ tag_ids: 12,
147
+ updated_from: "2018-01-15T00:00:00Z",
148
+ updated_to: "2018-01-16T00:00:00Z"
149
+ }
150
+ end
151
+
152
+ let(:results) { subject.all(params) }
153
+
154
+ it "raises a invalid params error" do
155
+ expect do
156
+ results
157
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
158
+ end
159
+ end
160
+
161
+ describe "with wrong tag filter type" do
162
+ let(:params) do
163
+ {
164
+ tag_filter_type: "or",
165
+ updated_from: "2018-01-15T00:00:00Z",
166
+ updated_to: "2018-01-16T00:00:00Z"
167
+ }
168
+ end
169
+
170
+ let(:results) { subject.all(params) }
171
+
172
+ it "raises a invalid params error" do
173
+ expect do
174
+ results
175
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
176
+ end
177
+ end
178
+
179
+ describe "with wrong from" do
180
+ let(:params) do
181
+ {
182
+ from: 123,
183
+ updated_from: "2018-01-15T00:00:00Z",
184
+ updated_to: "2018-01-16T00:00:00Z"
185
+ }
186
+ end
187
+
188
+ let(:results) { subject.all(params) }
189
+
190
+ it "raises a invalid params error" do
191
+ expect do
192
+ results
193
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
194
+ end
195
+ end
196
+
197
+ describe "with wrong to" do
198
+ let(:params) do
199
+ {
200
+ to: 123,
201
+ updated_from: "2018-01-15T00:00:00Z",
202
+ updated_to: "2018-01-16T00:00:00Z"
203
+ }
204
+ end
205
+
206
+ let(:results) { subject.all(params) }
207
+
208
+ it "raises a invalid params error" do
209
+ expect do
210
+ results
211
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
212
+ end
213
+ end
214
+
215
+ describe "with wrong updated from" do
216
+ let(:params) do
217
+ {
218
+ updated_from: 123
219
+ }
220
+ end
221
+
222
+ let(:results) { subject.all(params) }
223
+
224
+ it "raises a invalid params error" do
225
+ expect do
226
+ results
227
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
228
+ end
229
+ end
230
+
231
+ describe "with wrong updated to" do
232
+ let(:params) do
233
+ {
234
+ updated_to: 123
235
+ }
236
+ end
237
+
238
+ let(:results) { subject.all(params) }
239
+
240
+ it "raises a invalid params error" do
241
+ expect do
242
+ results
243
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
244
+ end
245
+ end
246
+
247
+ describe "with wrong billable" do
248
+ let(:params) do
249
+ {
250
+ tag_filter_type: 123,
251
+ updated_from: "2018-01-15T00:00:00Z",
252
+ updated_to: "2018-01-16T00:00:00Z"
253
+ }
254
+ end
255
+
256
+ let(:results) { subject.all(params) }
257
+
258
+ it "raises a invalid params error" do
259
+ expect do
260
+ results
261
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
262
+ end
263
+ end
264
+
265
+ describe "with wrong approved at from" do
266
+ let(:params) do
267
+ {
268
+ approved_at_from: 123,
269
+ updated_from: "2018-01-15T00:00:00Z",
270
+ updated_to: "2018-01-16T00:00:00Z"
271
+ }
272
+ end
273
+
274
+ let(:results) { subject.all(params) }
275
+
276
+ it "raises a invalid params error" do
277
+ expect do
278
+ results
279
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
280
+ end
281
+ end
282
+
283
+ describe "with wrong approved at to" do
284
+ let(:params) do
285
+ {
286
+ approved_at_to: 123,
287
+ updated_from: "2018-01-15T00:00:00Z",
288
+ updated_to: "2018-01-16T00:00:00Z"
289
+ }
290
+ end
291
+
292
+ let(:results) { subject.all(params) }
293
+
294
+ it "raises a invalid params error" do
295
+ expect do
296
+ results
297
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
298
+ end
299
+ end
300
+
301
+ describe "with wrong approved by ids" do
302
+ let(:params) do
303
+ {
304
+ approved_by_ids: 123,
305
+ updated_from: "2018-01-15T00:00:00Z",
306
+ updated_to: "2018-01-16T00:00:00Z"
307
+ }
308
+ end
309
+
310
+ let(:results) { subject.all(params) }
311
+
312
+ it "raises a invalid params error" do
313
+ expect do
314
+ results
315
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
316
+ end
317
+ end
318
+
319
+ describe "with validator" do
320
+ let(:entry_validator) do
321
+ class_double(
322
+ FreckleIO::Validator::Entry,
323
+ errors: {},
324
+ output: params
325
+ )
326
+ end
327
+
328
+ let(:params) do
329
+ {
330
+ updated_from: "2018-01-15T00:00:00Z",
331
+ updated_to: "2018-01-16T00:00:00Z"
332
+ }
333
+ end
334
+
335
+ let(:result) do
336
+ subject.all(params)
337
+ end
338
+
339
+ before do
340
+ allow(FreckleIO::Validator::Entry).to receive(
341
+ :validation
342
+ ).with(params, FreckleIO::Client::Entries::ALLOWED_KEYS) do
343
+ entry_validator
344
+ end
345
+
346
+ allow(FreckleIO::Validator::Entry).to receive(:errors)
347
+ allow(FreckleIO::Validator::Entry).to receive(:output)
348
+
349
+ result
350
+ end
351
+
352
+ it "call entry's validator" do
353
+ expect(FreckleIO::Validator::Entry).to have_received(
354
+ :validation
355
+ )
356
+ end
357
+ end
358
+ end
359
+ end
@@ -0,0 +1,132 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe FreckleIO::Client::ProjectGroups do
4
+ context "with configuration", :vcr do
5
+ describe "#all" do
6
+ let(:results) { subject.all }
7
+ let(:first_response) { results.last_responses.first }
8
+
9
+ it "result must be a Request::MultiplePages" do
10
+ expect(results).to be_a(FreckleIO::Request::MultiplePages)
11
+ end
12
+
13
+ it "returns a project group for each response" do
14
+ results.last_responses.each do |last_response|
15
+ expect(last_response.body.first.keys).to eq PROJECT_GROUP_KEYS
16
+ end
17
+ end
18
+ end
19
+
20
+ # describe "#show" do
21
+ # let(:result) { subject.show(ENV["REAL_FRECKLE_PROJECT_GROUP_ID"]) }
22
+ # let(:response) { result.last_response }
23
+
24
+ # it "get a spacific project group" do
25
+ # expect(response.body.keys).to eq(PROJECT_GROUP_KEYS)
26
+ # end
27
+
28
+ # it "raw links should be a empty array" do
29
+ # expect(result.raw_links).to be_empty
30
+ # end
31
+ # end
32
+
33
+ describe "with valid params" do
34
+ let(:params) do
35
+ {
36
+ name: "valid_string",
37
+ project_ids: "1,2,3",
38
+ per_page: 8
39
+ }
40
+ end
41
+
42
+ let(:results) { subject.all(params) }
43
+
44
+ it "params should be valid" do
45
+ expect do
46
+ results
47
+ end.not_to raise_error
48
+ end
49
+ end
50
+
51
+ describe "with unknow params" do
52
+ let(:params) do
53
+ {
54
+ invalid_params: "oh! oh!"
55
+ }
56
+ end
57
+
58
+ let(:results) { subject.all(params) }
59
+
60
+ it "raises a invalid params error" do
61
+ expect do
62
+ results
63
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
64
+ end
65
+ end
66
+
67
+ describe "with wrong name" do
68
+ let(:params) do
69
+ {
70
+ name: 123
71
+ }
72
+ end
73
+
74
+ let(:results) { subject.all(params) }
75
+
76
+ it "raises a invalid params error" do
77
+ expect do
78
+ results
79
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
80
+ end
81
+ end
82
+
83
+ describe "with project ids" do
84
+ let(:params) do
85
+ {
86
+ state: 123
87
+ }
88
+ end
89
+
90
+ let(:results) { subject.all(params) }
91
+
92
+ it "raises a invalid params error" do
93
+ expect do
94
+ results
95
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
96
+ end
97
+ end
98
+
99
+ describe "with validator" do
100
+ let(:project_group_validator) do
101
+ class_double(
102
+ FreckleIO::Validator::ProjectGroup,
103
+ errors: {},
104
+ output: {}
105
+ )
106
+ end
107
+
108
+ let(:result) do
109
+ subject.all
110
+ end
111
+
112
+ before do
113
+ allow(FreckleIO::Validator::ProjectGroup).to receive(
114
+ :validation
115
+ ).with({}, FreckleIO::Client::ProjectGroups::ALLOWED_KEYS) do
116
+ project_group_validator
117
+ end
118
+
119
+ allow(FreckleIO::Validator::ProjectGroup).to receive(:errors)
120
+ allow(FreckleIO::Validator::ProjectGroup).to receive(:output)
121
+
122
+ result
123
+ end
124
+
125
+ it "call project group's validator" do
126
+ expect(FreckleIO::Validator::ProjectGroup).to have_received(
127
+ :validation
128
+ )
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,183 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe FreckleIO::Client::Projects do
4
+ context "with configuration", :vcr do
5
+ describe "#all" do
6
+ let(:results) { subject.all }
7
+ let(:first_response) { results.last_responses.first }
8
+
9
+ it "result must be a Request::MultiplePages" do
10
+ expect(results).to be_a(FreckleIO::Request::MultiplePages)
11
+ end
12
+
13
+ it "returns a project for each response" do
14
+ results.last_responses.each do |last_response|
15
+ expect(last_response.body.first.keys).to eq PROJECT_KEYS
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "#show" do
21
+ let(:result) { subject.show(ENV["REAL_FRECKLE_PROJECT_ID"]) }
22
+ let(:response) { result.last_response }
23
+
24
+ it "get a spacific project" do
25
+ expect(response.body.keys).to eq(PROJECT_KEYS)
26
+ end
27
+
28
+ it "raw links should be a empty array" do
29
+ expect(result.raw_links).to be_empty
30
+ end
31
+ end
32
+
33
+ describe "with valid params" do
34
+ let(:params) do
35
+ {
36
+ name: "valid_string",
37
+ project_group_ids: "1",
38
+ billing_increment: "1",
39
+ enabled: true,
40
+ billable: true,
41
+ per_page: 30
42
+ }
43
+ end
44
+
45
+ let(:results) { subject.all(params) }
46
+
47
+ it "params should be valid" do
48
+ expect do
49
+ results
50
+ end.not_to raise_error
51
+ end
52
+ end
53
+
54
+ describe "with unknow params" do
55
+ let(:params) do
56
+ {
57
+ invalid_params: "oh! oh!"
58
+ }
59
+ end
60
+
61
+ let(:results) { subject.all(params) }
62
+
63
+ it "raises a invalid params error" do
64
+ expect do
65
+ results
66
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
67
+ end
68
+ end
69
+
70
+ describe "with wrong name" do
71
+ let(:params) do
72
+ {
73
+ email: 1234
74
+ }
75
+ end
76
+
77
+ let(:results) { subject.all(params) }
78
+
79
+ it "raises a invalid params error" do
80
+ expect do
81
+ results
82
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
83
+ end
84
+ end
85
+
86
+ describe "with wrong project group ids" do
87
+ let(:params) do
88
+ {
89
+ project_group_ids: 1234
90
+ }
91
+ end
92
+
93
+ let(:results) { subject.all(params) }
94
+
95
+ it "raises a invalid params error" do
96
+ expect do
97
+ results
98
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
99
+ end
100
+ end
101
+
102
+ describe "with wrong billing increment" do
103
+ let(:params) do
104
+ {
105
+ billing_increment: "1,3,7"
106
+ }
107
+ end
108
+
109
+ let(:results) { subject.all(params) }
110
+
111
+ it "raises a invalid params error" do
112
+ expect do
113
+ results
114
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
115
+ end
116
+ end
117
+
118
+ describe "with wrong enabled" do
119
+ let(:params) do
120
+ {
121
+ enabled: "oh! oh!"
122
+ }
123
+ end
124
+
125
+ let(:results) { subject.all(params) }
126
+
127
+ it "raises a invalid params error" do
128
+ expect do
129
+ results
130
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
131
+ end
132
+ end
133
+
134
+ describe "with wrong billable" do
135
+ let(:params) do
136
+ {
137
+ billable: "oh! oh!"
138
+ }
139
+ end
140
+
141
+ let(:results) { subject.all(params) }
142
+
143
+ it "raises a invalid params error" do
144
+ expect do
145
+ results
146
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
147
+ end
148
+ end
149
+
150
+ describe "with validator" do
151
+ let(:project_validator) do
152
+ class_double(
153
+ FreckleIO::Validator::Project,
154
+ errors: {},
155
+ output: {}
156
+ )
157
+ end
158
+
159
+ let(:result) do
160
+ subject.all
161
+ end
162
+
163
+ before do
164
+ allow(FreckleIO::Validator::Project).to receive(
165
+ :validation
166
+ ).with({}, FreckleIO::Client::Projects::ALLOWED_KEYS) do
167
+ project_validator
168
+ end
169
+
170
+ allow(FreckleIO::Validator::Project).to receive(:errors)
171
+ allow(FreckleIO::Validator::Project).to receive(:output)
172
+
173
+ result
174
+ end
175
+
176
+ it "call project's validator" do
177
+ expect(FreckleIO::Validator::Project).to have_received(
178
+ :validation
179
+ )
180
+ end
181
+ end
182
+ end
183
+ end