8f39c015ea
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`.
66 lines
1.8 KiB
Ruby
66 lines
1.8 KiB
Ruby
require "test_helper"
|
|
|
|
class UserTest < ActiveSupport::TestCase
|
|
test "create" do
|
|
user = User.create! \
|
|
role: "member",
|
|
name: "Victor Cooper",
|
|
email_address: "victor@hey.com",
|
|
password: "secret123456"
|
|
|
|
assert_equal user, User.authenticate_by(email_address: "victor@hey.com", password: "secret123456")
|
|
end
|
|
|
|
test "creation gives access to all_access collections" do
|
|
user = User.create! \
|
|
role: "member",
|
|
name: "Victor Cooper",
|
|
email_address: "victor@hey.com",
|
|
password: "secret123456"
|
|
|
|
assert_equal [ collections(:writebook) ], user.collections
|
|
end
|
|
|
|
test "deactivate" do
|
|
users(:jz).sessions.create!
|
|
|
|
assert_changes -> { users(:jz).active? }, from: true, to: false do
|
|
assert_changes -> { users(:jz).accesses.count }, from: 1, to: 0 do
|
|
assert_changes -> { users(:jz).sessions.count }, from: 1, to: 0 do
|
|
users(:jz).deactivate
|
|
end
|
|
end
|
|
end
|
|
unless Rails.application.config.x.local_authentication
|
|
assert_nil users(:jz).reload.signal_user
|
|
end
|
|
end
|
|
|
|
test "initials" do
|
|
assert_equal "JF", User.new(name: "jason fried").initials
|
|
assert_equal "DHH", User.new(name: "David Heinemeier Hansson").initials
|
|
assert_equal "ÉLH", User.new(name: "Éva-Louise Hernández").initials
|
|
end
|
|
|
|
test "system user" do
|
|
system_user = User.system
|
|
|
|
assert system_user.system?
|
|
assert_equal "System", system_user.name
|
|
assert_equal "S", system_user.initials
|
|
|
|
assert_not_includes User.active, system_user
|
|
end
|
|
|
|
test "start or continue conversation" do
|
|
user = users(:jz)
|
|
|
|
assert_nil user.conversation
|
|
|
|
conversation = user.start_or_continue_conversation
|
|
|
|
assert user.conversation
|
|
assert_equal user.conversation, conversation
|
|
end
|
|
end
|