Files
openfoodnetwork/spec/factories/user_factory.rb
Gaetan Craig-Riou 94fb1397f0 Set up data to hide ToS banner
The banner can in some case overlap element we are trying to interact
with. Add a fake ToS file and make sure user have accepted the ToS, so
that the banner is not shown
2023-12-22 13:20:14 +01:00

58 lines
1.4 KiB
Ruby

# frozen_string_literal: true
FactoryBot.define do
sequence :user_authentication_token do |n|
"xxxx#{Time.now.to_i}#{rand(1000)}#{n}xxxxxxxxxxxxx"
end
factory :user, class: Spree::User do
transient do
enterprises { [] }
end
email { generate(:random_email) }
login { email }
password { 'secret' }
password_confirmation { password }
if Spree::User.attribute_method? :authentication_token
authentication_token {
generate(:user_authentication_token)
}
end
confirmation_sent_at { '1970-01-01 00:00:00' }
confirmed_at { '1970-01-01 00:00:01' }
terms_of_service_accepted_at { 1.hour.ago }
before(:create) do |user, evaluator|
if evaluator.confirmation_sent_at
if evaluator.confirmed_at
user.skip_confirmation!
else
user.skip_confirmation_notification!
end
end
end
after(:create) do |user, proxy|
user.spree_roles.clear # Remove admin role
user.enterprises << proxy.enterprises
end
factory :admin_user do
spree_roles { [Spree::Role.find_or_create_by!(name: 'admin')] }
after(:create) do |user|
user.spree_roles << Spree::Role.find_or_create_by!(name: 'admin')
end
end
factory :oidc_user do
after(:create) do |user|
user.update uid: user.email
end
end
end
end