freckle_io 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
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,132 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe FreckleIO::Client::Tags 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 tag for each response" do
14
+ results.last_responses.each do |last_response|
15
+ expect(last_response.body.first.keys).to eq TAG_KEYS
16
+ end
17
+ end
18
+ end
19
+
20
+ # describe "#show" do
21
+ # let(:result) { subject.show(ENV["REAL_FRECKLE_TAG_ID"]) }
22
+ # let(:response) { result.last_response }
23
+
24
+ # it "get a spacific tag" do
25
+ # expect(response.body.keys).to eq(TAG_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
+ billable: true,
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 billable" 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(:tag_validator) do
101
+ class_double(
102
+ FreckleIO::Validator::Tag,
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::Tag).to receive(
114
+ :validation
115
+ ).with({}, FreckleIO::Client::Tags::ALLOWED_KEYS) do
116
+ tag_validator
117
+ end
118
+
119
+ allow(FreckleIO::Validator::Tag).to receive(:errors)
120
+ allow(FreckleIO::Validator::Tag).to receive(:output)
121
+
122
+ result
123
+ end
124
+
125
+ it "call tag's validator" do
126
+ expect(FreckleIO::Validator::Tag).to have_received(
127
+ :validation
128
+ )
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,150 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe FreckleIO::Client::Users 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 user for each response" do
14
+ results.last_responses.each do |last_response|
15
+ expect(last_response.body.first.keys).to eq USER_KEYS
16
+ end
17
+ end
18
+ end
19
+
20
+ describe "#show" do
21
+ let(:result) { subject.show(ENV["REAL_FRECKLE_USER_ID"]) }
22
+ let(:response) { result.last_response }
23
+
24
+ it "get a spacific user" do
25
+ expect(response.body.keys).to eq(USER_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
+ email: "email@domain.com",
38
+ role: "coworker",
39
+ state: "active",
40
+ per_page: 8
41
+ }
42
+ end
43
+
44
+ let(:results) { subject.all(params) }
45
+
46
+ it "params should be valid" do
47
+ expect do
48
+ results
49
+ end.not_to raise_error
50
+ end
51
+ end
52
+
53
+ describe "with unknow params" do
54
+ let(:params) do
55
+ {
56
+ invalid_params: "oh! oh!"
57
+ }
58
+ end
59
+
60
+ let(:results) { subject.all(params) }
61
+
62
+ it "raises a invalid params error" do
63
+ expect do
64
+ results
65
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
66
+ end
67
+ end
68
+
69
+ describe "with wrong email" do
70
+ let(:params) do
71
+ {
72
+ email: "invalid_email"
73
+ }
74
+ end
75
+
76
+ let(:results) { subject.all(params) }
77
+
78
+ it "raises a invalid params error" do
79
+ expect do
80
+ results
81
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
82
+ end
83
+ end
84
+
85
+ describe "with wrong role" do
86
+ let(:params) do
87
+ {
88
+ role: "invalid_role"
89
+ }
90
+ end
91
+
92
+ let(:results) { subject.all(params) }
93
+
94
+ it "raises a invalid params error" do
95
+ expect do
96
+ results
97
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
98
+ end
99
+ end
100
+
101
+ describe "with state role" do
102
+ let(:params) do
103
+ {
104
+ state: "invalid_state"
105
+ }
106
+ end
107
+
108
+ let(:results) { subject.all(params) }
109
+
110
+ it "raises a invalid params error" do
111
+ expect do
112
+ results
113
+ end.to raise_error(FreckleIO::Errors::Params::InvalidParams)
114
+ end
115
+ end
116
+
117
+ describe "with validator" do
118
+ let(:user_validator) do
119
+ class_double(
120
+ FreckleIO::Validator::User,
121
+ errors: {},
122
+ output: {}
123
+ )
124
+ end
125
+
126
+ let(:result) do
127
+ subject.all
128
+ end
129
+
130
+ before do
131
+ allow(FreckleIO::Validator::User).to receive(
132
+ :validation
133
+ ).with({}, FreckleIO::Client::Users::ALLOWED_KEYS) do
134
+ user_validator
135
+ end
136
+
137
+ allow(FreckleIO::Validator::User).to receive(:errors)
138
+ allow(FreckleIO::Validator::User).to receive(:output)
139
+
140
+ result
141
+ end
142
+
143
+ it "call user's validator" do
144
+ expect(FreckleIO::Validator::User).to have_received(
145
+ :validation
146
+ )
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,70 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FreckleIO::Configuration do
4
+ context "with right configuration" do
5
+ before do
6
+ FreckleIO.reset
7
+ FreckleIO.configure do |config|
8
+ config.token = ENV["FRECKLE_TOKEN"]
9
+ config.url = ENV["FRECKLE_URL"]
10
+ end
11
+ end
12
+
13
+ it "return the correct token" do
14
+ expect(
15
+ FreckleIO.configuration.token
16
+ ).to eq ENV["FRECKLE_TOKEN"]
17
+ end
18
+
19
+ it "return the correct url" do
20
+ expect(
21
+ FreckleIO.configuration.url
22
+ ).to eq ENV["FRECKLE_URL"]
23
+ end
24
+ end
25
+
26
+ context "with wrong configuration" do
27
+ before do
28
+ FreckleIO.reset
29
+ FreckleIO.configure do |config|
30
+ config.auth_type = :wrong_type
31
+ end
32
+ end
33
+
34
+ it "raises a configuration error for authentication type" do
35
+ expect do
36
+ FreckleIO.configuration.auth_type
37
+ end.to raise_error(FreckleIO::Errors::Configuration)
38
+ end
39
+ end
40
+
41
+ context "without configuration" do
42
+ before do
43
+ FreckleIO.reset
44
+ end
45
+
46
+ it "raises a configuration error for token" do
47
+ expect do
48
+ FreckleIO.configuration.token
49
+ end.to raise_error(FreckleIO::Errors::Configuration)
50
+ end
51
+
52
+ it "raises a configuration error for authentication type" do
53
+ expect do
54
+ FreckleIO.configuration.auth_type
55
+ end.to raise_error(FreckleIO::Errors::Configuration)
56
+ end
57
+
58
+ it "raises a configuration error for max concurrency" do
59
+ expect do
60
+ FreckleIO.configuration.max_concurrency
61
+ end.to raise_error(FreckleIO::Errors::Configuration)
62
+ end
63
+
64
+ it "return default url" do
65
+ expect(
66
+ FreckleIO.configuration.url
67
+ ).to eq FreckleIO::Configuration::DEFAULT_URL
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,116 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FreckleIO::Connection do
4
+ context "with default configuration", :vcr do
5
+ let(:result) { subject.get("/v2/users") }
6
+
7
+ describe "with header" do
8
+ let(:ua) { result.env.request_headers["User-Agent"] }
9
+
10
+ it "set user agent" do
11
+ expect(ua).to eq "MyFreckleBot/1.0"
12
+ end
13
+ end
14
+
15
+ describe "with freckle token authentication" do
16
+ let(:header_token) { result.env.request_headers["X-FreckleToken"] }
17
+
18
+ it "set X-FreckleToken" do
19
+ expect(header_token).not_to be nil
20
+ end
21
+ end
22
+
23
+ describe "with too many request" do
24
+ # per_page = 1 raise Faraday::ClientError: the server responded
25
+ # with status 429 (Too Many Requests)
26
+ #
27
+ # HTTP/1.1 429 Too Many Requests
28
+ # Content-Type: text/html
29
+ # Retry-After: 3600
30
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429
31
+
32
+ xit "to implement"
33
+ end
34
+
35
+ describe "with page param" do
36
+ let(:result) { subject.get("/v2/users", params: {page: 2}) }
37
+
38
+ it "response must be success" do
39
+ expect(result.success?).to be(true)
40
+ end
41
+ end
42
+
43
+ describe "with per_page param" do
44
+ let(:per_page) { 8 }
45
+ let(:result) { subject.get("/v2/users", params: {per_page: per_page}) }
46
+
47
+ it "response must have per_page elements" do
48
+ expect(result.body.count).to eq(per_page)
49
+ end
50
+ end
51
+
52
+ describe "with invalid url" do
53
+ let(:invalid_resource) { subject.get("/invalid_url") }
54
+
55
+ it "raises a resource not found error for invalid resource" do
56
+ expect do
57
+ invalid_resource
58
+ end.to raise_error(FreckleIO::Errors::Connection::ResourceNotFound)
59
+ end
60
+ end
61
+
62
+ describe "with a valid response" do
63
+ it "must be a json format" do
64
+ expect(result.env.response_headers["Content-Type"]).to eq(
65
+ "application/json; charset=utf-8"
66
+ )
67
+ end
68
+ end
69
+ end
70
+
71
+ context "with exceptions" do
72
+ let(:invalid_request) { subject.get("/") }
73
+
74
+ describe "with invalid host" do
75
+ before do
76
+ allow(Faraday).to receive(:new).once.and_raise(
77
+ Faraday::ConnectionFailed, "Connection failed"
78
+ )
79
+ end
80
+
81
+ it "raises a connection error for invalid host" do
82
+ expect do
83
+ invalid_request
84
+ end.to raise_error(FreckleIO::Errors::Connection::Failed)
85
+ end
86
+ end
87
+
88
+ describe "with invalid resource" do
89
+ before do
90
+ allow(Faraday).to receive(:new).once.and_raise(
91
+ Faraday::ResourceNotFound, "Resource not found"
92
+ )
93
+ end
94
+
95
+ it "raises a connection error for invalid host" do
96
+ expect do
97
+ invalid_request
98
+ end.to raise_error(FreckleIO::Errors::Connection::ResourceNotFound)
99
+ end
100
+ end
101
+
102
+ describe "with client error" do
103
+ before do
104
+ allow(Faraday).to receive(:new).once.and_raise(
105
+ Faraday::ClientError, "Client error"
106
+ )
107
+ end
108
+
109
+ it "raises a connection error for invalid host" do
110
+ expect do
111
+ invalid_request
112
+ end.to raise_error(FreckleIO::Errors::Connection::ClientError)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,105 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FreckleIO::Paginator do
4
+ let(:result) { described_class.new(raw_links) }
5
+
6
+ describe "#next" do
7
+ let(:raw_links) do
8
+ "<https://api.letsfreckle.com/v2/users?page=1>; rel=\"first\",\
9
+ <https://api.letsfreckle.com/v2/users?page=2>; rel=\"next\""
10
+ end
11
+
12
+ it "returns link of next page" do
13
+ expect(result.next).to eq("/v2/users?page=2")
14
+ end
15
+ end
16
+
17
+ describe "#prev" do
18
+ let(:raw_links) do
19
+ "<https://api.letsfreckle.com/v2/users?page=1>; rel=\"prev\",\
20
+ <https://api.letsfreckle.com/v2/users?page=3>; rel=\"next\""
21
+ end
22
+
23
+ it "returns link of previous page" do
24
+ expect(result.prev).to eq("/v2/users?page=1")
25
+ end
26
+ end
27
+
28
+ describe "#last" do
29
+ let(:raw_links) do
30
+ "<https://api.letsfreckle.com/v2/users?page=1>; rel=\"prev\",\
31
+ <https://api.letsfreckle.com/v2/users?page=2>; rel=\"last\""
32
+ end
33
+
34
+ it "returns link of previous page" do
35
+ expect(result.last).to eq("/v2/users?page=2")
36
+ end
37
+ end
38
+
39
+ describe "#first" do
40
+ let(:raw_links) do
41
+ "<https://api.letsfreckle.com/v2/users?page=1>; rel=\"first\",\
42
+ <https://api.letsfreckle.com/v2/users?page=2>; rel=\"next\""
43
+ end
44
+
45
+ it "returns link of previous page" do
46
+ expect(result.first).to eq("/v2/users?page=1")
47
+ end
48
+ end
49
+
50
+ context "without void raw links" do
51
+ let(:raw_links) { "" }
52
+
53
+ describe "#next" do
54
+ it "return nil" do
55
+ expect(result.next).to eq(nil)
56
+ end
57
+ end
58
+
59
+ describe "#prev" do
60
+ it "return nil" do
61
+ expect(result.prev).to eq(nil)
62
+ end
63
+ end
64
+
65
+ describe "#last" do
66
+ it "return nil" do
67
+ expect(result.last).to eq(nil)
68
+ end
69
+ end
70
+
71
+ describe "#first" do
72
+ it "return nil" do
73
+ expect(result.first).to eq(nil)
74
+ end
75
+ end
76
+ end
77
+
78
+ context "without empty array raw links" do
79
+ let(:raw_links) { [] }
80
+
81
+ describe "#next" do
82
+ it "return nil" do
83
+ expect(result.next).to eq(nil)
84
+ end
85
+ end
86
+
87
+ describe "#prev" do
88
+ it "return nil" do
89
+ expect(result.prev).to eq(nil)
90
+ end
91
+ end
92
+
93
+ describe "#last" do
94
+ it "return nil" do
95
+ expect(result.last).to eq(nil)
96
+ end
97
+ end
98
+
99
+ describe "#first" do
100
+ it "return nil" do
101
+ expect(result.first).to eq(nil)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe FreckleIO::Params do
4
+ context "when invalid module" do
5
+ subject do
6
+ described_class.new({}, nil, "invalid_module").call
7
+ end
8
+
9
+ it "raises a invalid module error" do
10
+ expect do
11
+ subject
12
+ end.to raise_error(FreckleIO::Errors::Params::InvalidModule)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe FreckleIO::Request::MultiplePages do
4
+ context "with configuration", :vcr do
5
+ let(:result) { subject.get("/v2/users") }
6
+ let(:default_per_page) { 30 }
7
+
8
+ describe "#get" do
9
+ let(:last_responses) { result.last_responses }
10
+
11
+ it "returns an array of faraday response" do
12
+ expect(last_responses).to all(be_a(Faraday::Response))
13
+ end
14
+
15
+ it "returns freckle default per page elements" do
16
+ expect(last_responses.first.body.count).to eq(default_per_page)
17
+ end
18
+ end
19
+ end
20
+
21
+ context "with per page", :vcr do
22
+ before do
23
+ FreckleIO.configure do |config|
24
+ config.per_page = per_page
25
+ end
26
+ end
27
+
28
+ let(:per_page) { 19 }
29
+ let(:result) { subject.get("/v2/users") }
30
+
31
+ describe "#get" do
32
+ let(:last_responses) { result.last_responses }
33
+
34
+ it "return per page number elements" do
35
+ expect(last_responses.first.body.count).to eq(per_page)
36
+ end
37
+ end
38
+ end
39
+ end