Skip to content

Commit

Permalink
Move users updating <= 8 perm's integration tests
Browse files Browse the repository at this point in the history
... to new structure, which improves consistency between account and
users namespaces. The tests for when there are more than eight
permissions will be moved over later
  • Loading branch information
yndajas committed Sep 8, 2024
1 parent e27bc57 commit 428fd7d
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 279 deletions.
266 changes: 0 additions & 266 deletions test/integration/users/access_and_permissions_test.rb
Original file line number Diff line number Diff line change
@@ -1,272 +1,6 @@
require "test_helper"

class Users::AccessAndPermissionsTest < ActionDispatch::IntegrationTest
context "as a super admin" do
setup do
admin = create(:superadmin_user)
@user = create(:user)

visit root_path
signin_with(admin)
end

should "support granting app-specific permissions" do
app = create(
:application,
name: "MyApp",
with_non_delegatable_supported_permissions: %w[pre-existing adding never],
)
@user.grant_application_signin_permission(app)
@user.grant_application_permission(app, "pre-existing")

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"
check "adding"
click_button "Update permissions"

assert_includes @user.permissions_for(app), "pre-existing"
assert_includes @user.permissions_for(app), "adding"
assert_not_includes @user.permissions_for(app), "never"
end

should "be able to grant delegatable and non-delegatable permissions" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[delegatable_perm],
with_non_delegatable_supported_permissions: %w[non_delegatable_perm],
)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("delegatable_perm")
assert page.has_field?("non_delegatable_perm")
end

should "not be able to grant permissions that are not grantable_from_ui" do
app = create(
:application,
name: "MyApp",
with_non_delegatable_supported_permissions: %w[grantable_from_ui_perm],
with_non_delegatable_supported_permissions_not_grantable_from_ui: %w[not_grantable_from_ui_perm],
)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("grantable_from_ui_perm")
assert page.has_no_field?("not_grantable_from_ui_perm")
end
end

context "as an admin" do
setup do
admin = create(:admin_user)
@user = create(:user)

visit root_path
signin_with(admin)
end

should "support granting app-specific permissions" do
app = create(
:application,
name: "MyApp",
with_non_delegatable_supported_permissions: %w[pre-existing adding never],
)
@user.grant_application_signin_permission(app)
@user.grant_application_permission(app, "pre-existing")

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"
check "adding"
click_button "Update permissions"

assert_includes @user.permissions_for(app), "pre-existing"
assert_includes @user.permissions_for(app), "adding"
assert_not_includes @user.permissions_for(app), "never"
end

should "be able to grant delegatable and non-delegatable permissions" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[delegatable_perm],
with_non_delegatable_supported_permissions: %w[non_delegatable_perm],
)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("delegatable_perm")
assert page.has_field?("non_delegatable_perm")
end

should "not be able to grant permissions that are not grantable_from_ui" do
app = create(
:application,
name: "MyApp",
with_non_delegatable_supported_permissions: %w[grantable_from_ui_perm],
with_non_delegatable_supported_permissions_not_grantable_from_ui: %w[not_grantable_from_ui_perm],
)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("grantable_from_ui_perm")
assert page.has_no_field?("not_grantable_from_ui_perm")
end
end

context "as a super organisation admin" do
setup do
@super_org_admin = create(:super_organisation_admin_user)
@user = create(:user, organisation: @super_org_admin.organisation)

visit root_path
signin_with(@super_org_admin)
end

should "support granting app-specific permissions" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[pre-existing adding never],
)
@super_org_admin.grant_application_signin_permission(app)
@user.grant_application_signin_permission(app)
@user.grant_application_permission(app, "pre-existing")

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"
check "adding"
click_button "Update permissions"

assert_includes @user.permissions_for(app), "pre-existing"
assert_includes @user.permissions_for(app), "adding"
assert_not_includes @user.permissions_for(app), "never"
end

should "not be able to grant permissions that are non-delegatable" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[delegatable_perm],
with_non_delegatable_supported_permissions: %w[non_delegatable_perm],
)
@super_org_admin.grant_application_signin_permission(app)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("delegatable_perm")
assert page.has_no_field?("non_delegatable_perm")

assert_selector ".govuk-inset-text", text: "Below, you will only see permissions that you are authorised to manage. You can also view all the permissions #{@user.name} has for MyApp."
end

should "not be able to grant permissions that are not grantable_from_ui" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[grantable_from_ui_perm],
with_delegatable_supported_permissions_not_grantable_from_ui: %w[not_grantable_from_ui_perm],
)
@super_org_admin.grant_application_signin_permission(app)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("grantable_from_ui_perm")
assert page.has_no_field?("not_grantable_from_ui_perm")
end
end

context "as an organisation admin" do
setup do
@organisation_admin = create(:organisation_admin_user)
@user = create(:user, organisation: @organisation_admin.organisation)

visit root_path
signin_with(@organisation_admin)
end

should "support granting app-specific permissions" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[pre-existing adding never],
)
@organisation_admin.grant_application_signin_permission(app)
@user.grant_application_signin_permission(app)
@user.grant_application_permission(app, "pre-existing")

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"
check "adding"
click_button "Update permissions"

assert_includes @user.permissions_for(app), "pre-existing"
assert_includes @user.permissions_for(app), "adding"
assert_not_includes @user.permissions_for(app), "never"
end

should "not be able to grant permissions that are non-delegatable" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[delegatable_perm],
with_non_delegatable_supported_permissions: %w[non_delegatable_perm],
)
@organisation_admin.grant_application_signin_permission(app)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("delegatable_perm")
assert page.has_no_field?("non_delegatable_perm")

assert_selector ".govuk-inset-text", text: "Below, you will only see permissions that you are authorised to manage. You can also view all the permissions #{@user.name} has for MyApp."
end

should "not be able to grant permissions that are not grantable_from_ui" do
app = create(
:application,
name: "MyApp",
with_delegatable_supported_permissions: %w[grantable_from_ui_perm],
with_delegatable_supported_permissions_not_grantable_from_ui: %w[not_grantable_from_ui_perm],
)
@organisation_admin.grant_application_signin_permission(app)
@user.grant_application_signin_permission(app)

visit edit_user_path(@user)
click_link "Manage permissions"
click_link "Update permissions for MyApp"

assert page.has_field?("grantable_from_ui_perm")
assert page.has_no_field?("not_grantable_from_ui_perm")
end
end

context "with apps that have greater than eight permissions" do
should "support granting app-specific permissions" do
admin = create(:superadmin_user)
Expand Down
Loading

0 comments on commit 428fd7d

Please sign in to comment.