2021-10-04 18:59:41 +02:00
|
|
|
defmodule Mobilizon.Service.Export.Participants.CommonTest do
|
2022-03-23 15:22:14 +01:00
|
|
|
use Mobilizon.DataCase
|
2021-10-04 18:59:41 +02:00
|
|
|
|
|
|
|
import Mobilizon.Factory
|
|
|
|
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias Mobilizon.Service.Export.Participants.Common
|
2023-08-23 16:10:32 +02:00
|
|
|
import Mobilizon.Service.DateTime, only: [datetime_to_string: 1]
|
2021-10-04 18:59:41 +02:00
|
|
|
|
|
|
|
test "convert participants to list items" do
|
|
|
|
participant = insert(:participant)
|
|
|
|
actor = insert(:actor)
|
|
|
|
name = Actor.display_name_and_username(actor)
|
2023-08-23 16:10:32 +02:00
|
|
|
date = datetime_to_string(participant.inserted_at)
|
|
|
|
assert [^name, _, ^date, ""] = Common.to_list({participant, actor})
|
2021-10-04 18:59:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "convert participants with metadata to list items" do
|
|
|
|
participant = insert(:participant, metadata: %{message: "a message"})
|
|
|
|
actor = insert(:actor)
|
|
|
|
name = Actor.display_name_and_username(actor)
|
2023-08-23 16:10:32 +02:00
|
|
|
date = datetime_to_string(participant.inserted_at)
|
|
|
|
assert [^name, _, ^date, "a message"] = Common.to_list({participant, actor})
|
2021-10-04 18:59:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
test "convert anonymous participants to list items" do
|
|
|
|
participant = insert(:participant)
|
|
|
|
actor = insert(:actor, domain: nil, preferred_username: "anonymous")
|
2023-08-23 16:10:32 +02:00
|
|
|
date = datetime_to_string(participant.inserted_at)
|
|
|
|
assert ["Anonymous participant", _, ^date, ""] = Common.to_list({participant, actor})
|
2021-10-04 18:59:41 +02:00
|
|
|
end
|
|
|
|
end
|