debianize-mobilizon/test/graphql/resolvers/conversation_test.exs
Thomas Citharel b5672cee7e
WIP
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2023-11-14 14:24:17 +01:00

79 lines
2.2 KiB
Elixir

defmodule Mobilizon.GraphQL.Resolvers.ConversationTest do
use Mobilizon.Web.ConnCase
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.GraphQL.AbsintheHelpers
import Mobilizon.Factory
setup %{conn: conn} do
user = insert(:user)
actor = insert(:actor, user: user, preferred_username: "test")
{:ok, conn: conn, user: user, actor: actor}
end
@event_conversations_query """
query Event($uuid: UUID!) {
event(uuid: $uuid) {
id
uuid
conversations {
total
elements {
id
lastComment {
id
text
}
comments {
total
elements {
id
text
}
}
actor {
id
preferredUsername
}
}
}
}
}
"""
describe "Find conversations for event" do
test "for a given event", %{conn: conn, user: user, actor: actor} do
event = insert(:event, organizer_actor: actor)
conversation = insert(:conversation, event: event)
another_comment = build(:comment, origin_comment: conversation.origin_comment)
conversation_participant =
insert(:conversation_participant, actor: actor, conversation: conversation)
res =
conn
|> auth_conn(user)
|> AbsintheHelpers.graphql_query(
query: @event_conversations_query,
variables: %{uuid: conversation.event.uuid}
)
assert res["errors"] == nil
assert res["data"]["event"]["uuid"] == to_string(conversation.event.uuid)
assert res["data"]["event"]["conversations"]["total"] == 1
conversation_data = hd(res["data"]["event"]["conversations"]["elements"])
assert conversation_data["id"] == to_string(conversation.id)
assert conversation_data["lastComment"]["text"] == conversation.last_comment.text
assert conversation_data["comments"]["total"] == 2
assert conversation_data["comments"]["elements"]
|> Enum.any?(fn comment -> comment.text == conversation.origin_comment.text end)
assert conversation_data["actor"]["preferredUsername"] ==
conversation_participant.actor.preferred_username
end
end
end