user_management_api 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/README.md +90 -0
- data/Rakefile +114 -0
- data/lib/user_management_api.rb +38 -0
- data/lib/user_management_api/answerbase_session_token.rb +6 -0
- data/lib/user_management_api/client.rb +108 -0
- data/lib/user_management_api/client_methods/answerbase_session_tokens.rb +15 -0
- data/lib/user_management_api/client_methods/registration_groups.rb +38 -0
- data/lib/user_management_api/client_methods/registrations.rb +54 -0
- data/lib/user_management_api/client_methods/urls.rb +65 -0
- data/lib/user_management_api/client_methods/users.rb +24 -0
- data/lib/user_management_api/config.rb +13 -0
- data/lib/user_management_api/connection_manager.rb +17 -0
- data/lib/user_management_api/entity.rb +132 -0
- data/lib/user_management_api/errors.rb +49 -0
- data/lib/user_management_api/lookup.rb +6 -0
- data/lib/user_management_api/paged_collection.rb +16 -0
- data/lib/user_management_api/railtie.rb +8 -0
- data/lib/user_management_api/registration.rb +20 -0
- data/lib/user_management_api/registration_group.rb +8 -0
- data/lib/user_management_api/user.rb +6 -0
- data/lib/user_management_api/version.rb +3 -0
- data/spec/integration/registration_groups_spec.rb +30 -0
- data/spec/integration/registrations_spec.rb +44 -0
- data/spec/integration/users_spec.rb +63 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/client_context.rb +12 -0
- data/spec/support/integration_context.rb +29 -0
- data/spec/unit/client_methods/answerbase_session_tokens_spec.rb +68 -0
- data/spec/unit/client_methods/registration_groups_spec.rb +157 -0
- data/spec/unit/client_methods/registrations_spec.rb +131 -0
- data/spec/unit/client_methods/users_spec.rb +149 -0
- data/spec/unit/client_spec.rb +121 -0
- data/spec/unit/connection_manager_spec.rb +23 -0
- data/spec/unit/entity_spec.rb +93 -0
- data/spec/unit/registration_spec.rb +25 -0
- data/user_management_api.gemspec +32 -0
- metadata +264 -0
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'Registration Groups', integration: true do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
users = client.users_by_email(['owner@tet.com', 'enrolled1@tet.com', 'enrolled2@tet.com'])
|
7
|
+
@owner = users.detect { |u| u.email == 'owner@tet.com' }
|
8
|
+
@enrolled1 = users.detect { |u| u.email == 'enrolled1@tet.com' }
|
9
|
+
@enrolled2 = users.detect { |u| u.email == 'enrolled2@tet.com' }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'returns data for group owners' do
|
13
|
+
data = client.owned_registration_groups('cps', @owner.unique_id)
|
14
|
+
expect(data.length).to eq 1
|
15
|
+
expect(data.first).to be_a UserManagementApi::RegistrationGroup
|
16
|
+
expect(data.first.owner.unique_id).to eq @owner.unique_id
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns data for group enrollees' do
|
20
|
+
data = client.enrolled_registration_groups('cps', @enrolled1.unique_id)
|
21
|
+
expect(data.length).to eq 1
|
22
|
+
expect(data.first).to be_a UserManagementApi::RegistrationGroup
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns data for pending groups' do
|
26
|
+
data = client.pending_registration_groups('cps')
|
27
|
+
expect(data.length).to eq 3
|
28
|
+
expect(data.first).to be_a UserManagementApi::RegistrationGroup
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'Registrations', integration: true do
|
4
|
+
|
5
|
+
describe 'search' do
|
6
|
+
|
7
|
+
it 'returns a page of data given no criteria' do
|
8
|
+
data = client.search_registrations('usa')
|
9
|
+
expect(data.length).to eq 25
|
10
|
+
expect(data.current_page).to eq 1
|
11
|
+
expect(data.first).to be_a UserManagementApi::Registration
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns a page of data given a page size' do
|
15
|
+
data = client.search_registrations('usa', per: 20)
|
16
|
+
expect(data.length).to eq 20
|
17
|
+
expect(data.total_pages).to eq 2
|
18
|
+
expect(data.first).to be_a UserManagementApi::Registration
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'set_registration_custom_attributes' do
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
@user = client.users_by_email('owner@tet.com').first
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'correctly updates custom attributes' do
|
30
|
+
reg = client.user_registration('cps', @user.unique_id)
|
31
|
+
expect(reg.custom_attributes).to eq({})
|
32
|
+
|
33
|
+
reg = client.set_registration_custom_attributes('cps', @user.unique_id, {key1: 'value1', key2: 'value2'})
|
34
|
+
|
35
|
+
expect(reg.custom_attributes).to eq({'key1' => 'value1', 'key2' => 'value2'})
|
36
|
+
|
37
|
+
reg = client.set_registration_custom_attributes('cps', @user.unique_id, {key1: 'value1-updated', key2: ''})
|
38
|
+
|
39
|
+
expect(reg.custom_attributes).to eq({'key1' => 'value1-updated'})
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'Users', integration: true do
|
4
|
+
|
5
|
+
describe 'User Retrieval' do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@user = client.create_user(UserManagementApi::User.new({email: "#{SecureRandom.uuid}@example.com", first_name: 'Eddie', last_name: 'Dean', password: '1nine9teen'}))
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should retrieve a user' do
|
12
|
+
user = client.user(@user.unique_id)
|
13
|
+
expect(user).not_to be_nil
|
14
|
+
expect(user.unique_id).to eq @user.unique_id
|
15
|
+
expect(user.email).to eq @user.email
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return nil for an invalid id' do
|
19
|
+
user = client.user('abc123')
|
20
|
+
expect(user).to be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'User Creation' do
|
26
|
+
it 'should create and return a user' do
|
27
|
+
user = client.create_user(UserManagementApi::User.new({email: "#{SecureRandom.uuid}@example.com", first_name: 'Eddie', last_name: 'Dean', password: '1nine9teen'}))
|
28
|
+
found = client.user(user.unique_id)
|
29
|
+
expect(found).not_to be_nil
|
30
|
+
expect(found.email).to eq user.email
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise UnprocessableEntityError with an invalid user' do
|
34
|
+
expect { client.create_user(UserManagementApi::User.new({email: "#{SecureRandom.uuid}@example.com"})) }.to raise_error(UserManagementApi::UnprocessableEntityError) do |error|
|
35
|
+
expect(error.errors).not_to be_nil
|
36
|
+
expect(error.errors['first_name']).not_to be_nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'User Updates' do
|
42
|
+
|
43
|
+
before(:each) do
|
44
|
+
@user = client.create_user(UserManagementApi::User.new({email: "#{SecureRandom.uuid}@example.com", first_name: 'Eddie', last_name: 'Dean', password: '1nine9teen'}))
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should update and return a user' do
|
48
|
+
@user.first_name = 'Edward'
|
49
|
+
u = client.update_user(@user)
|
50
|
+
expect(u.last_name).to eq 'Dean'
|
51
|
+
expect(u.first_name).to eq 'Edward'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should raise UnprocessableEntityError with an invalid user' do
|
55
|
+
@user.first_name = nil
|
56
|
+
expect { client.update_user(@user) }.to raise_error(UserManagementApi::UnprocessableEntityError) do |error|
|
57
|
+
expect(error.errors).not_to be_nil
|
58
|
+
expect(error.errors['first_name']).not_to be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'oj'
|
4
|
+
require 'simplecov'
|
5
|
+
require 'simplecov-rcov'
|
6
|
+
|
7
|
+
MultiJson.use :oj
|
8
|
+
|
9
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter '/spec/'
|
12
|
+
add_filter '/vendor/bundle'
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'rspec'
|
16
|
+
require 'webmock/rspec'
|
17
|
+
require File.expand_path('../../lib/user_management_api', __FILE__)
|
18
|
+
|
19
|
+
Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
|
23
|
+
config.add_setting :uma_port, default: ENV['UMA_PORT'] || 3000
|
24
|
+
|
25
|
+
config.filter_run_excluding :integration unless ENV['ENABLE_INTEGRATION'] == 'true'
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
|
2
|
+
RSpec.shared_context "client context" do
|
3
|
+
let(:uri) { 'http://example.com' }
|
4
|
+
let(:token) { 'token' }
|
5
|
+
let(:client) { UserManagementApi::Client.new(uri, token) }
|
6
|
+
let(:base_uri) { client.base_api_uri }
|
7
|
+
|
8
|
+
let(:day) { 60 * 60 * 24 }
|
9
|
+
|
10
|
+
let(:unique_id) { SecureRandom.uuid }
|
11
|
+
let(:user_json) { { unique_id: "#{unique_id}", email: "roland@tet.com", first_name: "Roland", last_name: "Deschain" } }
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
RSpec.shared_context("integration context", { integration: true }) do
|
3
|
+
|
4
|
+
# Disable WebMocks and make requests to the real deal
|
5
|
+
before(:all) do
|
6
|
+
WebMock.disable!
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:all) do
|
10
|
+
WebMock.enable!
|
11
|
+
end
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
# Assume there's a UserManagementApp running in the integration_test env on localhost
|
15
|
+
uri = "http://localhost:#{RSpec.configuration.uma_port}"
|
16
|
+
|
17
|
+
# Reseed the UMA app
|
18
|
+
Faraday.get("#{uri}/integration_test/reseed")
|
19
|
+
|
20
|
+
# Magic test token. See UserManagementApp/lib/integration_test_seeder.rb
|
21
|
+
token = '00000000-1111-2222-3333-444444444444'
|
22
|
+
@client = UserManagementApi::Client.new(uri, token)
|
23
|
+
end
|
24
|
+
|
25
|
+
def client
|
26
|
+
@client
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe UserManagementApi::ClientMethods::AnswerbaseSessionTokens do
|
4
|
+
|
5
|
+
include_context 'client context'
|
6
|
+
|
7
|
+
let(:session_id) { SecureRandom::uuid }
|
8
|
+
let(:token_json) { {user_unique_id: unique_id, session_id: session_id, created_at: Time.now, updated_at: Time.now} }
|
9
|
+
|
10
|
+
describe '#answerbase_session_token' do
|
11
|
+
|
12
|
+
it 'makes a GET request to the correct URL' do
|
13
|
+
stub = stub_request(:get, "#{base_uri}/answerbase_session_tokens/#{session_id}")
|
14
|
+
client.answerbase_session_token(session_id)
|
15
|
+
|
16
|
+
expect(stub).to have_been_requested.times(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns nil when an invalid id is passed' do
|
20
|
+
stub = stub_request(:get, "#{base_uri}/answerbase_session_tokens/#{session_id}").to_return(:status => 404)
|
21
|
+
|
22
|
+
expect(client.answerbase_session_token(session_id)).to be_nil
|
23
|
+
|
24
|
+
expect(stub).to have_been_requested.times(1)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns a AnswerbaseSessionToken object' do
|
28
|
+
stub = stub_request(:get, "#{base_uri}/answerbase_session_tokens/#{session_id}").to_return(body: MultiJson.dump(token_json))
|
29
|
+
|
30
|
+
token = client.answerbase_session_token(session_id)
|
31
|
+
|
32
|
+
expect(token).not_to be_nil
|
33
|
+
expect(token).to be_a(UserManagementApi::AnswerbaseSessionToken)
|
34
|
+
expect(token.session_id).to eq session_id
|
35
|
+
|
36
|
+
expect(stub).to have_been_requested.times(1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#create_answerbase_session_token' do
|
41
|
+
it 'makes a POST to the correct url' do
|
42
|
+
stub = stub_request(:post, "#{base_uri}/answerbase_session_tokens/#{unique_id}")
|
43
|
+
client.create_answerbase_session_token(unique_id)
|
44
|
+
|
45
|
+
expect(stub).to have_been_requested.times(1)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raises a UnprocessableEntityError on a 422' do
|
49
|
+
stub = stub_request(:post, "#{base_uri}/answerbase_session_tokens/junk").to_return(status: 422, body: MultiJson.dump({session_id: ['Cannot be blank']}))
|
50
|
+
|
51
|
+
expect { client.create_answerbase_session_token('junk') }.to raise_error(UserManagementApi::UnprocessableEntityError)
|
52
|
+
|
53
|
+
expect(stub).to have_been_requested.times(1)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns a AnswerbaseSessionToken object' do
|
57
|
+
stub = stub_request(:post, "#{base_uri}/answerbase_session_tokens/#{unique_id}").to_return(body: MultiJson.dump(token_json))
|
58
|
+
|
59
|
+
token = client.create_answerbase_session_token(unique_id)
|
60
|
+
|
61
|
+
expect(token).not_to be_nil
|
62
|
+
expect(token).to be_a(UserManagementApi::AnswerbaseSessionToken)
|
63
|
+
|
64
|
+
expect(stub).to have_been_requested.times(1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe UserManagementApi::ClientMethods::RegistrationGroups do
|
4
|
+
|
5
|
+
include_context 'client context'
|
6
|
+
|
7
|
+
let(:registration_group_json) { { unique_id: SecureRandom.uuid, name: 'Group', project: 'cps', end_date: Time.now + day, active: true, created_at: Time.now, updated_at: Time.now, owner: user_json } }
|
8
|
+
|
9
|
+
describe '#owned_registration_groups' do
|
10
|
+
let(:url) { "#{base_uri}/registration_groups/cps/owned/#{unique_id}" }
|
11
|
+
|
12
|
+
it 'makes a GET request to the correct URL' do
|
13
|
+
stub = stub_request(:get, url)
|
14
|
+
client.owned_registration_groups('cps', unique_id)
|
15
|
+
|
16
|
+
expect(stub).to have_been_requested.times(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns an array of RegistrationGroups' do
|
20
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump([registration_group_json, registration_group_json]))
|
21
|
+
|
22
|
+
groups = client.owned_registration_groups('cps', unique_id)
|
23
|
+
|
24
|
+
expect(groups).to be_a Array
|
25
|
+
expect(groups.length).to eq 2
|
26
|
+
expect(groups.first).to be_a UserManagementApi::RegistrationGroup
|
27
|
+
|
28
|
+
expect(stub).to have_been_requested.times(1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#enrolled_registration_groups' do
|
33
|
+
let(:url) { "#{base_uri}/registration_groups/cps/enrolled/#{unique_id}" }
|
34
|
+
|
35
|
+
it 'makes a GET request to the correct URL' do
|
36
|
+
stub = stub_request(:get, url)
|
37
|
+
client.enrolled_registration_groups('cps', unique_id)
|
38
|
+
|
39
|
+
expect(stub).to have_been_requested.times(1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns an array of RegistrationGroups' do
|
43
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump([registration_group_json, registration_group_json]))
|
44
|
+
|
45
|
+
groups = client.enrolled_registration_groups('cps', unique_id)
|
46
|
+
|
47
|
+
expect(groups).to be_a Array
|
48
|
+
expect(groups.length).to eq 2
|
49
|
+
expect(groups.first).to be_a UserManagementApi::RegistrationGroup
|
50
|
+
|
51
|
+
expect(stub).to have_been_requested.times(1)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#registration_group' do
|
56
|
+
|
57
|
+
let(:registration_group_uid) { SecureRandom.uuid }
|
58
|
+
let(:url) { "#{base_uri}/registration_groups/#{registration_group_uid}" }
|
59
|
+
|
60
|
+
it 'makes a GET request to the correct URL' do
|
61
|
+
stub = stub_request(:get, url)
|
62
|
+
client.registration_group(registration_group_uid)
|
63
|
+
|
64
|
+
expect(stub).to have_been_requested.times(1)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns a RegistrationGroup object' do
|
68
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump(registration_group_json))
|
69
|
+
|
70
|
+
rg = client.registration_group(registration_group_uid)
|
71
|
+
|
72
|
+
expect(rg).to be_a UserManagementApi::RegistrationGroup
|
73
|
+
|
74
|
+
expect(stub).to have_been_requested.times(1)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#registration_group_enrollees' do
|
79
|
+
|
80
|
+
let(:registration_group_uid) { SecureRandom.uuid }
|
81
|
+
let(:url) { "#{base_uri}/registration_groups/#{registration_group_uid}/enrollees" }
|
82
|
+
|
83
|
+
it 'makes a GET request to the correct URL' do
|
84
|
+
stub = stub_request(:get, url)
|
85
|
+
client.registration_group_enrollees(registration_group_uid)
|
86
|
+
|
87
|
+
expect(stub).to have_been_requested.times(1)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns an array of Users' do
|
91
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump([user_json, user_json]))
|
92
|
+
|
93
|
+
rg = client.registration_group_enrollees(registration_group_uid)
|
94
|
+
|
95
|
+
expect(rg).to be_a Array
|
96
|
+
expect(rg.first).to be_a UserManagementApi::User
|
97
|
+
|
98
|
+
expect(stub).to have_been_requested.times(1)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#registration_group_remove_enrollee' do
|
103
|
+
|
104
|
+
let(:registration_group_uid) { SecureRandom.uuid }
|
105
|
+
let(:url) { "#{base_uri}/registration_groups/#{registration_group_uid}/enrollees/#{unique_id}" }
|
106
|
+
|
107
|
+
it 'makes a DELETE request to the correct URL' do
|
108
|
+
stub = stub_request(:delete, url)
|
109
|
+
client.registration_group_remove_enrollee(registration_group_uid, unique_id)
|
110
|
+
|
111
|
+
expect(stub).to have_been_requested.times(1)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns true for a 200 response' do
|
115
|
+
stub = stub_request(:delete, url).to_return(body: MultiJson.dump({notice: 'good'}))
|
116
|
+
|
117
|
+
rg = client.registration_group_remove_enrollee(registration_group_uid, unique_id)
|
118
|
+
|
119
|
+
expect(rg).to eq true
|
120
|
+
|
121
|
+
expect(stub).to have_been_requested.times(1)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'returns false for a 404 response' do
|
125
|
+
stub = stub_request(:delete, url).to_return(body: MultiJson.dump({error: 'not found'}), status: 404)
|
126
|
+
|
127
|
+
rg = client.registration_group_remove_enrollee(registration_group_uid, unique_id)
|
128
|
+
|
129
|
+
expect(rg).to eq false
|
130
|
+
|
131
|
+
expect(stub).to have_been_requested.times(1)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#pending_registration_groups' do
|
136
|
+
let(:url) { "#{base_uri}/registration_groups/cps/pending" }
|
137
|
+
|
138
|
+
it 'makes a GET request to the correct URL' do
|
139
|
+
stub = stub_request(:get, url)
|
140
|
+
client.pending_registration_groups('cps')
|
141
|
+
|
142
|
+
expect(stub).to have_been_requested.times(1)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'returns an array of RegistrationGroups' do
|
146
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump([registration_group_json, registration_group_json]))
|
147
|
+
|
148
|
+
groups = client.pending_registration_groups('cps')
|
149
|
+
|
150
|
+
expect(groups).to be_a Array
|
151
|
+
expect(groups.length).to eq 2
|
152
|
+
expect(groups.first).to be_a UserManagementApi::RegistrationGroup
|
153
|
+
|
154
|
+
expect(stub).to have_been_requested.times(1)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe UserManagementApi::ClientMethods::RegistrationGroups do
|
4
|
+
|
5
|
+
include_context 'client context'
|
6
|
+
|
7
|
+
let(:registration_json) { {user_unique_id: unique_id, institution: 'Tet', project: 'cps', max_extract_size: 20480, field: {id: 1, label: 'label'}, research_areas: [{id: 1, label: 'research'}, {id: 2, label: 'science'}]} }
|
8
|
+
let(:registration_list) { [registration_json, registration_json, registration_json] }
|
9
|
+
let(:paged_registration_list) { { total_count: 3, total_pages: 1, current_page: 1, registrations: registration_list } }
|
10
|
+
|
11
|
+
describe '#user_registrations' do
|
12
|
+
|
13
|
+
let(:url) { "#{base_uri}/registrations/#{unique_id}" }
|
14
|
+
|
15
|
+
it 'makes a GET to the correct url' do
|
16
|
+
stub = stub_request(:get, url)
|
17
|
+
client.user_registrations(unique_id)
|
18
|
+
|
19
|
+
expect(stub).to have_been_requested.times(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns nil for an invalid user' do
|
23
|
+
stub = stub_request(:get, url).to_return(:status => 404)
|
24
|
+
|
25
|
+
expect(client.user_registrations(unique_id)).to be_nil
|
26
|
+
|
27
|
+
expect(stub).to have_been_requested.times(1)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns an array of projects for a valid user' do
|
31
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump(registration_list))
|
32
|
+
|
33
|
+
list = client.user_registrations(unique_id)
|
34
|
+
|
35
|
+
expect(list).not_to be_nil
|
36
|
+
expect(list).to be_a(Array)
|
37
|
+
expect(list.size).to eq 3
|
38
|
+
expect(list.first).to be_a(UserManagementApi::Registration)
|
39
|
+
expect(list.first.institution).to eq 'Tet'
|
40
|
+
|
41
|
+
expect(stub).to have_been_requested.times(1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#user_registration' do
|
46
|
+
|
47
|
+
let(:url) { "#{base_uri}/registrations/cps/#{unique_id}" }
|
48
|
+
|
49
|
+
it 'makes a GET request to the correct URL' do
|
50
|
+
stub = stub_request(:get, url)
|
51
|
+
client.user_registration('cps', unique_id)
|
52
|
+
|
53
|
+
expect(stub).to have_been_requested.times(1)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns nil when an invalid id is passed' do
|
57
|
+
stub = stub_request(:get, url).to_return(:status => 404)
|
58
|
+
|
59
|
+
expect(client.user_registration('cps', unique_id)).to be_nil
|
60
|
+
|
61
|
+
expect(stub).to have_been_requested.times(1)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns a Registration object' do
|
65
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump(registration_json))
|
66
|
+
|
67
|
+
reg = client.user_registration('cps', unique_id)
|
68
|
+
|
69
|
+
expect(reg).not_to be_nil
|
70
|
+
expect(reg).to be_a(UserManagementApi::Registration)
|
71
|
+
expect(reg.institution).to eq 'Tet'
|
72
|
+
expect(reg.field).not_to be_nil
|
73
|
+
expect(reg.field.id).to eq 1
|
74
|
+
expect(reg.max_extract_size).to eq 20480
|
75
|
+
|
76
|
+
expect(reg.research_areas).not_to be_nil
|
77
|
+
expect(reg.research_areas).to be_a(Array)
|
78
|
+
expect(reg.research_areas.first.id).to eq 1
|
79
|
+
|
80
|
+
expect(stub).to have_been_requested.times(1)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#search_registrations' do
|
85
|
+
|
86
|
+
let(:url) { "#{base_uri}/registrations/cps" }
|
87
|
+
|
88
|
+
it 'makes a GET request to the correct URL' do
|
89
|
+
stub = stub_request(:get, url)
|
90
|
+
client.search_registrations('cps')
|
91
|
+
|
92
|
+
expect(stub).to have_been_requested.times(1)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns a PagedCollection object' do
|
96
|
+
stub = stub_request(:get, url).to_return(body: MultiJson.dump(paged_registration_list))
|
97
|
+
|
98
|
+
data = client.search_registrations('cps')
|
99
|
+
|
100
|
+
expect(data).to be_a UserManagementApi::PagedCollection
|
101
|
+
expect(data.total_pages).to eq 1
|
102
|
+
expect(data.total_count).to eq 3
|
103
|
+
expect(data.current_page).to eq 1
|
104
|
+
expect(data.length).to eq 3
|
105
|
+
expect(data.first).to be_a UserManagementApi::Registration
|
106
|
+
expect(data.first.institution).to eq 'Tet'
|
107
|
+
|
108
|
+
expect(stub).to have_been_requested.times(1)
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#set_registration_custom_attributes' do
|
114
|
+
let(:url) { "#{base_uri}/registrations/cps/#{unique_id}/custom_attributes" }
|
115
|
+
|
116
|
+
it 'makes a PATCH request to the correct URL' do
|
117
|
+
stub = stub_request(:patch, url)
|
118
|
+
client.set_registration_custom_attributes('cps', unique_id, {key: 'value'})
|
119
|
+
|
120
|
+
expect(stub).to have_been_requested.times(1)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'returns a Registration object' do
|
124
|
+
stub = stub_request(:patch, url).to_return(body: MultiJson.dump(registration_json))
|
125
|
+
data = client.set_registration_custom_attributes('cps', unique_id, {key: 'value'})
|
126
|
+
|
127
|
+
expect(data).to be_a UserManagementApi::Registration
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|