42 lines
1.6 KiB
Ruby
42 lines
1.6 KiB
Ruby
require "test_helper"
|
|
|
|
class AdminUserTest < ActiveSupport::TestCase
|
|
test "email is normalized to lowercase and stripped before save" do
|
|
user = AdminUser.create!(name: "Jane", email: " Jane@Example.COM ", password: "supersecret123")
|
|
assert_equal "jane@example.com", user.email
|
|
end
|
|
|
|
test "email uniqueness is case-insensitive" do
|
|
AdminUser.create!(name: "First", email: "user@example.com", password: "supersecret123")
|
|
dup = AdminUser.new(name: "Second", email: "USER@example.com", password: "supersecret123")
|
|
assert_not dup.valid?
|
|
assert_includes dup.errors[:email], "has already been taken"
|
|
end
|
|
|
|
test "password must be at least 8 characters when present" do
|
|
user = AdminUser.new(name: "Short", email: "short@example.com", password: "1234567")
|
|
assert_not user.valid?
|
|
assert_includes user.errors[:password], "is too short (minimum is 8 characters)"
|
|
end
|
|
|
|
test "authenticate returns the user with a valid password" do
|
|
user = AdminUser.create!(name: "Auth", email: "auth@example.com", password: "supersecret123")
|
|
assert_equal user, user.authenticate("supersecret123")
|
|
assert_not user.authenticate("wrong")
|
|
end
|
|
|
|
test "ntfy_configured? returns true only when topic and token and enabled are set" do
|
|
admin = AdminUser.new(name: "N", email: "n@e.com", password: "password123")
|
|
assert_not admin.ntfy_configured?
|
|
|
|
admin.ntfy_enabled = true
|
|
assert_not admin.ntfy_configured?
|
|
|
|
admin.ntfy_topic = "my-topic"
|
|
assert_not admin.ntfy_configured?
|
|
|
|
admin.ntfy_token = "tk_abc"
|
|
assert admin.ntfy_configured?
|
|
end
|
|
end
|