logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

article_handling_test.exs (2934B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 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{
  14. status: 200,
  15. body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json"),
  16. headers: HttpRequestMock.activitypub_object_headers()
  17. }
  18. end)
  19. data =
  20. File.read!("test/fixtures/tesla_mock/wedistribute-create-article.json") |> Jason.decode!()
  21. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
  22. object = Object.normalize(data["object"], fetch: false)
  23. assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support"
  24. assert object.data["summary"] ==
  25. "One of the largest platforms in the federated social web is dropping the protocol that it started with."
  26. assert object.data["url"] == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
  27. end
  28. test "Plume Article" do
  29. Tesla.Mock.mock(fn
  30. %{url: "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} ->
  31. %Tesla.Env{
  32. status: 200,
  33. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json"),
  34. headers: HttpRequestMock.activitypub_object_headers()
  35. }
  36. %{url: "https://baptiste.gelez.xyz/@/BaptisteGelez"} ->
  37. %Tesla.Env{
  38. status: 200,
  39. body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json"),
  40. headers: HttpRequestMock.activitypub_object_headers()
  41. }
  42. end)
  43. {:ok, object} =
  44. Fetcher.fetch_object_from_id(
  45. "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
  46. )
  47. assert object.data["name"] == "This Month in Plume: June 2018"
  48. assert object.data["url"] ==
  49. "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
  50. end
  51. test "Prismo Article" do
  52. Tesla.Mock.mock(fn %{url: "https://prismo.news/@mxb"} ->
  53. %Tesla.Env{
  54. status: 200,
  55. body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json"),
  56. headers: HttpRequestMock.activitypub_object_headers()
  57. }
  58. end)
  59. data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!()
  60. {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
  61. object = Object.normalize(data["object"], fetch: false)
  62. assert object.data["url"] == "https://prismo.news/posts/83"
  63. end
  64. end