# frozen_string_literal: true

module AAAHelpers

  def given_login!
    current_user = FactoryBot.create(:user)
    token = AAA::Test.generate_token(id: current_user.id)
    res = AAA.client.transfer_login(token: token, site_id: "cms")
    current_session = AAA::RequestHelper::CurrentSession.new(
      res.fetch(:details, :flow, :account_id),
      current_user.id,
      current_user.name,
      current_user.email,
      res.fetch(:details, :flow, :session_id),
    )
    request.env["aaa.helper"] = Struct.new(:current_session, :logged_in?).new(current_session, true)
    current_user
  end

end
