defp paginate(entities, page, page_size) do
entities
- |> Enum.take(page * page_size)
- |> Enum.take(-page_size)
+ |> Enum.chunk_every(page_size)
+ |> Enum.at(page - 1)
end
@spec show(keyword()) :: {:ok, t()} | {:error, atom()}
# with the API so it should be sufficient
with {:create_dir, :ok} <- {:create_dir, File.mkdir_p(emoji_path)},
{:ls, {:ok, results}} <- {:ls, File.ls(emoji_path)} do
- {:ok, results}
+ {:ok, Enum.sort(results)}
else
{:create_dir, {:error, e}} -> {:error, :create_dir, e}
{:ls, {:error, e}} -> {:error, :ls, e}
resp = conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
assert resp["count"] == 3
+
+ assert resp["packs"]
+ |> Map.keys()
+ |> length() == 3
+
shared = resp["packs"]["test_pack"]
assert shared["files"] == %{"blank" => "blank.png", "blank2" => "blank2.png"}
assert Map.has_key?(shared["pack"], "download-sha256")
|> json_response_and_validate_schema(200)
assert resp["count"] == 3
- [pack1] = Map.keys(resp["packs"])
+
+ packs = Map.keys(resp["packs"])
+
+ assert length(packs) == 1
+
+ [pack1] = packs
resp =
conn
|> json_response_and_validate_schema(200)
assert resp["count"] == 3
- [pack2] = Map.keys(resp["packs"])
+ packs = Map.keys(resp["packs"])
+ assert length(packs) == 1
+ [pack2] = packs
resp =
conn
|> json_response_and_validate_schema(200)
assert resp["count"] == 3
- [pack3] = Map.keys(resp["packs"])
+ packs = Map.keys(resp["packs"])
+ assert length(packs) == 1
+ [pack3] = packs
assert [pack1, pack2, pack3] |> Enum.uniq() |> length() == 3
end