spearly-sdk-ruby 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +11 -6
- data/.rubocop.yml +3 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +8 -1
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/lib/spearly/auth/authorizer.rb +0 -1
- data/lib/spearly/auth/client.rb +34 -159
- data/lib/spearly/auth/team.rb +43 -12
- data/lib/spearly/auth/team_member.rb +28 -0
- data/lib/spearly/auth/team_subscription.rb +18 -0
- data/lib/spearly/auth/token.rb +18 -50
- data/lib/spearly/auth/user.rb +17 -55
- data/lib/spearly/auth.rb +2 -9
- data/lib/spearly/cloud/client.rb +2 -2
- data/lib/spearly/version.rb +1 -1
- data/spearly.gemspec +1 -8
- data/spec/spearly/auth/client_spec.rb +6 -74
- data/spec/spearly/auth/team_member_spec.rb +159 -0
- data/spec/spearly/auth/team_spec.rb +371 -0
- data/spec/spearly/auth/team_subscription_spec.rb +82 -0
- data/spec/spearly/auth/token_spec.rb +150 -0
- data/spec/spearly/auth/user_spec.rb +168 -0
- data/spec/spec_helper.rb +0 -1
- metadata +12 -92
- data/lib/spearly/auth/engine.rb +0 -13
- data/lib/spearly/auth/oauth_user.rb +0 -32
- data/lib/spearly/auth/rails/helpers.rb +0 -31
@@ -8,83 +8,15 @@ RSpec.describe Spearly::Auth::Client do
|
|
8
8
|
before do
|
9
9
|
stub_const('ENV', { 'SPEARLY_API_URL' => 'https://api.spearly.test' })
|
10
10
|
|
11
|
-
allow(Faraday).to receive(:
|
11
|
+
allow(Faraday).to receive(:new).and_return(connection_double)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
let!(:params) { { hey: 'jude' } }
|
17
|
-
let!(:client) { described_class.new('token') }
|
18
|
-
|
19
|
-
before do
|
20
|
-
allow(connection_double).to receive(:post).and_return(response_double)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'makes POST request to /teams' do
|
24
|
-
uri_parsed = Addressable::URI.parse('https://api.spearly.test/teams').normalize.to_s
|
25
|
-
|
26
|
-
expect(connection_double).to receive(:post).with(uri_parsed,
|
27
|
-
params.as_json,
|
28
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
29
|
-
'Authorization' => 'token')
|
30
|
-
|
31
|
-
described_class.new('token')
|
32
|
-
.create_team(params)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns data object if status is 201' do
|
36
|
-
res = client.create_team(params)
|
37
|
-
|
38
|
-
expect(res).to eq('id' => '711')
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns errors object if status is 422' do
|
42
|
-
response_double = instance_double(Faraday::Response, status: 422, body: { 'errors' => { 'owner' => ["can't own more than 2 free teams"] } }.to_json)
|
43
|
-
|
44
|
-
allow(connection_double).to receive(:post).and_return(response_double)
|
45
|
-
|
46
|
-
res = client.create_team(params)
|
47
|
-
|
48
|
-
expect(res['errors']).to eq('owner' => ["can't own more than 2 free teams"])
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '.get_team_subscriptions()' do
|
53
|
-
let!(:response_double) { instance_double(Faraday::Response, status: 200, body: { 'data' => [{ 'id' => 'sub_1' }] }.to_json) }
|
54
|
-
let!(:team_id) { '711' }
|
55
|
-
let!(:params) { { service_name: 'cms' } }
|
56
|
-
let!(:client) { described_class.new('token') }
|
57
|
-
|
58
|
-
before do
|
59
|
-
allow(connection_double).to receive(:get).and_return(response_double)
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'makes GET request to /teams/{team_id}/subscriptions' do
|
63
|
-
uri_parsed = Addressable::URI.parse('https://api.spearly.test/teams/711/subscriptions').normalize.to_s
|
64
|
-
|
65
|
-
expect(connection_double).to receive(:get).with(uri_parsed,
|
66
|
-
params.as_json,
|
67
|
-
'Accept' => 'application/vnd.spearly.v2+json',
|
68
|
-
'Authorization' => 'token')
|
14
|
+
it 'raises ServerError on Faraday::ConnectionFailed' do
|
15
|
+
allow(connection_double).to receive(:run_request).and_raise(Faraday::ConnectionFailed.new('Failed to open TCP connection to :80'))
|
69
16
|
|
17
|
+
expect do
|
70
18
|
described_class.new('token')
|
71
|
-
.
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'returns data object if status is 200' do
|
75
|
-
res = client.get_team_subscriptions(team_id, params)
|
76
|
-
|
77
|
-
expect(res).to eq('data' => [{ 'id' => 'sub_1' }])
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'returns empty array if status is not 200' do
|
81
|
-
response_double = instance_double(Faraday::Response, status: 404)
|
82
|
-
|
83
|
-
allow(connection_double).to receive(:get).and_return(response_double)
|
84
|
-
|
85
|
-
res = client.get_team_subscriptions(team_id, params)
|
86
|
-
|
87
|
-
expect(res).to eq []
|
88
|
-
end
|
19
|
+
.run_request(:method => :get, path: '/connection_failed')
|
20
|
+
end.to raise_error(Spearly::Auth::ServerError, 'Failed to open TCP connection to :80')
|
89
21
|
end
|
90
22
|
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Spearly::Auth::TeamMember do
|
6
|
+
let!(:connection_double) { instance_double(Faraday::Connection) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
stub_const('ENV', { 'SPEARLY_API_URL' => 'https://api.spearly.test' })
|
10
|
+
|
11
|
+
allow(Faraday).to receive(:new).and_return(connection_double)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.invite_user_to_team()' do
|
15
|
+
let!(:response_double) { instance_double(Faraday::Response, status: 201, body: { 'data' => { 'id' => 'team_invitation_1' } }.to_json) }
|
16
|
+
let!(:team_id) { '711' }
|
17
|
+
let!(:client) { Spearly::Auth::Client.new('token') }
|
18
|
+
|
19
|
+
let!(:params) do
|
20
|
+
{
|
21
|
+
email: 'hey@jude.test',
|
22
|
+
roles: {
|
23
|
+
cms: 'admin',
|
24
|
+
cloud: 'developer'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'makes POST request to /teams/:team_id/invite' do
|
34
|
+
uri_parsed = Addressable::URI.parse('/teams/711/invite').normalize.to_s
|
35
|
+
|
36
|
+
expect(connection_double).to receive(:run_request).with(:post,
|
37
|
+
uri_parsed,
|
38
|
+
params,
|
39
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
40
|
+
'Authorization' => 'token')
|
41
|
+
|
42
|
+
client.invite_user_to_team(team_id, params)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns data array if status is 201' do
|
46
|
+
res = client.invite_user_to_team(team_id, params)
|
47
|
+
|
48
|
+
expect(res).to eq('data' => { 'id' => 'team_invitation_1' })
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'throws AuthorizationError if 401' do
|
52
|
+
response_double = instance_double(Faraday::Response, status: 401)
|
53
|
+
|
54
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
55
|
+
|
56
|
+
expect do
|
57
|
+
client.invite_user_to_team(team_id, params)
|
58
|
+
end.to raise_error(Spearly::Auth::AuthorizationError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'throws NotFoundError if 404' do
|
62
|
+
response_double = instance_double(Faraday::Response, status: 404)
|
63
|
+
|
64
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
65
|
+
|
66
|
+
expect do
|
67
|
+
client.invite_user_to_team(team_id, params)
|
68
|
+
end.to raise_error(Spearly::Auth::NotFoundError)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'throws ServerError if 500' do
|
72
|
+
response_double = instance_double(Faraday::Response, status: 500)
|
73
|
+
|
74
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
75
|
+
|
76
|
+
expect do
|
77
|
+
client.invite_user_to_team(team_id, params)
|
78
|
+
end.to raise_error(Spearly::Auth::ServerError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'throws ServiceUnavailableError if 503' do
|
82
|
+
response_double = instance_double(Faraday::Response, status: 503)
|
83
|
+
|
84
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
85
|
+
|
86
|
+
expect do
|
87
|
+
client.invite_user_to_team(team_id, params)
|
88
|
+
end.to raise_error(Spearly::Auth::ServiceUnavailableError)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '.get_team_members()' do
|
93
|
+
let!(:response_double) { instance_double(Faraday::Response, status: 200, body: { 'data' => [{ 'id' => 'team_member_1' }] }.to_json) }
|
94
|
+
let!(:team_id) { '711' }
|
95
|
+
let!(:client) { Spearly::Auth::Client.new('token') }
|
96
|
+
|
97
|
+
before do
|
98
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'makes GET request to /teams/:team_id/members' do
|
102
|
+
uri_parsed = Addressable::URI.parse('/teams/711/members').normalize.to_s
|
103
|
+
|
104
|
+
expect(connection_double).to receive(:run_request).with(:get,
|
105
|
+
uri_parsed,
|
106
|
+
nil,
|
107
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
108
|
+
'Authorization' => 'token')
|
109
|
+
|
110
|
+
client.get_team_members(team_id)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'returns data array if status is 200' do
|
114
|
+
res = client.get_team_members(team_id)
|
115
|
+
|
116
|
+
expect(res).to eq('data' => [{ 'id' => 'team_member_1' }])
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'throws AuthorizationError if 401' do
|
120
|
+
response_double = instance_double(Faraday::Response, status: 401)
|
121
|
+
|
122
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
123
|
+
|
124
|
+
expect do
|
125
|
+
client.get_team_members(team_id)
|
126
|
+
end.to raise_error(Spearly::Auth::AuthorizationError)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'throws NotFoundError if 404' do
|
130
|
+
response_double = instance_double(Faraday::Response, status: 404)
|
131
|
+
|
132
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
133
|
+
|
134
|
+
expect do
|
135
|
+
client.get_team_members(team_id)
|
136
|
+
end.to raise_error(Spearly::Auth::NotFoundError)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'throws ServerError if 500' do
|
140
|
+
response_double = instance_double(Faraday::Response, status: 500)
|
141
|
+
|
142
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
143
|
+
|
144
|
+
expect do
|
145
|
+
client.get_team_members(team_id)
|
146
|
+
end.to raise_error(Spearly::Auth::ServerError)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'throws ServiceUnavailableError if 503' do
|
150
|
+
response_double = instance_double(Faraday::Response, status: 503)
|
151
|
+
|
152
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
153
|
+
|
154
|
+
expect do
|
155
|
+
client.get_team_members(team_id)
|
156
|
+
end.to raise_error(Spearly::Auth::ServiceUnavailableError)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,371 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Spearly::Auth::Team do
|
6
|
+
let!(:connection_double) { instance_double(Faraday::Connection) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
stub_const('ENV', { 'SPEARLY_API_URL' => 'https://api.spearly.test' })
|
10
|
+
|
11
|
+
allow(Faraday).to receive(:new).and_return(connection_double)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.create_team()' do
|
15
|
+
let!(:response_double) { instance_double(Faraday::Response, status: 201, body: { 'data' => { 'id' => 'team_1' } }.to_json) }
|
16
|
+
let!(:params) { { hey: 'jude' } }
|
17
|
+
let!(:client) { Spearly::Auth::Client.new('token') }
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'makes POST request to /teams' do
|
24
|
+
uri_parsed = Addressable::URI.parse('/teams').normalize.to_s
|
25
|
+
|
26
|
+
expect(connection_double).to receive(:run_request).with(:post,
|
27
|
+
uri_parsed,
|
28
|
+
params,
|
29
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
30
|
+
'Authorization' => 'token')
|
31
|
+
|
32
|
+
client.create_team(params)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns object if 201' do
|
36
|
+
res = client.create_team(params)
|
37
|
+
|
38
|
+
expect(res).to eq('data' => { 'id' => 'team_1' })
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns errors object if 422' do
|
42
|
+
response_double = instance_double(Faraday::Response, status: 422, body: { 'errors' => { 'owner' => ["can't own more than 2 free teams"] } }.to_json)
|
43
|
+
|
44
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
45
|
+
|
46
|
+
res = client.create_team(params)
|
47
|
+
|
48
|
+
expect(res['errors']).to eq('owner' => ["can't own more than 2 free teams"])
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'throws AuthorizationError if 401' do
|
52
|
+
response_double = instance_double(Faraday::Response, status: 401)
|
53
|
+
|
54
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
55
|
+
|
56
|
+
expect do
|
57
|
+
client.create_team(params)
|
58
|
+
end.to raise_error(Spearly::Auth::AuthorizationError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'throws NotFoundError if 404' do
|
62
|
+
response_double = instance_double(Faraday::Response, status: 404)
|
63
|
+
|
64
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
65
|
+
|
66
|
+
expect do
|
67
|
+
client.create_team(params)
|
68
|
+
end.to raise_error(Spearly::Auth::NotFoundError)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'throws ServerError if 500' do
|
72
|
+
response_double = instance_double(Faraday::Response, status: 500)
|
73
|
+
|
74
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
75
|
+
|
76
|
+
expect do
|
77
|
+
client.create_team(params)
|
78
|
+
end.to raise_error(Spearly::Auth::ServerError)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'throws ServiceUnavailableError if 503' do
|
82
|
+
response_double = instance_double(Faraday::Response, status: 503)
|
83
|
+
|
84
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
85
|
+
|
86
|
+
expect do
|
87
|
+
client.create_team(params)
|
88
|
+
end.to raise_error(Spearly::Auth::ServiceUnavailableError)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '.get_team()' do
|
93
|
+
let!(:response_double) { instance_double(Faraday::Response, status: 200, body: { 'data' => { 'id' => 'team_1' } }.to_json) }
|
94
|
+
let!(:team_id) { 'team_1' }
|
95
|
+
let!(:client) { Spearly::Auth::Client.new('token') }
|
96
|
+
|
97
|
+
before do
|
98
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'makes GET request to /teams/:team_id' do
|
102
|
+
uri_parsed = Addressable::URI.parse("/teams/#{team_id}").normalize.to_s
|
103
|
+
|
104
|
+
expect(connection_double).to receive(:run_request).with(:get,
|
105
|
+
uri_parsed,
|
106
|
+
nil,
|
107
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
108
|
+
'Authorization' => 'token')
|
109
|
+
|
110
|
+
client.get_team(team_id)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'returns data array if 200' do
|
114
|
+
res = client.get_team(team_id)
|
115
|
+
|
116
|
+
expect(res).to eq('data' => { 'id' => 'team_1' })
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'throws AuthorizationError if 401' do
|
120
|
+
response_double = instance_double(Faraday::Response, status: 401)
|
121
|
+
|
122
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
123
|
+
|
124
|
+
expect do
|
125
|
+
client.get_team(team_id)
|
126
|
+
end.to raise_error(Spearly::Auth::AuthorizationError)
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'throws NotFoundError if 404' do
|
130
|
+
response_double = instance_double(Faraday::Response, status: 404)
|
131
|
+
|
132
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
133
|
+
|
134
|
+
expect do
|
135
|
+
client.get_team(team_id)
|
136
|
+
end.to raise_error(Spearly::Auth::NotFoundError)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'throws ServerError if 500' do
|
140
|
+
response_double = instance_double(Faraday::Response, status: 500)
|
141
|
+
|
142
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
143
|
+
|
144
|
+
expect do
|
145
|
+
client.get_team(team_id)
|
146
|
+
end.to raise_error(Spearly::Auth::ServerError)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'throws ServiceUnavailableError if 503' do
|
150
|
+
response_double = instance_double(Faraday::Response, status: 503)
|
151
|
+
|
152
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
153
|
+
|
154
|
+
expect do
|
155
|
+
client.get_team(team_id)
|
156
|
+
end.to raise_error(Spearly::Auth::ServiceUnavailableError)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '.get_teams()' do
|
161
|
+
let!(:response_double) { instance_double(Faraday::Response, status: 200, body: { 'data' => [{ 'id' => 'team_1' }] }.to_json) }
|
162
|
+
let!(:params) { { service_name: 'cms' } }
|
163
|
+
let!(:client) { Spearly::Auth::Client.new('token') }
|
164
|
+
|
165
|
+
before do
|
166
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'makes GET request to /teams' do
|
170
|
+
uri_parsed = Addressable::URI.parse('/teams').normalize.to_s
|
171
|
+
|
172
|
+
expect(connection_double).to receive(:run_request).with(:get,
|
173
|
+
uri_parsed,
|
174
|
+
params,
|
175
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
176
|
+
'Authorization' => 'token')
|
177
|
+
|
178
|
+
client.get_teams(params)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'returns data array if 200' do
|
182
|
+
res = client.get_teams(params)
|
183
|
+
|
184
|
+
expect(res).to eq('data' => [{ 'id' => 'team_1' }])
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'throws AuthorizationError if 401' do
|
188
|
+
response_double = instance_double(Faraday::Response, status: 401)
|
189
|
+
|
190
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
191
|
+
|
192
|
+
expect do
|
193
|
+
client.get_teams(params)
|
194
|
+
end.to raise_error(Spearly::Auth::AuthorizationError)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'throws NotFoundError if 404' do
|
198
|
+
response_double = instance_double(Faraday::Response, status: 404)
|
199
|
+
|
200
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
201
|
+
|
202
|
+
expect do
|
203
|
+
client.get_teams(params)
|
204
|
+
end.to raise_error(Spearly::Auth::NotFoundError)
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'throws ServerError if 500' do
|
208
|
+
response_double = instance_double(Faraday::Response, status: 500)
|
209
|
+
|
210
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
211
|
+
|
212
|
+
expect do
|
213
|
+
client.get_teams(params)
|
214
|
+
end.to raise_error(Spearly::Auth::ServerError)
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'throws ServiceUnavailableError if 503' do
|
218
|
+
response_double = instance_double(Faraday::Response, status: 503)
|
219
|
+
|
220
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
221
|
+
|
222
|
+
expect do
|
223
|
+
client.get_teams(params)
|
224
|
+
end.to raise_error(Spearly::Auth::ServiceUnavailableError)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe '.update_team()' do
|
229
|
+
let!(:response_double) { instance_double(Faraday::Response, status: 200, body: { 'data' => { 'id' => 'team_1' } }.to_json) }
|
230
|
+
let!(:team_id) { 'team_1' }
|
231
|
+
let!(:client) { Spearly::Auth::Client.new('token') }
|
232
|
+
|
233
|
+
let!(:params) do
|
234
|
+
{
|
235
|
+
team: {
|
236
|
+
name: 'new name'
|
237
|
+
}
|
238
|
+
}
|
239
|
+
end
|
240
|
+
|
241
|
+
before do
|
242
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'makes PUT request to /teams/:team_id' do
|
246
|
+
uri_parsed = Addressable::URI.parse("/teams/#{team_id}").normalize.to_s
|
247
|
+
|
248
|
+
expect(connection_double).to receive(:run_request).with(:put,
|
249
|
+
uri_parsed,
|
250
|
+
params,
|
251
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
252
|
+
'Authorization' => 'token')
|
253
|
+
|
254
|
+
client.update_team(team_id, params)
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'returns data object if 200' do
|
258
|
+
res = client.update_team(team_id, params)
|
259
|
+
|
260
|
+
expect(res).to eq('data' => { 'id' => 'team_1' })
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'throws AuthorizationError if 401' do
|
264
|
+
response_double = instance_double(Faraday::Response, status: 401)
|
265
|
+
|
266
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
267
|
+
|
268
|
+
expect do
|
269
|
+
client.update_team(team_id, params)
|
270
|
+
end.to raise_error(Spearly::Auth::AuthorizationError)
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'throws NotFoundError if 404' do
|
274
|
+
response_double = instance_double(Faraday::Response, status: 404)
|
275
|
+
|
276
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
277
|
+
|
278
|
+
expect do
|
279
|
+
client.update_team(team_id, params)
|
280
|
+
end.to raise_error(Spearly::Auth::NotFoundError)
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'throws ServerError if 500' do
|
284
|
+
response_double = instance_double(Faraday::Response, status: 500)
|
285
|
+
|
286
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
287
|
+
|
288
|
+
expect do
|
289
|
+
client.update_team(team_id, params)
|
290
|
+
end.to raise_error(Spearly::Auth::ServerError)
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'throws ServiceUnavailableError if 503' do
|
294
|
+
response_double = instance_double(Faraday::Response, status: 503)
|
295
|
+
|
296
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
297
|
+
|
298
|
+
expect do
|
299
|
+
client.update_team(team_id, params)
|
300
|
+
end.to raise_error(Spearly::Auth::ServiceUnavailableError)
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
describe '.regenerate_team_api_access_token()' do
|
305
|
+
let!(:response_double) { instance_double(Faraday::Response, status: 200, body: { 'data' => { 'id' => 'team_1' } }.to_json) }
|
306
|
+
let!(:team_id) { 'team_1' }
|
307
|
+
let!(:client) { Spearly::Auth::Client.new('token') }
|
308
|
+
|
309
|
+
before do
|
310
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'makes GET request to /teams/:team_id/regenerate_api_access_token' do
|
314
|
+
uri_parsed = Addressable::URI.parse("/teams/#{team_id}/regenerate_api_access_token").normalize.to_s
|
315
|
+
|
316
|
+
expect(connection_double).to receive(:run_request).with(:get,
|
317
|
+
uri_parsed,
|
318
|
+
nil,
|
319
|
+
'Accept' => 'application/vnd.spearly.v2+json',
|
320
|
+
'Authorization' => 'token')
|
321
|
+
|
322
|
+
client.regenerate_team_api_access_token(team_id)
|
323
|
+
end
|
324
|
+
|
325
|
+
it 'returns data object if 200' do
|
326
|
+
res = client.regenerate_team_api_access_token(team_id)
|
327
|
+
|
328
|
+
expect(res).to eq('data' => { 'id' => 'team_1' })
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'throws AuthorizationError if 401' do
|
332
|
+
response_double = instance_double(Faraday::Response, status: 401)
|
333
|
+
|
334
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
335
|
+
|
336
|
+
expect do
|
337
|
+
client.regenerate_team_api_access_token(team_id)
|
338
|
+
end.to raise_error(Spearly::Auth::AuthorizationError)
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'throws NotFoundError if 404' do
|
342
|
+
response_double = instance_double(Faraday::Response, status: 404)
|
343
|
+
|
344
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
345
|
+
|
346
|
+
expect do
|
347
|
+
client.regenerate_team_api_access_token(team_id)
|
348
|
+
end.to raise_error(Spearly::Auth::NotFoundError)
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'throws ServerError if 500' do
|
352
|
+
response_double = instance_double(Faraday::Response, status: 500)
|
353
|
+
|
354
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
355
|
+
|
356
|
+
expect do
|
357
|
+
client.regenerate_team_api_access_token(team_id)
|
358
|
+
end.to raise_error(Spearly::Auth::ServerError)
|
359
|
+
end
|
360
|
+
|
361
|
+
it 'throws ServiceUnavailableError if 503' do
|
362
|
+
response_double = instance_double(Faraday::Response, status: 503)
|
363
|
+
|
364
|
+
allow(connection_double).to receive(:run_request).and_return(response_double)
|
365
|
+
|
366
|
+
expect do
|
367
|
+
client.regenerate_team_api_access_token(team_id)
|
368
|
+
end.to raise_error(Spearly::Auth::ServiceUnavailableError)
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|