2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-12-19 14:47:15 +00:00
|
|
|
# This file registers a hook before each system test
|
2021-08-17 12:10:02 +00:00
|
|
|
# which logs in with/authenticates the admin@example.com account.
|
2018-12-19 14:47:15 +00:00
|
|
|
|
|
|
|
# we need to make sure that Capybara is configured/started before
|
|
|
|
# this hook. Otherwise a login try is performed while the app/puma
|
|
|
|
# hasn't started yet.
|
|
|
|
require_relative './driven_by'
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
|
|
|
|
config.before(:each, type: :system) do |example|
|
|
|
|
|
2021-11-04 13:40:58 +00:00
|
|
|
ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
|
|
|
|
|
2018-12-19 14:47:15 +00:00
|
|
|
# there is no way to authenticated in a not set up system
|
|
|
|
next if !example.metadata.fetch(:set_up, true)
|
|
|
|
|
2020-06-18 11:51:25 +00:00
|
|
|
authenticated = example.metadata.fetch(:authenticated_as, true)
|
2021-11-04 13:40:58 +00:00
|
|
|
credentials = authenticated_as_get_user(authenticated, return_type: :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 '/'
|
2018-12-19 14:47:15 +00:00
|
|
|
|
2021-12-10 12:37:47 +00:00
|
|
|
wait.until_exists do
|
2021-11-04 13:40:58 +00:00
|
|
|
current_login
|
|
|
|
end
|
2022-02-11 09:18:56 +00:00
|
|
|
|
|
|
|
await_empty_ajax_queue
|
2021-11-04 13:40:58 +00:00
|
|
|
end
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
|
|
|
end
|