0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 15:18:34 +08:00
discourse/spec/system/impersonation_spec.rb
Martin Brennan 4c44eec9d5
DEV: Complete several legacy upcoming changes (#39742)
The following upcoming changes have now progressed
past stable, with the following effect:

* enable_form_templates - Default to true and shows as a normal
  site setting.
* impersonate_without_logout - Site setting removed, this is the
  new behaviour for impersonation.
* enable_auto_grid_images - Default to true and shows as a normal site
  setting.

The upcoming change metadata for these items has now been removed.
2026-05-06 10:08:47 +10:00

65 lines
1.9 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Impersonation" do
fab!(:admin)
fab!(:user)
let(:dialog) { PageObjects::Components::Dialog.new }
before { sign_in(admin) }
it "allows you to start and stop impersonating with the click of a button" do
visit("/admin/users/#{user.id}/#{user.username}")
page.find(".btn-impersonate").click
expect(page).to have_current_path("/")
expect(page).to have_css(
".impersonation-notice",
text: I18n.t("js.impersonation.notice", username: user.username),
)
visit("/latest")
page.find(".impersonation-notice .btn-danger").click
expect(page).to have_current_path("/")
expect(page).to have_no_css(".impersonation-notice")
end
it "shows a helpful error when the user is not found" do
Admin::ImpersonateController.any_instance.stubs(:create).raises(Discourse::NotFound)
visit("/admin/users/#{user.id}/#{user.username}")
page.find(".btn-impersonate").click
expect(dialog).to be_open
expect(dialog).to have_content(I18n.t("admin_js.admin.impersonate.not_found"))
end
it "shows a helpful error when impersonation of that user is not allowed" do
Admin::ImpersonateController.any_instance.stubs(:create).raises(Discourse::InvalidAccess)
visit("/admin/users/#{user.id}/#{user.username}")
page.find(".btn-impersonate").click
expect(dialog).to be_open
expect(dialog).to have_content(I18n.t("admin_js.admin.impersonate.invalid"))
end
it "shows a helpful error when there's an unexpected server error" do
Admin::ImpersonateController.any_instance.stubs(:create).raises(StandardError)
visit("/admin/users/#{user.id}/#{user.username}")
# Suppress the expected error from the intentionally raised StandardError
silence_stdout do
page.find(".btn-impersonate").click
expect(dialog).to be_open
expect(dialog).to have_content(I18n.t("admin_js.admin.impersonate.error"))
end
end
end