Generate * from *Map
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
4bcae3597f
commit
5c62c50e9b
6 changed files with 25 additions and 2 deletions
|
@ -26,7 +26,7 @@ defp map_to_str_impl(data, mode) do
|
|||
|> Enum.join(sep(mode))
|
||||
else
|
||||
[lang] -> data[lang]
|
||||
_ -> ""
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -86,7 +86,9 @@ defp fix(data) do
|
|||
|> fix_attachments()
|
||||
|> CommonFixes.fix_quote_url()
|
||||
|> Transmogrifier.fix_emoji()
|
||||
|> Transmogrifier.fix_content_map()
|
||||
|> CommonFixes.fix_multilang_field("content", "contentMap", multiline: true)
|
||||
|> CommonFixes.fix_multilang_field("summary", "summaryMap", multiline: false)
|
||||
|> CommonFixes.fix_multilang_field("name", "nameMap", multiline: false)
|
||||
|> CommonFixes.maybe_add_language()
|
||||
|> CommonFixes.maybe_add_content_map()
|
||||
end
|
||||
|
|
|
@ -102,6 +102,9 @@ defp fix(data) do
|
|||
|> CommonFixes.fix_quote_url()
|
||||
|> Transmogrifier.fix_emoji()
|
||||
|> fix_url()
|
||||
|> CommonFixes.fix_multilang_field("content", "contentMap", multiline: true)
|
||||
|> CommonFixes.fix_multilang_field("summary", "summaryMap", multiline: false)
|
||||
|> CommonFixes.fix_multilang_field("name", "nameMap", multiline: false)
|
||||
|> fix_content()
|
||||
end
|
||||
|
||||
|
|
|
@ -194,4 +194,13 @@ def maybe_add_content_map(%{"language" => language, "content" => content} = obje
|
|||
end
|
||||
|
||||
def maybe_add_content_map(object), do: object
|
||||
|
||||
def fix_multilang_field(data, str_field, map_field, opts \\ []) do
|
||||
with %{} = map <- data[map_field],
|
||||
str when is_binary(str) <- Pleroma.MultiLanguage.map_to_str(map, opts) do
|
||||
Map.put(data, str_field, str)
|
||||
else
|
||||
_ -> data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -67,6 +67,9 @@ defp fix(data) do
|
|||
|> CommonFixes.fix_quote_url()
|
||||
|> Transmogrifier.fix_emoji()
|
||||
|> fix_closed()
|
||||
|> CommonFixes.fix_multilang_field("content", "contentMap", multiline: true)
|
||||
|> CommonFixes.fix_multilang_field("summary", "summaryMap", multiline: false)
|
||||
|> CommonFixes.fix_multilang_field("name", "nameMap", multiline: false)
|
||||
end
|
||||
|
||||
def changeset(struct, data) do
|
||||
|
|
|
@ -54,9 +54,14 @@ test "Note with contentMap and summaryMap", %{note: note} do
|
|||
|> Map.put("summaryMap", summary_map)
|
||||
|> Map.put("contentMap", content_map)
|
||||
|
||||
expected_summary = Pleroma.MultiLanguage.map_to_str(summary_map, multiline: false)
|
||||
expected_content = Pleroma.MultiLanguage.map_to_str(content_map, multiline: true)
|
||||
|
||||
assert %{
|
||||
valid?: true,
|
||||
changes: %{
|
||||
summary: ^expected_summary,
|
||||
content: ^expected_content,
|
||||
summaryMap: ^summary_map,
|
||||
contentMap: ^content_map
|
||||
}
|
||||
|
@ -74,6 +79,7 @@ test "Note with empty *Map", %{note: note} do
|
|||
changes: changes
|
||||
} = ArticleNotePageValidator.cast_and_validate(note)
|
||||
|
||||
assert changes.content == note["content"]
|
||||
assert Map.has_key?(changes, :summaryMap)
|
||||
refute Map.has_key?(changes, :contentMap)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue