omniauth-applicaster 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edf87dd26be860aed8bf8c56e8563eeb6527edcb
4
- data.tar.gz: 0b16b09ea5d7033268eea2159d602eb84b2df0a0
3
+ metadata.gz: f0ac378a39c598eb3656c8065628155e0b61bfde
4
+ data.tar.gz: 765f8acd6f8fac276beb05d58c91c218e64dc1d1
5
5
  SHA512:
6
- metadata.gz: 12da0d51621807af0deccab136ec6e1e6fe8f21f569dfe2b6e1866595d194fa2657efb92ac05ae515763156476e43ab25a85e34acededd12f7a81ff7db27701a
7
- data.tar.gz: fb117f61e5020c553f60549584dfac6f027d1cfe78acc37fe97344fc10ec1933a28caff99ddab3d1a45af96217c747d6fbb53a3731deff4f34609c51b17422da
6
+ metadata.gz: 0486f7b9d14805c576d94ed13bc0bf84b26714123316360fc8bfb6473bfc2257b0ebb9f86169b486b38294f698c0cdc180e413004dba5fef5f3b73538ba562c4
7
+ data.tar.gz: 5d932c806d173728e1a389700b55e21253bb4566d65f99194933ea10da974890bd0e9c0605b402f54731de59f05c567bb7941aff3cef26ff59b12ce83ecfe7a8
data/README.md CHANGED
@@ -97,6 +97,14 @@ service.accounts.each do |account|
97
97
  end
98
98
  ```
99
99
 
100
+ #### Get user by id
101
+
102
+ ```ruby
103
+ service = Applicaster::Accounts.new
104
+ user = service.find_user_by_id(user_id)
105
+ # user is an Applicaster::Accounts::User instance
106
+ ```
107
+
100
108
  #### Get a user using an access token
101
109
 
102
110
  ```ruby
@@ -125,6 +133,7 @@ end
125
133
 
126
134
  You can use `accounts_mock_data` to access the fake data, for example:
127
135
  `accounts_mock_data.all_accounts_attributes.first`
136
+ `accounts_mock_data.user_attributes`
128
137
 
129
138
  in example groups that use the client_credentials flow use:
130
139
  ```ruby
@@ -134,6 +143,21 @@ before do
134
143
  end
135
144
  ```
136
145
 
146
+ in tests that use `find_user_by_id` method you can do the following:
147
+ ```ruby
148
+
149
+ let(:user) { accounts_mock_data.user_attributes }
150
+ let(:accounts_service) { Applicaster::Accounts.new }
151
+
152
+ before do
153
+ stub_client_credentials_request
154
+ stub_accounts_user_show_response(user: user, token: client_credentials_token)
155
+ end
156
+
157
+ it "..." do
158
+ expect(accounts_service.find_user_by_id(user[:id])).to ...
159
+ end
160
+ ```
137
161
 
138
162
 
139
163
  ## Contributing
@@ -60,6 +60,14 @@ module Applicaster
60
60
  end
61
61
  end
62
62
 
63
+ def user_by_id_and_token(id, token)
64
+ Applicaster::Accounts::User.new(
65
+ connection(token: token)
66
+ .get("/api/v1/users/#{id}.json")
67
+ .body
68
+ )
69
+ end
70
+
63
71
  def accounts_from_token(token)
64
72
  connection(token: token)
65
73
  .get("/api/v1/accounts.json")
@@ -93,6 +101,10 @@ module Applicaster
93
101
  self.class.accounts_from_token(client_credentials_token.token)
94
102
  end
95
103
 
104
+ def find_user_by_id(id)
105
+ self.class.user_by_id_and_token(id, client_credentials_token.token)
106
+ end
107
+
96
108
  def connection(*args)
97
109
  self.class.connection(*args)
98
110
  end
@@ -13,6 +13,15 @@ module Applicaster
13
13
  }
14
14
  end
15
15
  end
16
+
17
+ def user_attributes
18
+ id = Test.inc_sequence
19
+ {
20
+ id: id,
21
+ name: "Test User #{id}",
22
+ email: "test-user#{id}@example.com",
23
+ }
24
+ end
16
25
  end
17
26
  end
18
27
  end
@@ -9,6 +9,14 @@ module Applicaster
9
9
  module Test
10
10
  module Accounts
11
11
  module WebMockHelper
12
+ def stub_accounts_user_show_response(options = {})
13
+ user = options[:user] || accounts_mock_data.user_attributes
14
+
15
+ stub_request(:get, accounts_base_url.join("/api/v1/users/#{user[:id]}.json"))
16
+ .with(query: { access_token: options[:token] })
17
+ .to_return(successful_json_response(user))
18
+ end
19
+
12
20
  def stub_accounts_index_response(options = {})
