logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

article_handling_test.exs (2626B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
  5. use Oban.Testing, repo: Pleroma.Repo
  6. use Pleroma.DataCase
  7. alias Pleroma.Activity
  8. alias Pleroma.Object
  9. alias Pleroma.Object.Fetcher
  10. alias Pleroma.Web.ActivityPub.Transmogrifier
  11. test "Pterotype (Wordpress Plugin) Article" do
  12. Tesla.Mock.mock(fn %{url: "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog"} ->
  13. %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")}
  14. end)
  15. data =
  16. File.read!("test/fixtures/tesla_mock/wedistribute-create-article.json") |> Jason.decode!()
  17. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
  18. object = Object.normalize(data["object"])
  19. assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support"
  20. assert object.data["summary"] ==
  21. "One of the largest platforms in the federated social web is dropping the protocol that it started with."
  22. assert object.data["url"] == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
  23. end
  24. test "Plume Article" do
  25. Tesla.Mock.mock(fn
  26. %{url: "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} ->
  27. %Tesla.Env{
  28. status: 200,
  29. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
  30. }
  31. %{url: "https://baptiste.gelez.xyz/@/BaptisteGelez"} ->
  32. %Tesla.Env{
  33. status: 200,
  34. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
  35. }
  36. end)
  37. {:ok, object} =
  38. Fetcher.fetch_object_from_id(
  39. "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
  40. )
  41. assert object.data["name"] == "This Month in Plume: June 2018"
  42. assert object.data["url"] ==
  43. "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
  44. end
  45. test "Prismo Article" do
  46. Tesla.Mock.mock(fn %{url: "https://prismo.news/@mxb"} ->
  47. %Tesla.Env{
  48. status: 200,
  49. body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
  50. }
  51. end)
  52. data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!()
  53. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
  54. object = Object.normalize(data["object"])
  55. assert object.data["url"] == "https://prismo.news/posts/83"
  56. end
  57. end