feat(ntfy): add ntfy fields to admin_users and ntfy_configured? method
This commit is contained in:
@@ -1,7 +1,41 @@
|
||||
require "test_helper"
|
||||
|
||||
class AdminUserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user