13
21
  accounts = options[:accounts] || accounts_mock_data.all_accounts_attributes
14
22
 
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Applicaster
3
- VERSION = "1.5.2"
3
+ VERSION = "1.6.0"
4
4
  end
5
5
  end
@@ -106,6 +106,35 @@ RSpec.describe Applicaster::Accounts do
106
106
  end
107
107
  end
108
108
 
109
+ describe ".user_by_id_and_token" do
110
+ let(:user_id) { 11 }
111
+ let(:return_value) { Applicaster::Accounts.user_by_id_and_token(user_id, token) }
112
+
113
+ context "when token is valid" do
114
+ let(:token) { "valid-access-token" }
115
+
116
+ before do
117
+ stub_user_show_request(user_id, token)
118
+ end
119
+
120
+ it "returns an Applicaster::Accounts::User instance" do
121
+ expect(return_value).to be_kind_of(Applicaster::Accounts::User)
122
+ end
123
+ end
124
+
125
+ context "when token is invalid" do
126
+ let(:token) { "invalid-access-token" }
127
+
128
+ before do
129
+ stub_user_show_request_with_invalid_token(user_id, token)
130
+ end
131
+
132
+ it "fails with Faraday::ClientError" do
133
+ expect { return_value }.to raise_error(Faraday::ClientError)
134
+ end
135
+ end
136
+ end
137
+
109
138
  describe ".accounts_from_token" do
110
139
  let(:token) { "valid-access-token" }
111
140
  let(:return_value) { Applicaster::Accounts.accounts_from_token(token) }
@@ -161,6 +190,20 @@ RSpec.describe Applicaster::Accounts do
161
190
  end
162
191
  end
163
192
 
193
+ describe "#find_user_by_id" do
194
+ let(:user_id) { 11 }
195
+
196
+ before do
197
+ stub_client_credentials_request
198
+ stub_user_show_request(user_id, "client-credentials-token")
199
+ end
200
+
201
+ it "returns User object" do
202
+ expect(accounts_service.find_user_by_id(user_id))
203
+ .to be_kind_of(Applicaster::Accounts::User)
204
+ end
205
+ end
206
+
164
207
  def stub_accounts_index_request(token)
165
208
  stub_request(:get, "https://#{accounts_host}/api/v1/accounts.json").
166
209
  with(query: { access_token: token }).
@@ -17,4 +17,12 @@ RSpec.describe Applicaster::Test::Accounts::MockData do
17
17
  it { is_expected.to include(name: /Test Account \d+/) }
18
18
  end
19
19
  end
20
+
21
+ describe "#user_attributes" do
22
+ subject(:user) { mock_data.user_attributes }
23
+
24
+ it { is_expected.to include(:id) }
25
+ it { is_expected.to include(name: /\ATest User \d+\z/) }
26
+ it { is_expected.to include(email: /\Atest-user\d+@example.com\z/) }
27
+ end
20
28
  end
@@ -4,6 +4,7 @@ RSpec.describe Applicaster::Test::Accounts::WebMockHelper do
4
4
  let(:including_class) { Class.new { include(Applicaster::Test::Accounts::WebMockHelper) } }
5
5
  subject(:instace) { including_class.new }
6
6
 
7
+ it { is_expected.to respond_to(:stub_accounts_user_show_response) }
7
8
  it { is_expected.to respond_to(:stub_accounts_index_response) }
8
9
  it { is_expected.to respond_to(:stub_client_credentials_request) }
9
10
  it { is_expected.to respond_to(:accounts_mock_data) }
@@ -25,6 +25,18 @@ module WebmockStubsHelper
25
25
  .to_return(status: 401, body: "")
26
26
  end
27
27
 
28
+ def stub_user_show_request_with_invalid_token(user_id, token)
29
+ stub_request(:get, "https://#{accounts_host}/api/v1/users/#{user_id}.json")
30
+ .with(query: { access_token: token })
31
+ .to_return(status: 401, body: "")
32
+ end
33
+
34
+ def stub_user_show_request(user_id, token)
35
+ stub_request(:get, "https://#{accounts_host}/api/v1/users/#{user_id}.json").
36
+ with(query: { access_token: token }).
37
+ to_return(successful_json_response(mock_user_response))
38
+ end
39
+
28
40
  def accounts_host
29
41
  "accounts.applicaster.com"
30
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-applicaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neer Friedman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler