fix tests
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
305a8d9c98
commit
e80715c06d
18 changed files with 73 additions and 26 deletions
|
@ -91,7 +91,7 @@ defp get_description(upload) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp validate_description_limit(%{} = description) do
|
defp validate_description_limit(%{} = description) do
|
||||||
Enum.each(description, fn content ->
|
Enum.all?(description, fn {_, content} ->
|
||||||
String.length(content) <= Pleroma.Config.get([:instance, :description_limit])
|
String.length(content) <= Pleroma.Config.get([:instance, :description_limit])
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -86,6 +86,7 @@ defp fix(data) do
|
||||||
|> fix_attachments()
|
|> fix_attachments()
|
||||||
|> CommonFixes.fix_quote_url()
|
|> CommonFixes.fix_quote_url()
|
||||||
|> Transmogrifier.fix_emoji()
|
|> Transmogrifier.fix_emoji()
|
||||||
|
|> Transmogrifier.fix_content_map()
|
||||||
|> CommonFixes.maybe_add_language()
|
|> CommonFixes.maybe_add_language()
|
||||||
|> CommonFixes.maybe_add_content_map()
|
|> CommonFixes.maybe_add_content_map()
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do
|
||||||
|
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:name, :string)
|
field(:name, :string)
|
||||||
field(:nameRendered, :string)
|
|
||||||
field(:nameMap, ObjectValidators.ContentLanguageMap)
|
field(:nameMap, ObjectValidators.ContentLanguageMap)
|
||||||
|
|
||||||
embeds_one :replies, Replies, primary_key: false do
|
embeds_one :replies, Replies, primary_key: false do
|
||||||
|
@ -26,7 +25,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator do
|
||||||
|
|
||||||
def changeset(struct, data) do
|
def changeset(struct, data) do
|
||||||
struct
|
struct
|
||||||
|> cast(data, [:name, :nameRendered, :nameMap, :type])
|
|> cast(data, [:name, :nameMap, :type])
|
||||||
|> cast_embed(:replies, with: &replies_changeset/2)
|
|> cast_embed(:replies, with: &replies_changeset/2)
|
||||||
|> validate_inclusion(:type, ["Note"])
|
|> validate_inclusion(:type, ["Note"])
|
||||||
|> validate_required([:name, :type])
|
|> validate_required([:name, :type])
|
||||||
|
|
|
@ -103,6 +103,11 @@ defp update_request do
|
||||||
type: :string,
|
type: :string,
|
||||||
description: "A plain-text description of the media, for accessibility purposes."
|
description: "A plain-text description of the media, for accessibility purposes."
|
||||||
}),
|
}),
|
||||||
|
language: %Schema{
|
||||||
|
type: :string,
|
||||||
|
nullable: true,
|
||||||
|
description: "ISO 639 language code for this status."
|
||||||
|
},
|
||||||
focus: %Schema{
|
focus: %Schema{
|
||||||
type: :string,
|
type: :string,
|
||||||
description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
|
description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
|
||||||
|
|
|
@ -163,7 +163,9 @@ defp language(%{params: %{language: language}} = draft) when not is_nil(language
|
||||||
|
|
||||||
defp language(%{status: status} = draft) when is_binary(status) do
|
defp language(%{status: status} = draft) when is_binary(status) do
|
||||||
detected_language =
|
detected_language =
|
||||||
LanguageDetector.detect(draft.status <> " " <> (draft.summary || draft.params[:summary]))
|
LanguageDetector.detect(
|
||||||
|
draft.status <> " " <> (draft.summary || draft.params[:summary] || draft.params[:name])
|
||||||
|
)
|
||||||
|
|
||||||
if MultiLanguage.good_locale_code?(detected_language) do
|
if MultiLanguage.good_locale_code?(detected_language) do
|
||||||
%__MODULE__{
|
%__MODULE__{
|
||||||
|
@ -535,7 +537,7 @@ defp differentiate_string_map(str) when is_binary(str), do: {str, nil}
|
||||||
|
|
||||||
defp get_source_map(%{status_map: %{} = status_map} = draft) do
|
defp get_source_map(%{status_map: %{} = status_map} = draft) do
|
||||||
%{
|
%{
|
||||||
"content" => Map.get(status_map, draft.language),
|
"content" => Map.get(draft, :status),
|
||||||
"contentMap" => status_map
|
"contentMap" => status_map
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,10 @@ def create(
|
||||||
{_, true} <-
|
{_, true} <-
|
||||||
{:valid_locale,
|
{:valid_locale,
|
||||||
Map.get(data, :description_map) == nil or MultiLanguage.good_locale_code?(language)},
|
Map.get(data, :description_map) == nil or MultiLanguage.good_locale_code?(language)},
|
||||||
|
{_, true} <-
|
||||||
|
{:locale_included,
|
||||||
|
Map.get(data, :description_map) == nil or
|
||||||
|
Map.has_key?(Map.get(data, :description_map), language)},
|
||||||
{:ok, object} <-
|
{:ok, object} <-
|
||||||
ActivityPub.upload(
|
ActivityPub.upload(
|
||||||
file,
|
file,
|
||||||
|
@ -44,6 +48,9 @@ def create(
|
||||||
{:valid_locale, _} ->
|
{:valid_locale, _} ->
|
||||||
render_error(conn, 422, "valid language must be provided with description_map")
|
render_error(conn, 422, "valid language must be provided with description_map")
|
||||||
|
|
||||||
|
{:locale_included, _} ->
|
||||||
|
render_error(conn, 422, "the provided language must be included in description_map")
|
||||||
|
|
||||||
{:error, e} ->
|
{:error, e} ->
|
||||||
conn
|
conn
|
||||||
|> put_status(:unprocessable_entity)
|
|> put_status(:unprocessable_entity)
|
||||||
|
@ -63,6 +70,10 @@ def create2(
|
||||||
{_, true} <-
|
{_, true} <-
|
||||||
{:valid_locale,
|
{:valid_locale,
|
||||||
Map.get(data, :description_map) == nil or MultiLanguage.good_locale_code?(language)},
|
Map.get(data, :description_map) == nil or MultiLanguage.good_locale_code?(language)},
|
||||||
|
{_, true} <-
|
||||||
|
{:locale_included,
|
||||||
|
Map.get(data, :description_map) == nil or
|
||||||
|
Map.has_key?(Map.get(data, :description_map), language)},
|
||||||
{:ok, object} <-
|
{:ok, object} <-
|
||||||
ActivityPub.upload(
|
ActivityPub.upload(
|
||||||
file,
|
file,
|
||||||
|
@ -80,6 +91,9 @@ def create2(
|
||||||
{:valid_locale, _} ->
|
{:valid_locale, _} ->
|
||||||
render_error(conn, 422, "valid language must be provided with description_map")
|
render_error(conn, 422, "valid language must be provided with description_map")
|
||||||
|
|
||||||
|
{:locale_included, _} ->
|
||||||
|
render_error(conn, 422, "the provided language must be included in description_map")
|
||||||
|
|
||||||
{:error, e} ->
|
{:error, e} ->
|
||||||
conn
|
conn
|
||||||
|> put_status(:unprocessable_entity)
|
|> put_status(:unprocessable_entity)
|
||||||
|
@ -104,9 +118,9 @@ def update(
|
||||||
) do
|
) do
|
||||||
with %Object{} = object <- Object.get_by_id(id),
|
with %Object{} = object <- Object.get_by_id(id),
|
||||||
:ok <- Object.authorize_access(object, user),
|
:ok <- Object.authorize_access(object, user),
|
||||||
language = Map.get(body_params, :language, object["language"]),
|
language = Map.get(body_params, :language, object.data["language"]),
|
||||||
{_, true} <-
|
{_, true} <- {:valid_locale, MultiLanguage.good_locale_code?(language)},
|
||||||
{:valid_locale, description_map == nil or MultiLanguage.good_locale_code?(language)},
|
{_, true} <- {:locale_included, Map.has_key?(description_map, language)},
|
||||||
{_, {:ok, %{}}} <- {:description_map, MultiLanguage.validate_map(description_map)},
|
{_, {:ok, %{}}} <- {:description_map, MultiLanguage.validate_map(description_map)},
|
||||||
{:ok, %Object{data: data}} <-
|
{:ok, %Object{data: data}} <-
|
||||||
Object.update_data(object, %{
|
Object.update_data(object, %{
|
||||||
|
@ -120,6 +134,9 @@ def update(
|
||||||
{:valid_locale, _} ->
|
{:valid_locale, _} ->
|
||||||
render_error(conn, 422, "valid language must be provided with description_map")
|
render_error(conn, 422, "valid language must be provided with description_map")
|
||||||
|
|
||||||
|
{:locale_included, _} ->
|
||||||
|
render_error(conn, 422, "the provided language must be included in description_map")
|
||||||
|
|
||||||
{:description_map, _} ->
|
{:description_map, _} ->
|
||||||
render_error(conn, 422, "description_map not valid")
|
render_error(conn, 422, "description_map not valid")
|
||||||
end
|
end
|
||||||
|
|
|
@ -212,7 +212,14 @@ def create(
|
||||||
} = conn,
|
} = conn,
|
||||||
_
|
_
|
||||||
) do
|
) do
|
||||||
create(conn |> put_in([:private, :open_api_spex, :body_params, :status], ""), %{})
|
create(
|
||||||
|
put_in(
|
||||||
|
conn,
|
||||||
|
[Access.key(:private), Access.key(:open_api_spex), Access.key(:body_params), :status],
|
||||||
|
""
|
||||||
|
),
|
||||||
|
%{}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(
|
def create(
|
||||||
|
@ -222,7 +229,14 @@ def create(
|
||||||
} = conn,
|
} = conn,
|
||||||
_
|
_
|
||||||
) do
|
) do
|
||||||
create(conn |> put_in([:private, :open_api_spex, :body_params, :status], ""), %{})
|
create(
|
||||||
|
put_in(
|
||||||
|
conn,
|
||||||
|
[Access.key(:private), Access.key(:open_api_spex), Access.key(:body_params), :status],
|
||||||
|
""
|
||||||
|
),
|
||||||
|
%{}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp do_create(
|
defp do_create(
|
||||||
|
|
|
@ -65,7 +65,7 @@ defp options_and_votes_count(options) do
|
||||||
current_count = option["replies"]["totalItems"] || 0
|
current_count = option["replies"]["totalItems"] || 0
|
||||||
|
|
||||||
{%{
|
{%{
|
||||||
title: option["nameRendered"] || name,
|
title: name,
|
||||||
title_map: option["nameMap"] || %{},
|
title_map: option["nameMap"] || %{},
|
||||||
votes_count: current_count
|
votes_count: current_count
|
||||||
}, current_count + count}
|
}, current_count + count}
|
||||||
|
|
|
@ -1412,7 +1412,7 @@ test "sets a description if given", %{test_file: file} do
|
||||||
|
|
||||||
test "sets a multilang description if given", %{test_file: file} do
|
test "sets a multilang description if given", %{test_file: file} do
|
||||||
{:ok, %Object{} = object} =
|
{:ok, %Object{} = object} =
|
||||||
ActivityPub.upload(file, description_map: %{"a" => "mew", "b" => "lol"})
|
ActivityPub.upload(file, description_map: %{"a" => "mew", "b" => "lol"}, language: "a")
|
||||||
|
|
||||||
assert object.data["nameMap"] == %{"a" => "mew", "b" => "lol"}
|
assert object.data["nameMap"] == %{"a" => "mew", "b" => "lol"}
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,7 +56,8 @@ test "accepts multilang" do
|
||||||
tags: [],
|
tags: [],
|
||||||
summary_map: %{"a" => "mew", "b" => "lol"},
|
summary_map: %{"a" => "mew", "b" => "lol"},
|
||||||
cc: [],
|
cc: [],
|
||||||
extra: %{}
|
extra: %{},
|
||||||
|
language: "a"
|
||||||
}
|
}
|
||||||
|
|
||||||
assert {:ok,
|
assert {:ok,
|
||||||
|
|
|
@ -20,7 +20,7 @@ test "" do
|
||||||
"nameMap" => name_map
|
"nameMap" => name_map
|
||||||
}
|
}
|
||||||
|
|
||||||
assert %{valid?: true, changes: %{nameMap: ^name_map, nameRendered: _}} =
|
assert %{valid?: true, changes: %{nameMap: ^name_map, name: _}} =
|
||||||
QuestionOptionsValidator.changeset(%QuestionOptionsValidator{}, data)
|
QuestionOptionsValidator.changeset(%QuestionOptionsValidator{}, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -251,7 +251,7 @@ test "it only uses contentMap if content is not present" do
|
||||||
assert object.data["content"] == "Hi"
|
assert object.data["content"] == "Hi"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it works for incoming notices with a nil contentMap (firefish)" do
|
test "it works for incoming notices with a nil content (firefish)" do
|
||||||
data =
|
data =
|
||||||
File.read!("test/fixtures/mastodon-post-activity-contentmap.json")
|
File.read!("test/fixtures/mastodon-post-activity-contentmap.json")
|
||||||
|> Jason.decode!()
|
|> Jason.decode!()
|
||||||
|
|
|
@ -19,7 +19,8 @@ test "content", %{user: user} do
|
||||||
{:ok, draft} =
|
{:ok, draft} =
|
||||||
ActivityDraft.create(user, %{
|
ActivityDraft.create(user, %{
|
||||||
status_map: %{"a" => "mew mew", "b" => "lol lol"},
|
status_map: %{"a" => "mew mew", "b" => "lol lol"},
|
||||||
spoiler_text_map: %{"a" => "mew", "b" => "lol"}
|
spoiler_text_map: %{"a" => "mew", "b" => "lol"},
|
||||||
|
language: "a"
|
||||||
})
|
})
|
||||||
|
|
||||||
assert %{
|
assert %{
|
||||||
|
|
|
@ -740,7 +740,8 @@ test "multilang support" do
|
||||||
%{"a" => "bar", "c" => "2"}
|
%{"a" => "bar", "c" => "2"}
|
||||||
],
|
],
|
||||||
expires_in: 600
|
expires_in: 600
|
||||||
}
|
},
|
||||||
|
language: "a"
|
||||||
})
|
})
|
||||||
|
|
||||||
assert %{"oneOf" => choices} = poll
|
assert %{"oneOf" => choices} = poll
|
||||||
|
|
|
@ -55,7 +55,8 @@ test "/api/v1/media, multilang", %{conn: conn, image: image} do
|
||||||
|> put_req_header("content-type", "multipart/form-data")
|
|> put_req_header("content-type", "multipart/form-data")
|
||||||
|> post("/api/v1/media", %{
|
|> post("/api/v1/media", %{
|
||||||
"file" => image,
|
"file" => image,
|
||||||
"description_map" => %{"a" => "mew", "b" => "lol"}
|
"description_map" => %{"a" => "mew", "b" => "lol"},
|
||||||
|
"language" => "a"
|
||||||
})
|
})
|
||||||
|> json_response_and_validate_schema(:ok)
|
|> json_response_and_validate_schema(:ok)
|
||||||
|
|
||||||
|
@ -119,7 +120,8 @@ test "/api/v2/media, multilang", %{conn: conn, image: image} do
|
||||||
|> put_req_header("content-type", "multipart/form-data")
|
|> put_req_header("content-type", "multipart/form-data")
|
||||||
|> post("/api/v2/media", %{
|
|> post("/api/v2/media", %{
|
||||||
"file" => image,
|
"file" => image,
|
||||||
"description_map" => %{"a" => "mew", "b" => "lol"}
|
"description_map" => %{"a" => "mew", "b" => "lol"},
|
||||||
|
"language" => "a"
|
||||||
})
|
})
|
||||||
|> json_response_and_validate_schema(202)
|
|> json_response_and_validate_schema(202)
|
||||||
|
|
||||||
|
@ -261,7 +263,8 @@ test "/api/v1/media/:id description_map", %{conn: conn, object: object} do
|
||||||
conn
|
conn
|
||||||
|> put_req_header("content-type", "multipart/form-data")
|
|> put_req_header("content-type", "multipart/form-data")
|
||||||
|> put("/api/v1/media/#{object.id}", %{
|
|> put("/api/v1/media/#{object.id}", %{
|
||||||
"description_map" => %{"a" => "test-media", "b" => "xxx"}
|
"description_map" => %{"a" => "test-media", "b" => "xxx"},
|
||||||
|
"language" => "a"
|
||||||
})
|
})
|
||||||
|> json_response_and_validate_schema(:ok)
|
|> json_response_and_validate_schema(:ok)
|
||||||
|
|
||||||
|
|
|
@ -321,6 +321,7 @@ test "posting a multilang summary with singlelang status", %{conn: conn} do
|
||||||
|> put_req_header("idempotency-key", idempotency_key)
|
|> put_req_header("idempotency-key", idempotency_key)
|
||||||
|> post("/api/v1/statuses", %{
|
|> post("/api/v1/statuses", %{
|
||||||
"spoiler_text_map" => %{"a" => "mew mew", "b" => "lol lol"},
|
"spoiler_text_map" => %{"a" => "mew mew", "b" => "lol lol"},
|
||||||
|
"language" => "a",
|
||||||
"status" => "mewlol",
|
"status" => "mewlol",
|
||||||
"sensitive" => "0"
|
"sensitive" => "0"
|
||||||
})
|
})
|
||||||
|
@ -864,7 +865,8 @@ test "posting a multilang poll", %{conn: conn} do
|
||||||
%{"a" => "Misato", "b" => "3"}
|
%{"a" => "Misato", "b" => "3"}
|
||||||
],
|
],
|
||||||
"expires_in" => 420
|
"expires_in" => 420
|
||||||
}
|
},
|
||||||
|
"language" => "a"
|
||||||
})
|
})
|
||||||
|
|
||||||
response = json_response_and_validate_schema(conn, 200)
|
response = json_response_and_validate_schema(conn, 200)
|
||||||
|
|
|
@ -175,8 +175,7 @@ test "renders multilang" do
|
||||||
"oneOf" => [
|
"oneOf" => [
|
||||||
%{
|
%{
|
||||||
"name" => "mew",
|
"name" => "mew",
|
||||||
"nameMap" => %{"en" => "mew", "cmn" => "喵"},
|
"nameMap" => %{"en" => "mew", "cmn" => "喵"}
|
||||||
"nameRendered" => "mew | 喵"
|
|
||||||
},
|
},
|
||||||
%{"name" => "mew mew", "nameMap" => %{"en" => "mew mew", "cmn" => "喵喵"}}
|
%{"name" => "mew mew", "nameMap" => %{"en" => "mew mew", "cmn" => "喵喵"}}
|
||||||
]
|
]
|
||||||
|
@ -185,7 +184,7 @@ test "renders multilang" do
|
||||||
|
|
||||||
assert %{
|
assert %{
|
||||||
options: [
|
options: [
|
||||||
%{title: "mew | 喵", title_map: %{"en" => "mew", "cmn" => "喵"}},
|
%{title: "mew", title_map: %{"en" => "mew", "cmn" => "喵"}},
|
||||||
%{title: "mew mew", title_map: %{"en" => "mew mew", "cmn" => "喵喵"}}
|
%{title: "mew mew", title_map: %{"en" => "mew mew", "cmn" => "喵喵"}}
|
||||||
]
|
]
|
||||||
} = PollView.render("show.json", %{object: object})
|
} = PollView.render("show.json", %{object: object})
|
||||||
|
|
|
@ -380,7 +380,6 @@ test "a note activity with multiple languages" do
|
||||||
content_map: %{"en" => "mew mew", "cmn" => "喵喵"},
|
content_map: %{"en" => "mew mew", "cmn" => "喵喵"},
|
||||||
spoiler_text: "mew",
|
spoiler_text: "mew",
|
||||||
spoiler_text_map: %{"en" => "mew", "cmn" => "喵"},
|
spoiler_text_map: %{"en" => "mew", "cmn" => "喵"},
|
||||||
language: "mul",
|
|
||||||
pleroma: %{
|
pleroma: %{
|
||||||
content: %{"text/plain" => "mew mew"},
|
content: %{"text/plain" => "mew mew"},
|
||||||
content_map: %{"text/plain" => %{"en" => "mew mew", "cmn" => "喵喵"}},
|
content_map: %{"text/plain" => %{"en" => "mew mew", "cmn" => "喵喵"}},
|
||||||
|
@ -399,7 +398,8 @@ test "a note activity with single language" do
|
||||||
"content" => "mew mew",
|
"content" => "mew mew",
|
||||||
"contentMap" => %{"en" => "mew mew"},
|
"contentMap" => %{"en" => "mew mew"},
|
||||||
"summary" => "mew",
|
"summary" => "mew",
|
||||||
"summaryMap" => %{"en" => "mew"}
|
"summaryMap" => %{"en" => "mew"},
|
||||||
|
"language" => "en"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -686,6 +686,7 @@ test "Complete Mastodon style" do
|
||||||
preview_url: "someurl",
|
preview_url: "someurl",
|
||||||
text_url: "someurl",
|
text_url: "someurl",
|
||||||
description: nil,
|
description: nil,
|
||||||
|
description_map: %{},
|
||||||
pleroma: %{mime_type: "image/png"},
|
pleroma: %{mime_type: "image/png"},
|
||||||
meta: %{original: %{width: 200, height: 100, aspect: 2}},
|
meta: %{original: %{width: 200, height: 100, aspect: 2}},
|
||||||
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
|
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
|
||||||
|
@ -720,6 +721,7 @@ test "Honkerific" do
|
||||||
expected = %{
|
expected = %{
|
||||||
blurhash: nil,
|
blurhash: nil,
|
||||||
description: "they have played us for absolute fools.",
|
description: "they have played us for absolute fools.",
|
||||||
|
description_map: %{},
|
||||||
id: "1638338801",
|
id: "1638338801",
|
||||||
pleroma: %{mime_type: "image/png", name: "fool.jpeg"},
|
pleroma: %{mime_type: "image/png", name: "fool.jpeg"},
|
||||||
preview_url: "someurl",
|
preview_url: "someurl",
|
||||||
|
|
Loading…
Reference in a new issue