An IndieWeb engine for a self-hostable website. https://koype.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

content_test.exs 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. defmodule IndieWeb.Micropub.ContentTest do
  2. use Koype.DataCase
  3. use ExVCR.Mock
  4. alias IndieWeb.Micropub.Content
  5. doctest Content
  6. describe ".process_property/2" do
  7. test "processes location value with GeoURI" do
  8. {:ok, result} = Content.process_property("location", "geo:40.0,-100.0")
  9. assert %{lat: 40.0, lng: -100.0} = result
  10. end
  11. test "processes existing single category value" do
  12. category = insert(:category)
  13. assert {:ok, result} = Content.process_property("category", category.name)
  14. assert result.name =~ category.name
  15. end
  16. test "processes new single category value" do
  17. category = Faker.Lorem.word()
  18. assert {:ok, result} = Content.process_property("category", category)
  19. assert result.name =~ category
  20. assert {:ok, next_result} = Content.process_property("category", category)
  21. assert next_result.id == result.id
  22. end
  23. test "processes new multiple category values" do
  24. categories = Faker.Lorem.words()
  25. {:ok, result} = Content.process_property("category", categories)
  26. for category <- categories do
  27. assert Enum.any?(result, fn r -> r.name =~ category end)
  28. end
  29. end
  30. end
  31. describe ".parse_extensions/2" do
  32. test "ignores unknown extensions that are parsed to it" do
  33. model = insert(:entry)
  34. assert {:ok, ^model} = Content.parse_extensions(model, %{"mp-magic" => "foo"})
  35. end
  36. test "mp-slug: removes slug if value is emptied and slug is set" do
  37. model = insert(:entry, slug: "foobar")
  38. assert {:ok, %Koype.Repo.Entry{slug: nil}} = Content.parse_extensions(model, %{"mp-slug" => ""})
  39. end
  40. test "mp-slug: does nothing if value is emptied and slug is empty" do
  41. model = insert(:entry, slug: nil)
  42. assert {:ok, ^model} = Content.parse_extensions(model, %{"mp-slug" => ""})
  43. end
  44. test "mp-slug: adds slug if value is provided" do
  45. model = insert(:entry)
  46. assert {:ok, %Koype.Repo.Entry{slug: "foobar"}} = Content.parse_extensions(model, %{"mp-slug" => "foobar"})
  47. end
  48. test "mp-syndicate-to: does not create syndication results on unknown target IDs" do
  49. model = insert(:entry)
  50. assert {:ok, ^model} = Content.parse_extensions(model, %{"mp-syndicate-to" => [Faker.UUID.v4()]})
  51. end
  52. test "mp-syndicate-to: sends request to endpoint of syndication target" do
  53. model = insert(:entry)
  54. targets = insert_list(3, :syndication_target)
  55. syndication_target_ids = Enum.map(targets, & &1.id)
  56. use_cassette :stub, uri: "~r/*/", method: "post" do
  57. assert {:ok, ^model} = Content.parse_extensions(model, %{"mp-syndicate-to" => syndication_target_ids})
  58. end
  59. end
  60. end
  61. describe ".expand_property/2" do
  62. @describetag skip: true
  63. test "start: expands to NaiveDateTime"
  64. test "end: expands to NaiveDateTime"
  65. end
  66. end