2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:15:08 +08:00
discourse/spec/system/impersonation_spec.rb
Martin Brennan 6e8570b0fb
DEV: Rename experimental_ upcoming change settings (#37589)
We can use the status of upcoming changes to indicate
whether they are experimental or not, having experimental
in the setting name is redundant.

Migrates the settings and the upcoming change events,
updates code, and updates yaml translation keys.
2026-02-10 10:34:37 +10:00

66 lines
1.9 KiB
Ruby

# frozen_string_literal: true
describe "Impersonation", type: :system do
fab!(:admin)
fab!(:user)
let(:dialog) { PageObjects::Components::Dialog.new }
before do
SiteSetting.impersonate_without_logout = true
sign_in(admin)
end
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}")
page.find(".btn-impersonate").click
expect(dialog).to be_open
expect(dialog).to have_content(I18n.t("admin_js.admin.impersonate.error"))
end
end