Merge branch 'birth-dates' into 'develop'
Birth dates See merge request pleroma/pleroma!3608
This commit is contained in:
commit
dd7977bb68
26 changed files with 423 additions and 14 deletions
|
|
@ -755,6 +755,54 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "user registration, with :birthday_required and :birthday_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, :birthday_required], true)
|
||||
clear_config([:instance, :birthday_min_age], 18 * 365)
|
||||
end
|
||||
|
||||
test "it passes when correct birth date is provided" do
|
||||
today = Date.utc_today()
|
||||
birthday = Date.add(today, -19 * 365)
|
||||
|
||||
params =
|
||||
@full_user_data
|
||||
|> Map.put(:birthday, birthday)
|
||||
|
||||
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()
|
||||
birthday = Date.add(today, -17 * 365)
|
||||
|
||||
params =
|
||||
@full_user_data
|
||||
|> Map.put(:birthday, birthday)
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -389,6 +389,26 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
assert %{data: %{"id" => ^object_url}} = Object.get_by_ap_id(object_url)
|
||||
end
|
||||
|
||||
test "fetches user birthday information from misskey" do
|
||||
user_id = "https://misskey.io/@mkljczk"
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: ^user_id
|
||||
} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/birthdays/misskey-user.json"),
|
||||
headers: [{"content-type", "application/activity+json"}]
|
||||
}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||
|
||||
assert user.birthday == ~D[2001-02-12]
|
||||
end
|
||||
end
|
||||
|
||||
test "it fetches the appropriate tag-restricted posts" do
|
||||
|
|
|
|||
|
|
@ -1608,6 +1608,60 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "create account with required birth date" do
|
||||
setup %{conn: conn} do
|
||||
clear_config([:instance, :birthday_required], true)
|
||||
clear_config([:instance, :birthday_min_age], 18 * 365)
|
||||
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer " <> app_token.token)
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|
||||
[conn: conn]
|
||||
end
|
||||
|
||||
test "creates an account if provided valid birth date", %{conn: conn} do
|
||||
birthday =
|
||||
Date.utc_today()
|
||||
|> Date.add(-19 * 365)
|
||||
|> Date.to_string()
|
||||
|
||||
params = %{
|
||||
username: "mkljczk",
|
||||
email: "mkljczk@example.org",
|
||||
password: "dupa.8",
|
||||
agreement: true,
|
||||
birthday: birthday
|
||||
}
|
||||
|
||||
res =
|
||||
conn
|
||||
|> post("/api/v1/accounts", params)
|
||||
|
||||
assert json_response_and_validate_schema(res, 200)
|
||||
end
|
||||
|
||||
test "returns an error if missing birth date", %{conn: conn} do
|
||||
params = %{
|
||||
username: "mkljczk",
|
||||
email: "mkljczk@example.org",
|
||||
password: "dupa.8",
|
||||
agreement: true
|
||||
}
|
||||
|
||||
res =
|
||||
conn
|
||||
|> post("/api/v1/accounts", params)
|
||||
|
||||
assert json_response_and_validate_schema(res, 400) == %{
|
||||
"error" => "{\"birthday\":[\"can't be blank\"]}"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/v1/accounts/:id/lists - account_lists" do
|
||||
test "returns lists to which the account belongs" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:lists"])
|
||||
|
|
|
|||
|
|
@ -370,6 +370,26 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
]
|
||||
end
|
||||
|
||||
test "updates birth date", %{conn: conn} do
|
||||
res =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
"birthday" => "2001-02-12"
|
||||
})
|
||||
|
||||
assert user_data = json_response_and_validate_schema(res, 200)
|
||||
assert user_data["pleroma"]["birthday"] == "2001-02-12"
|
||||
end
|
||||
|
||||
test "updates the user's show_birthday status", %{conn: conn} do
|
||||
res =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
"show_birthday" => true
|
||||
})
|
||||
|
||||
assert user_data = json_response_and_validate_schema(res, 200)
|
||||
assert user_data["source"]["pleroma"]["show_birthday"] == true
|
||||
end
|
||||
|
||||
test "emojis in fields labels", %{conn: conn} do
|
||||
fields = [
|
||||
%{"name" => ":firefox:", "value" => "is best 2hu"},
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
ap_id: user.ap_id,
|
||||
also_known_as: ["https://shitposter.zone/users/shp"],
|
||||
background_image: "https://example.com/images/asuka_hospital.png",
|
||||
birthday: nil,
|
||||
favicon: nil,
|
||||
is_confirmed: true,
|
||||
tags: [],
|
||||
|
|
@ -181,6 +182,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
ap_id: user.ap_id,
|
||||
also_known_as: [],
|
||||
background_image: nil,
|
||||
birthday: nil,
|
||||
favicon: nil,
|
||||
is_confirmed: true,
|
||||
tags: [],
|
||||
|
|
|
|||
|
|
@ -304,4 +304,59 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "birthday reminders" do
|
||||
test "returns a list of friends having birthday on specified day" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:accounts"])
|
||||
|
||||
%{id: id1} =
|
||||
user1 =
|
||||
insert(:user, %{
|
||||
birthday: "2001-02-12",
|
||||
show_birthday: true
|
||||
})
|
||||
|
||||
user2 =
|
||||
insert(:user, %{
|
||||
birthday: "2001-02-14",
|
||||
show_birthday: true
|
||||
})
|
||||
|
||||
user3 = insert(:user)
|
||||
|
||||
CommonAPI.follow(user, user1)
|
||||
CommonAPI.follow(user, user2)
|
||||
CommonAPI.follow(user, user3)
|
||||
|
||||
[%{"id" => ^id1}] =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/birthdays?day=12&month=2")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "the list doesn't list friends with hidden birth date" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:accounts"])
|
||||
|
||||
user1 =
|
||||
insert(:user, %{
|
||||
birthday: "2001-02-12",
|
||||
show_birthday: false
|
||||
})
|
||||
|
||||
%{id: id2} =
|
||||
user2 =
|
||||
insert(:user, %{
|
||||
birthday: "2001-02-12",
|
||||
show_birthday: true
|
||||
})
|
||||
|
||||
CommonAPI.follow(user, user1)
|
||||
CommonAPI.follow(user, user2)
|
||||
|
||||
[%{"id" => ^id2}] =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/birthdays?day=12&month=2")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue