-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and move onboarding controller tests to test/functional (#5307)
* Move onboarding controller tests to test/functional These tests fit more with the functional paradigm since they are named after a controller and test one action at a time. * Cleanup onboarding tests, convert to ActionDispatch::IntegrationTest
- Loading branch information
1 parent
eda971a
commit de200d3
Showing
12 changed files
with
203 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
app/controllers/organizations/onboarding/confirm_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
test/functional/organizations/onboarding/users_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
require "test_helper" | ||
|
||
class Organizations::Onboarding::UsersControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@user = create(:user, :mfa_enabled) | ||
@other_users = create_list(:user, 2) | ||
@rubygem = create(:rubygem, owners: [@user, *@other_users]) | ||
|
||
@organization_onboarding = create( | ||
:organization_onboarding, | ||
created_by: @user, | ||
namesake_rubygem: @rubygem | ||
) | ||
|
||
@invites = @organization_onboarding.invites.to_a | ||
end | ||
|
||
context "on GET /organizations/onboarding/users" do | ||
should "render the list of users to invite" do | ||
get organization_onboarding_users_path(as: @user) | ||
|
||
assert_response :ok | ||
# assert a text field has the handle | ||
@invites.each_with_index do |invite, idx| | ||
assert_select "input[name='organization_onboarding[invites_attributes][#{idx}][id]'][value='#{invite.id}']" | ||
assert_select "select[name='organization_onboarding[invites_attributes][#{idx}][role]']" | ||
end | ||
end | ||
|
||
context "when there are already users added" do | ||
should "render the list of users with their roles" do | ||
@organization_onboarding.invites.where(user_id: @other_users[0].id).update!(role: "admin") | ||
@organization_onboarding.invites.where(user_id: @other_users[1].id).update!(role: "maintainer") | ||
|
||
get organization_onboarding_users_path(as: @user) | ||
|
||
assert_response :ok | ||
|
||
assert_select "input[name='organization_onboarding[invites_attributes][0][id]'][value='#{@invites[0].id}']" | ||
assert_select "select[name='organization_onboarding[invites_attributes][0][role]'] option[selected][value='admin']" | ||
assert_select "input[name='organization_onboarding[invites_attributes][1][id]'][value='#{@invites[1].id}']" | ||
assert_select "select[name='organization_onboarding[invites_attributes][1][role]'] option[selected][value='maintainer']" | ||
end | ||
end | ||
end | ||
|
||
context "on PATCH /organizations/onboarding/users" do | ||
should "update invites ignoring blank rows" do | ||
patch organization_onboarding_users_path(as: @user), params: { | ||
organization_onboarding: { | ||
invites_attributes: { | ||
"0" => { id: @invites[0].id, role: "maintainer" }, | ||
"1" => { id: @invites[1].id, role: "" } | ||
} | ||
} | ||
} | ||
|
||
assert_redirected_to organization_onboarding_confirm_path | ||
|
||
@organization_onboarding.reload | ||
|
||
assert_equal "maintainer", @organization_onboarding.invites.find_by(user_id: @other_users[0].id).role | ||
assert_nil @organization_onboarding.invites.find_by(user_id: @other_users[1].id).role | ||
end | ||
|
||
should "update invites ignoring user_id in invites_attributes" do | ||
patch organization_onboarding_users_path(as: @user), params: { | ||
organization_onboarding: { | ||
invites_attributes: { | ||
"0" => { id: @invites[0].id, role: "maintainer" }, | ||
"1" => { user_id: @invites[1].user.id, role: "owner" } | ||
} | ||
} | ||
} | ||
|
||
assert_redirected_to organization_onboarding_confirm_path | ||
|
||
@organization_onboarding.reload | ||
|
||
assert_equal "maintainer", @organization_onboarding.invites.find_by(user_id: @other_users[0].id).role | ||
assert_nil @organization_onboarding.invites.find_by(user_id: @other_users[1].id).role | ||
assert_equal 1, @organization_onboarding.approved_invites.count | ||
end | ||
|
||
should "update multiple users" do | ||
patch organization_onboarding_users_path(as: @user), params: { | ||
organization_onboarding: { | ||
invites_attributes: { | ||
"0" => { id: @invites[0].id, role: "maintainer" }, | ||
"1" => { id: @invites[1].id, role: "admin" } | ||
} | ||
} | ||
} | ||
|
||
assert_redirected_to organization_onboarding_confirm_path | ||
|
||
@organization_onboarding.reload | ||
|
||
assert_equal "maintainer", @organization_onboarding.invites.find_by(user_id: @other_users[0].id).role | ||
assert_equal "admin", @organization_onboarding.invites.find_by(user_id: @other_users[1].id).role | ||
end | ||
|
||
context "when already invited users" do | ||
should "update roles and/or uninvite" do | ||
@organization_onboarding.invites.create(user_id: @other_users[0].id, role: "admin") | ||
@organization_onboarding.invites.create(user_id: @other_users[1].id, role: "maintainer") | ||
|
||
patch organization_onboarding_users_path(as: @user), params: { | ||
organization_onboarding: { | ||
invites_attributes: { | ||
"0" => { id: @invites[0].id, role: "maintainer" }, | ||
"1" => { id: @invites[1].id, role: "" } | ||
} | ||
} | ||
} | ||
|
||
@organization_onboarding.reload | ||
|
||
assert_equal "maintainer", @organization_onboarding.invites.find_by(user_id: @other_users[0].id).role | ||
assert_nil @organization_onboarding.invites.find_by(user_id: @other_users[1].id).role | ||
end | ||
end | ||
end | ||
end |
60 changes: 60 additions & 0 deletions
60
test/functional/organizations/onboarding_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "test_helper" | ||
|
||
class Organizations::OnboardingControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@user = create(:user) | ||
end | ||
|
||
context "GET /organizations/onboarding" do | ||
should "redirect to onboarding start page" do | ||
get organization_onboarding_path(as: @user) | ||
|
||
assert_redirected_to organization_onboarding_name_path | ||
end | ||
end | ||
|
||
context "DELETE /organizations/onboarding" do | ||
context "when onboarding is already completed" do | ||
should "not destroy the OrganizationOnboarding" do | ||
organization_onboarding = create(:organization_onboarding, :completed, created_by: @user) | ||
|
||
delete organization_onboarding_path(as: @user) | ||
|
||
assert_redirected_to dashboard_path | ||
assert OrganizationOnboarding.exists?(id: organization_onboarding.id) | ||
end | ||
end | ||
|
||
context "when user has a pending onboarding" do | ||
should "destroy the OrganizationOnboarding" do | ||
organization_onboarding = create(:organization_onboarding, created_by: @user) | ||
|
||
delete organization_onboarding_path(as: @user) | ||
|
||
assert_redirected_to dashboard_path | ||
refute OrganizationOnboarding.exists?(id: organization_onboarding.id) | ||
end | ||
end | ||
|
||
context "when user has a failed onboarding" do | ||
should "destroy the OrganizationOnboarding" do | ||
organization_onboarding = create(:organization_onboarding, :failed, created_by: @user) | ||
|
||
delete organization_onboarding_path(as: @user) | ||
|
||
assert_redirected_to dashboard_path | ||
refute OrganizationOnboarding.exists?(id: organization_onboarding.id) | ||
end | ||
end | ||
|
||
context "when the current user has not started onboarding" do | ||
should "redirect to the dashboard" do | ||
assert_no_difference -> { OrganizationOnboarding.count } do | ||
delete organization_onboarding_path(as: @user) | ||
end | ||
|
||
assert_redirected_to dashboard_path | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.