tabletop-companion/test/models/user_test.rb

59 lines
1.6 KiB
Ruby
Raw Normal View History

2024-05-26 10:45:10 +00:00
# frozen_string_literal: true
2024-04-14 10:10:10 +00:00
require "test_helper"
class UserTest < ActiveSupport::TestCase
test "full name returns first and last name" do
assert_equal "Trevor Vallender", users(:trevor).full_name
end
test "username must exist" do
assert_must_exist(users(:trevor), "username")
end
test "username must be unique" do
user1 = User.first
user2 = User.second
user1.username = user2.username
assert_not user1.valid?
end
test "email must exist" do
assert_must_exist(users(:trevor), "email")
end
test "email must be unique" do
user1 = User.first
user2 = User.second
user1.email = user2.email
assert_not user1.valid?
end
test "email must be a valid email" do
user = users(:trevor)
user.email = "trevor"
assert_not user.valid?
assert_includes user.errors[:email], "must be a valid email address"
end
test "first name must exist" do
assert_must_exist(users(:trevor), "first_name")
end
2024-04-14 19:01:32 +00:00
test "email verification token is invalid after email verified" do
user = users(:unverified)
token = user.generate_token_for(:email_verification)
assert_equal user, User.find_by_token_for(:email_verification, token)
user.update(verified: true)
assert_nil User.find_by_token_for(:email_verification, token)
end
2024-04-14 10:10:10 +00:00
test "password reset token is invalid after password changed" do
user = users(:trevor)
token = user.generate_token_for(:password_reset)
assert_equal user, User.find_by_token_for(:password_reset, token)
user.update(password: "new_password")
assert_nil User.find_by_token_for(:password_reset, token)
end
end