openstax_accounts 7.13.0 → 8.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/openstax/accounts/application_controller.rb +1 -1
- data/app/controllers/openstax/accounts/dev/accounts_controller.rb +1 -1
- data/app/controllers/openstax/accounts/dev/base_controller.rb +1 -1
- data/app/controllers/openstax/accounts/sessions_controller.rb +7 -8
- data/app/handlers/openstax/accounts/sessions_callback.rb +17 -37
- data/app/models/openstax/accounts/account.rb +33 -1
- data/app/models/openstax/accounts/group.rb +12 -8
- data/app/models/openstax/accounts/group_nesting.rb +8 -7
- data/app/representers/openstax/accounts/api/v1/unclaimed_account_representer.rb +1 -7
- data/app/routines/openstax/accounts/find_or_create_account.rb +9 -9
- data/app/routines/openstax/accounts/find_or_create_from_sso.rb +23 -0
- data/app/routines/openstax/accounts/sync_accounts.rb +1 -6
- data/config/routes.rb +11 -11
- data/db/migrate/0_create_openstax_accounts_accounts.rb +1 -1
- data/db/migrate/10_assign_missing_uuids_for_local_accounts.rb +2 -2
- data/db/migrate/11_add_support_identifier_to_accounts_accounts.rb +1 -1
- data/db/migrate/12_add_is_test_to_accounts_accounts.rb +1 -1
- data/db/migrate/13_add_school_type_to_accounts_accounts.rb +1 -1
- data/db/migrate/1_create_openstax_accounts_groups.rb +1 -1
- data/db/migrate/2_create_openstax_accounts_group_members.rb +1 -1
- data/db/migrate/3_create_openstax_accounts_group_owners.rb +1 -1
- data/db/migrate/4_create_openstax_accounts_group_nestings.rb +1 -1
- data/db/migrate/5_add_faculty_status_to_accounts_accounts.rb +1 -1
- data/db/migrate/6_add_salesforce_contact_id_to_accounts_accounts.rb +1 -1
- data/db/migrate/7_change_accounts_openstax_uid_to_be_nullable.rb +1 -1
- data/db/migrate/8_change_accounts_username_to_be_nullable.rb +1 -1
- data/db/migrate/9_add_uuid_and_role_to_accounts_accounts.rb +1 -1
- data/lib/omniauth/strategies/openstax.rb +6 -23
- data/lib/openstax/accounts/configuration.rb +16 -0
- data/lib/openstax/accounts/current_user_manager.rb +20 -0
- data/lib/openstax/accounts/has_many_through_groups/active_record/base.rb +5 -5
- data/lib/openstax/accounts/sso.rb +61 -0
- data/lib/openstax/accounts/version.rb +1 -1
- data/lib/openstax_accounts.rb +6 -7
- data/lib/tasks/sync.rake +3 -3
- data/spec/factories/openstax_accounts_account.rb +1 -1
- data/spec/factories/openstax_accounts_group.rb +3 -3
- data/spec/factories/openstax_accounts_group_member.rb +1 -1
- data/spec/factories/openstax_accounts_group_nesting.rb +1 -1
- data/spec/factories/openstax_accounts_group_owner.rb +1 -1
- metadata +34 -212
- data/Rakefile +0 -22
- data/spec/cassettes/OpenStax_Accounts_FindOrCreateAccount/can_create_users.yml +0 -303
- data/spec/controllers/openstax/accounts/dev/accounts_controller_spec.rb +0 -27
- data/spec/controllers/openstax/accounts/forwards_params_spec.rb +0 -75
- data/spec/controllers/openstax/accounts/sessions_controller_spec.rb +0 -71
- data/spec/controllers/openstax/accounts/uses_this_engine_controller_spec.rb +0 -22
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/access_policies/account_access_policy.rb +0 -11
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -13
- data/spec/dummy/app/controllers/api/application_groups_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/application_users_controller.rb +0 -15
- data/spec/dummy/app/controllers/api/dummy_controller.rb +0 -12
- data/spec/dummy/app/controllers/api/group_members_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/group_nestings_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/group_owners_controller.rb +0 -11
- data/spec/dummy/app/controllers/api/groups_controller.rb +0 -15
- data/spec/dummy/app/controllers/api/users_controller.rb +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/controllers/oauth_controller.rb +0 -10
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/anonymous_user.rb +0 -48
- data/spec/dummy/app/models/ownership.rb +0 -7
- data/spec/dummy/app/models/user.rb +0 -29
- data/spec/dummy/config.ru +0 -5
- data/spec/dummy/config/application.rb +0 -23
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -15
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -40
- data/spec/dummy/config/environments/production.rb +0 -82
- data/spec/dummy/config/environments/test.rb +0 -39
- data/spec/dummy/config/initializers/access_policies.rb +0 -1
- data/spec/dummy/config/initializers/assets.rb +0 -8
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -75
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/openstax_accounts.rb +0 -14
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -45
- data/spec/dummy/config/secrets.yml +0 -8
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/1000_create_users.rb +0 -11
- data/spec/dummy/db/migrate/1001_create_ownerships.rb +0 -11
- data/spec/dummy/db/schema.rb +0 -113
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -5137
- data/spec/dummy/log/test.log +0 -162651
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/handlers/openstax/accounts/accounts_search_spec.rb +0 -63
- data/spec/handlers/openstax/accounts/dev/accounts_search_spec.rb +0 -55
- data/spec/handlers/openstax/accounts/sessions_callback_spec.rb +0 -119
- data/spec/lib/openstax/accounts/api_spec.rb +0 -212
- data/spec/lib/openstax/accounts/configuration_spec.rb +0 -39
- data/spec/lib/openstax/accounts/current_user_manager_spec.rb +0 -157
- data/spec/lib/openstax/accounts/has_many_through_groups/active_record/base_spec.rb +0 -57
- data/spec/models/openstax/accounts/account_spec.rb +0 -114
- data/spec/models/openstax/accounts/anonymous_account_spec.rb +0 -9
- data/spec/models/openstax/accounts/group_spec.rb +0 -51
- data/spec/routines/openstax/accounts/create_group_spec.rb +0 -32
- data/spec/routines/openstax/accounts/find_or_create_account_spec.rb +0 -76
- data/spec/routines/openstax/accounts/search_accounts_shared_examples.rb +0 -160
- data/spec/routines/openstax/accounts/search_accounts_spec.rb +0 -6
- data/spec/routines/openstax/accounts/search_local_accounts_spec.rb +0 -6
- data/spec/routines/openstax/accounts/sync_accounts_spec.rb +0 -101
- data/spec/routines/openstax/accounts/sync_groups_spec.rb +0 -143
- data/spec/spec_helper.rb +0 -109
- data/spec/vcr_helper.rb +0 -14
data/spec/dummy/public/404.html
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<style type="text/css">
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
-
div.dialog {
|
8
|
-
width: 25em;
|
9
|
-
padding: 0 4em;
|
10
|
-
margin: 4em auto 0 auto;
|
11
|
-
border: 1px solid #ccc;
|
12
|
-
border-right-color: #999;
|
13
|
-
border-bottom-color: #999;
|
14
|
-
}
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
-
</style>
|
17
|
-
</head>
|
18
|
-
|
19
|
-
<body>
|
20
|
-
<!-- This file lives in public/404.html -->
|
21
|
-
<div class="dialog">
|
22
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
-
</div>
|
25
|
-
</body>
|
26
|
-
</html>
|
data/spec/dummy/public/422.html
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<style type="text/css">
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
-
div.dialog {
|
8
|
-
width: 25em;
|
9
|
-
padding: 0 4em;
|
10
|
-
margin: 4em auto 0 auto;
|
11
|
-
border: 1px solid #ccc;
|
12
|
-
border-right-color: #999;
|
13
|
-
border-bottom-color: #999;
|
14
|
-
}
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
-
</style>
|
17
|
-
</head>
|
18
|
-
|
19
|
-
<body>
|
20
|
-
<!-- This file lives in public/422.html -->
|
21
|
-
<div class="dialog">
|
22
|
-
<h1>The change you wanted was rejected.</h1>
|
23
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
-
</div>
|
25
|
-
</body>
|
26
|
-
</html>
|
data/spec/dummy/public/500.html
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<style type="text/css">
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
-
div.dialog {
|
8
|
-
width: 25em;
|
9
|
-
padding: 0 4em;
|
10
|
-
margin: 4em auto 0 auto;
|
11
|
-
border: 1px solid #ccc;
|
12
|
-
border-right-color: #999;
|
13
|
-
border-bottom-color: #999;
|
14
|
-
}
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
-
</style>
|
17
|
-
</head>
|
18
|
-
|
19
|
-
<body>
|
20
|
-
<!-- This file lives in public/500.html -->
|
21
|
-
<div class="dialog">
|
22
|
-
<h1>We're sorry, but something went wrong.</h1>
|
23
|
-
</div>
|
24
|
-
</body>
|
25
|
-
</html>
|
File without changes
|
data/spec/dummy/script/rails
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
-
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
6
|
-
require 'rails/commands'
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Accounts
|
5
|
-
|
6
|
-
RSpec.describe AccountsSearch do
|
7
|
-
|
8
|
-
let!(:account_1) { FactoryBot.create :openstax_accounts_account,
|
9
|
-
first_name: 'John',
|
10
|
-
last_name: 'Stravinsky',
|
11
|
-
username: 'jstrav' }
|
12
|
-
let!(:account_2) { FactoryBot.create :openstax_accounts_account,
|
13
|
-
first_name: 'Mary',
|
14
|
-
last_name: 'Mighty',
|
15
|
-
full_name: 'Mary Mighty',
|
16
|
-
username: 'mary' }
|
17
|
-
let!(:account_3) { FactoryBot.create :openstax_accounts_account,
|
18
|
-
first_name: 'John',
|
19
|
-
last_name: 'Stead',
|
20
|
-
username: 'jstead' }
|
21
|
-
|
22
|
-
let!(:account_4) { FactoryBot.create :openstax_accounts_account,
|
23
|
-
first_name: 'Bob',
|
24
|
-
last_name: 'JST',
|
25
|
-
username: 'bigbear' }
|
26
|
-
|
27
|
-
let!(:billy_accounts) {
|
28
|
-
(0..49).to_a.collect{|ii|
|
29
|
-
FactoryBot.create :openstax_accounts_account,
|
30
|
-
first_name: "Billy#{ii.to_s.rjust(2, '0')}",
|
31
|
-
last_name: "Bob_#{(49-ii).to_s.rjust(2,'0')}",
|
32
|
-
username: "billy_#{ii.to_s.rjust(2, '0')}"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
it "should match based on username" do
|
37
|
-
outputs = AccountsSearch.call(params: {search: {query: "username:jstra"}}).outputs
|
38
|
-
expect(outputs.total_count).to eq 1
|
39
|
-
expect(outputs.items).to eq [account_1]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return no results if the query is too short" do
|
43
|
-
routine = AccountsSearch.call(params: {search: {query: ""}})
|
44
|
-
outputs = routine.outputs
|
45
|
-
errors = routine.errors
|
46
|
-
expect(outputs.total_count).to be_nil
|
47
|
-
expect(outputs.items).to be_nil
|
48
|
-
expect(errors.last.code).to eq :query_too_short
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should return no results if the limit is exceeded" do
|
52
|
-
routine = AccountsSearch.call(params: {search: {query: "billy"}})
|
53
|
-
outputs = routine.outputs
|
54
|
-
errors = routine.errors
|
55
|
-
expect(outputs.total_count).to eq 50
|
56
|
-
expect(outputs.items).to be_nil
|
57
|
-
expect(errors.last.code).to eq :too_many_items
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Accounts
|
5
|
-
|
6
|
-
RSpec.describe Dev::AccountsSearch do
|
7
|
-
|
8
|
-
let!(:account_1) { FactoryBot.create :openstax_accounts_account,
|
9
|
-
first_name: 'John',
|
10
|
-
last_name: 'Stravinsky',
|
11
|
-
username: 'jstrav' }
|
12
|
-
let!(:account_2) { FactoryBot.create :openstax_accounts_account,
|
13
|
-
first_name: 'Mary',
|
14
|
-
last_name: 'Mighty',
|
15
|
-
full_name: 'Mary Mighty',
|
16
|
-
username: 'mary' }
|
17
|
-
let!(:account_3) { FactoryBot.create :openstax_accounts_account,
|
18
|
-
first_name: 'John',
|
19
|
-
last_name: 'Stead',
|
20
|
-
username: 'jstead' }
|
21
|
-
|
22
|
-
let!(:account_4) { FactoryBot.create :openstax_accounts_account,
|
23
|
-
first_name: 'Bob',
|
24
|
-
last_name: 'JST',
|
25
|
-
username: 'bigbear' }
|
26
|
-
|
27
|
-
let!(:billy_accounts) {
|
28
|
-
(0..49).to_a.collect{|ii|
|
29
|
-
FactoryBot.create :openstax_accounts_account,
|
30
|
-
first_name: "Billy#{ii.to_s.rjust(2, '0')}",
|
31
|
-
last_name: "Bob_#{(49-ii).to_s.rjust(2,'0')}",
|
32
|
-
username: "billy_#{ii.to_s.rjust(2, '0')}"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
it "should match based on username" do
|
37
|
-
outputs = Dev::AccountsSearch.call(params: {search: {query: "username:jstra"}}).outputs
|
38
|
-
expect(outputs.total_count).to eq 1
|
39
|
-
expect(outputs.items).to eq [account_1]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should have no limits" do
|
43
|
-
routine = Dev::AccountsSearch.call(params: {search: {query: ""}})
|
44
|
-
outputs = routine.outputs
|
45
|
-
errors = routine.errors
|
46
|
-
expect(outputs.total_count).to eq 54
|
47
|
-
expect(outputs.items).to eq [account_4, billy_accounts, account_3,
|
48
|
-
account_1, account_2].flatten
|
49
|
-
expect(errors).to be_empty
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Accounts
|
5
|
-
|
6
|
-
RSpec.describe SessionsCallback do
|
7
|
-
|
8
|
-
it "deals with null faculty_status" do
|
9
|
-
with_stubbing(false) do
|
10
|
-
request = mock_omniauth_request
|
11
|
-
remove_nickname!(request)
|
12
|
-
result = described_class.handle(request: request)
|
13
|
-
expect(result.outputs.account).to be_valid
|
14
|
-
expect(result.outputs.account).to be_persisted
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "uuid" do
|
19
|
-
it "sets the UUID on the account" do
|
20
|
-
uuid = SecureRandom.uuid
|
21
|
-
result = described_class.handle(request: mock_omniauth_request(uuid: uuid))
|
22
|
-
expect(result.outputs.account.uuid).to eq uuid
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "support_identifier" do
|
27
|
-
it "sets the support_identifier on the account" do
|
28
|
-
support_identifier = "cs_#{SecureRandom.hex(4)}"
|
29
|
-
result = described_class.handle(
|
30
|
-
request: mock_omniauth_request(support_identifier: support_identifier)
|
31
|
-
)
|
32
|
-
expect(result.outputs.account.support_identifier).to eq support_identifier
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "faculty_status" do
|
37
|
-
it "defaults to no_faculty_info if the received faculty_status is unknown" +
|
38
|
-
" (e.g. if Accounts is updated but this repo is not)" do
|
39
|
-
result = described_class.handle(
|
40
|
-
request: mock_omniauth_request(faculty_status: "howdy_ho")
|
41
|
-
)
|
42
|
-
expect(result.outputs.account).to be_no_faculty_info
|
43
|
-
end
|
44
|
-
|
45
|
-
it "defaults to no_faculty_info if faculty status is not present" do
|
46
|
-
request = mock_omniauth_request()
|
47
|
-
remove_faculty_status!(request)
|
48
|
-
result = described_class.handle(request: request)
|
49
|
-
expect(result.outputs.account).to be_no_faculty_info
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "role" do
|
54
|
-
it "sets the role on the account" do
|
55
|
-
result = described_class.handle(
|
56
|
-
request: mock_omniauth_request(self_reported_role: "instructor")
|
57
|
-
)
|
58
|
-
expect(result.outputs.account).to be_instructor
|
59
|
-
end
|
60
|
-
|
61
|
-
it "deals with unknown role (e.g. if Accounts update but this repo not)" do
|
62
|
-
result = described_class.handle(
|
63
|
-
request: mock_omniauth_request(self_reported_role: "howdy_ho")
|
64
|
-
)
|
65
|
-
expect(result.outputs.account).to be_unknown_role
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "school_type" do
|
70
|
-
it "sets the school_type on the account" do
|
71
|
-
result = described_class.handle(
|
72
|
-
request: mock_omniauth_request(school_type: "college")
|
73
|
-
)
|
74
|
-
expect(result.outputs.account).to be_college
|
75
|
-
end
|
76
|
-
|
77
|
-
it "deals with unknown school_type (e.g. if Accounts update but this repo not)" do
|
78
|
-
result = described_class.handle(
|
79
|
-
request: mock_omniauth_request(school_type: "howdy_ho")
|
80
|
-
)
|
81
|
-
expect(result.outputs.account).to be_unknown_school_type
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "user exists" do
|
86
|
-
it "updates the user's data" do
|
87
|
-
existing_account = FactoryBot.create :openstax_accounts_account
|
88
|
-
uuid = SecureRandom.uuid
|
89
|
-
support_identifier = "cs_#{SecureRandom.hex(4)}"
|
90
|
-
result = described_class.handle(
|
91
|
-
request: mock_omniauth_request(
|
92
|
-
uid: existing_account.openstax_uid,
|
93
|
-
first_name: "1234",
|
94
|
-
last_name: "5678",
|
95
|
-
title: "900",
|
96
|
-
nickname: "191919",
|
97
|
-
faculty_status: "confirmed_faculty",
|
98
|
-
uuid: uuid,
|
99
|
-
support_identifier: support_identifier,
|
100
|
-
self_reported_role: "instructor")
|
101
|
-
)
|
102
|
-
|
103
|
-
account = result.outputs.account.reload
|
104
|
-
expect(account.id).to eq existing_account.id
|
105
|
-
expect(account.first_name).to eq "1234"
|
106
|
-
expect(account.last_name).to eq "5678"
|
107
|
-
expect(account.title).to eq "900"
|
108
|
-
expect(account.username).to eq "191919"
|
109
|
-
expect(account).to be_confirmed_faculty
|
110
|
-
expect(account.uuid).to eq uuid
|
111
|
-
expect(account.support_identifier).to eq support_identifier
|
112
|
-
expect(account).to be_instructor
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
end
|
@@ -1,212 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module OpenStax
|
4
|
-
module Accounts
|
5
|
-
RSpec.describe Api do
|
6
|
-
|
7
|
-
let!(:account) { OpenStax::Accounts::Account.create(username: 'some_user',
|
8
|
-
first_name: 'Some', last_name: 'User', full_name: 'SomeUser',
|
9
|
-
title: 'Sir', openstax_uid: 1, access_token: 'secret') }
|
10
|
-
|
11
|
-
def reset(controller)
|
12
|
-
controller.last_action = nil
|
13
|
-
controller.last_json = nil
|
14
|
-
controller.last_params = nil
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'makes api requests' do
|
18
|
-
reset(::Api::DummyController)
|
19
|
-
Api.request(:post, 'dummy', :params => {:test => true})
|
20
|
-
expect(::Api::DummyController.last_action).to eq :dummy
|
21
|
-
expect(::Api::DummyController.last_params).to include 'test' => 'true'
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'users' do
|
25
|
-
before(:each) { reset(::Api::UsersController) }
|
26
|
-
let!(:account) { FactoryBot.create :openstax_accounts_account }
|
27
|
-
|
28
|
-
it 'makes api call to users index' do
|
29
|
-
Api.search_accounts('something')
|
30
|
-
expect(::Api::UsersController.last_action).to eq :index
|
31
|
-
expect(::Api::UsersController.last_params).to include :q => 'something'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'makes api call to user update' do
|
35
|
-
Api.update_account(account)
|
36
|
-
expect(::Api::UsersController.last_action).to eq :update
|
37
|
-
expect(::Api::UsersController.last_json).to include(
|
38
|
-
account.attributes.slice('username', 'first_name',
|
39
|
-
'last_name', 'full_name', 'title'))
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'makes api call to (temp) user create by email' do
|
43
|
-
Api.find_or_create_account(email: 'dummy@dum.my')
|
44
|
-
expect(::Api::UsersController.last_action).to eq :create
|
45
|
-
expect(::Api::UsersController.last_json).to(
|
46
|
-
include('email' => 'dummy@dum.my')
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'makes api call to (temp) user create by username' do
|
51
|
-
Api.find_or_create_account(username: 'dummy')
|
52
|
-
expect(::Api::UsersController.last_action).to eq :create
|
53
|
-
expect(::Api::UsersController.last_json).to(
|
54
|
-
include('username' => 'dummy')
|
55
|
-
)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context 'application_users' do
|
60
|
-
before(:each) { reset(::Api::ApplicationUsersController) }
|
61
|
-
|
62
|
-
it 'makes api call to application_users index' do
|
63
|
-
Api.search_application_accounts('something')
|
64
|
-
expect(::Api::ApplicationUsersController.last_action).to eq :index
|
65
|
-
expect(::Api::ApplicationUsersController.last_params).to include :q => 'something'
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'makes api call to application_users updates' do
|
69
|
-
Api.get_application_account_updates
|
70
|
-
expect(::Api::ApplicationUsersController.last_action).to eq :updates
|
71
|
-
expect(::Api::ApplicationUsersController.last_params).to include limit: "250"
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'does not limit updates call if param blank' do
|
75
|
-
allow(OpenStax::Accounts.configuration).to receive(:max_user_updates_per_request) { "" }
|
76
|
-
Api.get_application_account_updates
|
77
|
-
expect(::Api::ApplicationUsersController.last_action).to eq :updates
|
78
|
-
expect(::Api::ApplicationUsersController.last_params.keys).not_to include "limit"
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'makes api call to application_users updated' do
|
82
|
-
Api.mark_account_updates_as_read([{id: 1, read_updates: 1}])
|
83
|
-
expect(::Api::ApplicationUsersController.last_action).to eq :updated
|
84
|
-
expect(::Api::ApplicationUsersController.last_json).to include(
|
85
|
-
{'id' => 1, 'read_updates' => 1})
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'groups' do
|
90
|
-
before(:each) { reset(::Api::GroupsController) }
|
91
|
-
|
92
|
-
let!(:account) { FactoryBot.create :openstax_accounts_account }
|
93
|
-
let!(:group) { FactoryBot.create :openstax_accounts_group }
|
94
|
-
|
95
|
-
it 'makes api call to groups create' do
|
96
|
-
Api.create_group(account, group)
|
97
|
-
expect(::Api::GroupsController.last_action).to eq :create
|
98
|
-
expect(::Api::GroupsController.last_json).to include(
|
99
|
-
{'name' => 'MyGroup', 'is_public' => false})
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'makes api call to group update' do
|
103
|
-
group.save!
|
104
|
-
Api.update_group(account, group)
|
105
|
-
expect(::Api::GroupsController.last_action).to eq :update
|
106
|
-
expect(::Api::GroupsController.last_params).to include(
|
107
|
-
{'id' => group.openstax_uid.to_s})
|
108
|
-
expect(::Api::GroupsController.last_json).to include(
|
109
|
-
{'name' => group.name, 'is_public' => group.is_public})
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'makes api call to group destroy' do
|
113
|
-
group.save!
|
114
|
-
Api.destroy_group(account, group)
|
115
|
-
expect(::Api::GroupsController.last_action).to eq :destroy
|
116
|
-
expect(::Api::GroupsController.last_params).to include(
|
117
|
-
{'id' => group.openstax_uid.to_s})
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context 'group_members' do
|
122
|
-
before(:each) { reset(::Api::GroupMembersController) }
|
123
|
-
|
124
|
-
let!(:account) { FactoryBot.create :openstax_accounts_account }
|
125
|
-
let!(:group_member) { FactoryBot.build :openstax_accounts_group_member }
|
126
|
-
|
127
|
-
it 'makes api call to group_members create' do
|
128
|
-
Api.create_group_member(account, group_member)
|
129
|
-
expect(::Api::GroupMembersController.last_action).to eq :create
|
130
|
-
expect(::Api::GroupMembersController.last_params).to include(
|
131
|
-
{'group_id' => group_member.group_id.to_s,
|
132
|
-
'user_id' => group_member.user_id.to_s})
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'makes api call to group_member destroy' do
|
136
|
-
group_member.save!
|
137
|
-
Api.destroy_group_member(account, group_member)
|
138
|
-
expect(::Api::GroupMembersController.last_action).to eq :destroy
|
139
|
-
expect(::Api::GroupMembersController.last_params).to include(
|
140
|
-
{'group_id' => group_member.group_id.to_s,
|
141
|
-
'user_id' => group_member.user_id.to_s})
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context 'group_owners' do
|
146
|
-
before(:each) { reset(::Api::GroupOwnersController) }
|
147
|
-
|
148
|
-
let!(:account) { FactoryBot.create :openstax_accounts_account }
|
149
|
-
let!(:group_owner) { FactoryBot.build :openstax_accounts_group_owner }
|
150
|
-
|
151
|
-
it 'makes api call to group_owners create' do
|
152
|
-
Api.create_group_owner(account, group_owner)
|
153
|
-
expect(::Api::GroupOwnersController.last_action).to eq :create
|
154
|
-
expect(::Api::GroupOwnersController.last_params).to include(
|
155
|
-
{'group_id' => group_owner.group_id.to_s,
|
156
|
-
'user_id' => group_owner.user_id.to_s})
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'makes api call to group_owner destroy' do
|
160
|
-
group_owner.save!
|
161
|
-
Api.destroy_group_owner(account, group_owner)
|
162
|
-
expect(::Api::GroupOwnersController.last_action).to eq :destroy
|
163
|
-
expect(::Api::GroupOwnersController.last_params).to include(
|
164
|
-
{'group_id' => group_owner.group_id.to_s,
|
165
|
-
'user_id' => group_owner.user_id.to_s})
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'group_nestings' do
|
170
|
-
before(:each) { reset(::Api::GroupNestingsController) }
|
171
|
-
|
172
|
-
let!(:account) { FactoryBot.create :openstax_accounts_account }
|
173
|
-
let!(:group_nesting) { FactoryBot.build :openstax_accounts_group_nesting }
|
174
|
-
|
175
|
-
it 'makes api call to group_nestings (create)' do
|
176
|
-
Api.create_group_nesting(account, group_nesting)
|
177
|
-
expect(::Api::GroupNestingsController.last_action).to eq :create
|
178
|
-
expect(::Api::GroupNestingsController.last_params).to include(
|
179
|
-
{'group_id' => group_nesting.container_group_id.to_s,
|
180
|
-
'member_group_id' => group_nesting.member_group_id.to_s})
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'makes api call to group_nesting (destroy)' do
|
184
|
-
group_nesting.save!
|
185
|
-
Api.destroy_group_nesting(account, group_nesting)
|
186
|
-
expect(::Api::GroupNestingsController.last_action).to eq :destroy
|
187
|
-
expect(::Api::GroupNestingsController.last_params).to include(
|
188
|
-
{'group_id' => group_nesting.container_group_id.to_s,
|
189
|
-
'member_group_id' => group_nesting.member_group_id.to_s})
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context 'application_groups' do
|
194
|
-
before(:each) { reset(::Api::ApplicationGroupsController) }
|
195
|
-
|
196
|
-
it 'makes api call to application_groups_updates' do
|
197
|
-
Api.get_application_group_updates
|
198
|
-
expect(::Api::ApplicationGroupsController.last_action).to eq :updates
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'makes api call to application_groups_updated' do
|
202
|
-
Api.mark_group_updates_as_read([{id: 1, read_updates: 1}])
|
203
|
-
expect(::Api::ApplicationGroupsController.last_action).to eq :updated
|
204
|
-
expect(::Api::ApplicationGroupsController.last_json).to include(
|
205
|
-
{'id' => 1, 'read_updates' => 1})
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
end
|
210
|
-
|
211
|
-
end
|
212
|
-
end
|