Birth dates: Add tests

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-01-18 19:29:21 +01:00
commit dfb2808535
9 changed files with 210 additions and 9 deletions

View file

@ -755,6 +755,54 @@ defmodule Pleroma.UserTest do
end
end
describe "user registration, with :birth_date_required and :birth_date_min_age" do
@full_user_data %{
bio: "A guy",
name: "my name",
nickname: "nick",
password: "test",
password_confirmation: "test",
email: "email@example.com"
}
setup do
clear_config([:instance, :birth_date_required], true)
clear_config([:instance, :birth_date_min_age], 18 * 365)
end
test "it passes when correct birth date is provided" do
today = Date.utc_today()
birth_date = Date.add(today, -19 * 365)
params =
@full_user_data
|> Map.put(:birth_date, birth_date)
changeset = User.register_changeset(%User{}, params)
assert changeset.valid?
end
test "it fails when birth date is not provided" do
changeset = User.register_changeset(%User{}, @full_user_data)
refute changeset.valid?
end
test "it fails when provided invalid birth date" do
today = Date.utc_today()
birth_date = Date.add(today, -17 * 365)
params =
@full_user_data
|> Map.put(:birth_date, birth_date)
changeset = User.register_changeset(%User{}, params)
refute changeset.valid?
end
end
describe "get_or_fetch/1" do
test "gets an existing user by nickname" do
user = insert(:user)