defmodule Mobilizon.Service.MetadataTest do alias Mobilizon.Actors.Actor alias Mobilizon.Discussions.Comment alias Mobilizon.Events.Event alias Mobilizon.Posts.Post alias Mobilizon.Service.Metadata alias Mobilizon.Tombstone alias Mobilizon.Web.Endpoint alias Mobilizon.Web.Router.Helpers, as: Routes use Mobilizon.DataCase import Mobilizon.Factory describe "build_tags/2 for an actor" do test "that is a group gives tags" do %Actor{} = group = insert(:group, name: "My group") assert group |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "" assert group |> Map.put(:avatar, nil) |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "" end test "that is not a group doesn't give anything" do %Actor{} = person = insert(:actor) assert person |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "" assert person |> Metadata.build_tags("fr") |> Metadata.Utils.stringify_tags() == "" end end describe "build_tags/2 for an event" do test "gives tags" do alias Mobilizon.Web.Endpoint %Event{} = event = insert(:event) # Because the description in Schema.org data is double-escaped a = "\n" b = "\\n" assert event |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "#{event.title} - Mobilizon" assert event |> Map.put(:picture, nil) |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "#{event.title} - Mobilizon" end end describe "build_tags/2 for a post" do test "gives tags" do %Post{} = post = insert(:post) assert post |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "" end end describe "build_tags/2 for a comment" do test "gives tags" do %Comment{} = comment = insert(:comment) assert comment |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "" end end describe "build_tags/2 for a tombstone" do test "gives nothing" do %Tombstone{} = tombstone = insert(:tombstone) assert tombstone |> Metadata.build_tags() |> Metadata.Utils.stringify_tags() == "" end end end