Files
fizzy/test/test_helpers/session_test_helper.rb
T
Mike Dalessio 8f39c015ea Tests now pass with local authentication
This is the first step of a multi-step SaaS engine extraction.

Looking ahead to an open source release, we need to make sure that
local authentication is treated as an "official" option, and not just
a hack I added for Kevin to do load testing outside our DC. So this PR
gets to green, and adds a CI step in "local authentication" mode.

This all probably feels a little hacky to you, Reader, but the goal of
this change is to ease the next step, which will be extracting the
37id and Queenbee integrations into a proprietary "SaaS mode" engine.

In service of that goal, this commit simply wraps all of the dependent
code and tests with a conditional check on
`config.x.local_authentication`.
2025-09-13 15:21:00 -04:00

34 lines
1002 B
Ruby

module SessionTestHelper
def parsed_cookies
ActionDispatch::Cookies::CookieJar.build(request, cookies.to_hash)
end
def sign_in_as(user)
cookies.delete :session_token
user = users(user) unless user.is_a? User
if Rails.application.config.x.local_authentication
post session_path, params: { email_address: user.email_address, password: "secret123456" }
else
put session_launchpad_path, params: { sig: user.signal_user.perishable_signature }
end
cookie = cookies.get_cookie "session_token"
assert_not_nil cookie, "Expected session_token cookie to be set after sign in"
assert_equal Account.sole.slug, cookie.path, "Expected session_token cookie to be scoped to account slug"
end
def sign_out
delete session_path
assert_not cookies[:session_token].present?
end
def with_current_user(user)
user = users(user) unless user.is_a? User
Current.session = Session.new(user: user)
yield
ensure
Current.clear_all
end
end