Maintenance: Simulate login instead of using the real login form all the time.
This commit is contained in:
parent
44703499e3
commit
dc5ba3cbaa
7 changed files with 35 additions and 4 deletions
|
@ -43,6 +43,10 @@ module ApplicationController::Authenticates
|
|||
end
|
||||
|
||||
def authentication_check_only(auth_param = {})
|
||||
if Rails.env.test? && ENV['FAKE_SELENIUM_LOGIN_USER_ID'].present? && session[:user_id].blank?
|
||||
session[:user_id] = ENV['FAKE_SELENIUM_LOGIN_USER_ID'].to_i
|
||||
end
|
||||
|
||||
# logger.debug 'authentication_check'
|
||||
# logger.debug params.inspect
|
||||
# logger.debug session.inspect
|
||||
|
|
|
@ -12,12 +12,28 @@ RSpec.configure do |config|
|
|||
|
||||
config.before(:each, type: :system) do |example|
|
||||
|
||||
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
|
||||
|
||||
# there is no way to authenticated in a not set up system
|
||||
next if !example.metadata.fetch(:set_up, true)
|
||||
|
||||
authenticated = example.metadata.fetch(:authenticated_as, true)
|
||||
credentials = authenticated_as_get_user(authenticated, return_type: :credentials)
|
||||
credentials = authenticated_as_get_user(authenticated, return_type: :credentials)
|
||||
|
||||
login(**credentials) if credentials
|
||||
authentication_type = example.metadata.fetch(:authentication_type, :auto)
|
||||
|
||||
next if credentials.nil?
|
||||
|
||||
if authentication_type == :form
|
||||
login(**credentials)
|
||||
else
|
||||
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = User.find_by(email: credentials[:username]).id.to_s
|
||||
|
||||
visit '/'
|
||||
|
||||
wait(4).until_exists do
|
||||
current_login
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,8 @@ module CommonActions
|
|||
#
|
||||
# return [nil]
|
||||
def login(username:, password:, remember_me: false)
|
||||
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
|
||||
|
||||
visit '/'
|
||||
|
||||
within('#login') do
|
||||
|
@ -91,6 +93,7 @@ module CommonActions
|
|||
# logout
|
||||
#
|
||||
def logout
|
||||
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
|
||||
visit('logout')
|
||||
end
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ Capybara.register_driver(:zammad_chrome) do |app|
|
|||
options[:url] = ENV['REMOTE_URL']
|
||||
end
|
||||
|
||||
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
|
||||
|
||||
Capybara::Selenium::Driver.new(app, **options)
|
||||
end
|
||||
|
||||
|
@ -54,5 +56,7 @@ Capybara.register_driver(:zammad_firefox) do |app|
|
|||
options[:url] = ENV['REMOTE_URL']
|
||||
end
|
||||
|
||||
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
|
||||
|
||||
Capybara::Selenium::Driver.new(app, **options)
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Public Knowledge Base for editor', type: :system do
|
||||
RSpec.describe 'Public Knowledge Base for editor', authentication_type: :form, type: :system do
|
||||
include_context 'basic Knowledge Base'
|
||||
|
||||
before do
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Manage > Users', type: :system do
|
||||
describe 'switching to an alternative user', authenticated_as: -> { original_user } do
|
||||
describe 'switching to an alternative user', authentication_type: :form, authenticated_as: -> { original_user } do
|
||||
let(:original_user) { create(:admin) }
|
||||
let(:alternative_one_user) { create(:admin) }
|
||||
let(:alternative_two_user) { create(:admin) }
|
||||
|
|
|
@ -15,6 +15,8 @@ RSpec.describe 'Online notification', type: :system do
|
|||
context 'when pending time is reached soon' do
|
||||
before do
|
||||
visit "ticket/zoom/#{ticket.id}"
|
||||
|
||||
wait.until_exists { find("a[data-key='Ticket-#{ticket.id}']", wait: 0) }
|
||||
end
|
||||
|
||||
let(:ticket) { create(:ticket, owner: session_user, group: Group.first, state_name: 'pending reminder', pending_time: 4.seconds.from_now) }
|
||||
|
@ -44,6 +46,8 @@ RSpec.describe 'Online notification', type: :system do
|
|||
before do
|
||||
ensure_websocket do
|
||||
visit "ticket/zoom/#{ticket.id}"
|
||||
|
||||
wait.until_exists { find("a[data-key='Ticket-#{ticket.id}']", wait: 0) }
|
||||
end
|
||||
|
||||
ticket.update! state: Ticket::State.lookup(name: 'pending reminder'), pending_time: 5.seconds.from_now
|
||||
|
|
Loading…
Reference in a new issue