Fix tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-09-23 10:26:23 +02:00
parent 5520e2e5f9
commit 9abb2f3526
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
4 changed files with 50 additions and 88 deletions

View File

@ -3,6 +3,7 @@ defmodule MobilizonWeb.API.Events do
API for Events API for Events
""" """
alias Mobilizon.Events.Event alias Mobilizon.Events.Event
alias Mobilizon.Actors.Actor
alias Mobilizon.Service.ActivityPub alias Mobilizon.Service.ActivityPub
alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils alias Mobilizon.Service.ActivityPub.Utils, as: ActivityPubUtils
alias Mobilizon.Service.ActivityPub.Activity alias Mobilizon.Service.ActivityPub.Activity
@ -13,39 +14,19 @@ defmodule MobilizonWeb.API.Events do
""" """
@spec create_event(map()) :: {:ok, Activity.t(), Event.t()} | any() @spec create_event(map()) :: {:ok, Activity.t(), Event.t()} | any()
def create_event(%{organizer_actor: organizer_actor} = args) do def create_event(%{organizer_actor: organizer_actor} = args) do
with %{ with args <- prepare_args(args),
title: title,
physical_address: physical_address,
picture: picture,
content_html: content_html,
tags: tags,
to: to,
cc: cc,
begins_on: begins_on,
ends_on: ends_on,
category: category,
join_options: join_options,
options: options
} <- prepare_args(args),
event <- event <-
ActivityPubUtils.make_event_data( ActivityPubUtils.make_event_data(
organizer_actor.url, args.organizer_actor.url,
%{to: to, cc: cc}, %{to: args.to, cc: args.cc},
title, args.title,
content_html, args.content_html,
picture, args.picture,
tags, args.tags,
%{ args.metadata
begins_on: begins_on,
ends_on: ends_on,
physical_address: physical_address,
category: category,
options: options,
join_options: join_options
}
) do ) do
ActivityPub.create(%{ ActivityPub.create(%{
to: ["https://www.w3.org/ns/activitystreams#Public"], to: args.to,
actor: organizer_actor, actor: organizer_actor,
object: event, object: event,
local: true local: true
@ -64,42 +45,21 @@ defmodule MobilizonWeb.API.Events do
%Event{} = event %Event{} = event
) do ) do
with args <- Map.put(args, :tags, Map.get(args, :tags, [])), with args <- Map.put(args, :tags, Map.get(args, :tags, [])),
%{ args <- prepare_args(Map.merge(event, args)),
title: title,
physical_address: physical_address,
picture: picture,
content_html: content_html,
tags: tags,
to: to,
cc: cc,
begins_on: begins_on,
ends_on: ends_on,
category: category,
join_options: join_options,
options: options
} <-
prepare_args(Map.merge(event, args)),
event <- event <-
ActivityPubUtils.make_event_data( ActivityPubUtils.make_event_data(
organizer_actor.url, args.organizer_actor.url,
%{to: to, cc: cc}, %{to: args.to, cc: args.cc},
title, args.title,
content_html, args.content_html,
picture, args.picture,
tags, args.tags,
%{ args.metadata,
begins_on: begins_on,
ends_on: ends_on,
physical_address: physical_address,
category: category,
join_options: join_options,
options: options
},
event.uuid, event.uuid,
event.url event.url
) do ) do
ActivityPub.update(%{ ActivityPub.update(%{
to: ["https://www.w3.org/ns/activitystreams#Public"], to: args.to,
actor: organizer_actor.url, actor: organizer_actor.url,
cc: [], cc: [],
object: event, object: event,
@ -108,37 +68,33 @@ defmodule MobilizonWeb.API.Events do
end end
end end
defp prepare_args( defp prepare_args(args) do
%{ with %Actor{} = organizer_actor <- Map.get(args, :organizer_actor),
organizer_actor: organizer_actor, title <- args |> Map.get(:title, "") |> String.trim(),
title: title,
description: description,
options: options,
tags: tags,
begins_on: begins_on,
category: category,
join_options: join_options
} = args
) do
with physical_address <- Map.get(args, :physical_address, nil),
title <- String.trim(title),
visibility <- Map.get(args, :visibility, :public), visibility <- Map.get(args, :visibility, :public),
picture <- Map.get(args, :picture, nil), description <- Map.get(args, :description),
tags <- Map.get(args, :tags),
{content_html, tags, to, cc} <- {content_html, tags, to, cc} <-
Utils.prepare_content(organizer_actor, description, visibility, tags, nil) do Utils.prepare_content(organizer_actor, description, visibility, tags, nil) do
%{ %{
title: title, title: title,
physical_address: physical_address,
picture: picture,
content_html: content_html, content_html: content_html,
picture: Map.get(args, :picture),
tags: tags, tags: tags,
organizer_actor: organizer_actor,
to: to, to: to,
cc: cc, cc: cc,
begins_on: begins_on, metadata: %{
ends_on: Map.get(args, :ends_on, nil), begins_on: Map.get(args, :begins_on),
category: category, ends_on: Map.get(args, :ends_on),
join_options: join_options, physical_address: Map.get(args, :physical_address),
options: options category: Map.get(args, :category),
options: Map.get(args, :options),
join_options: Map.get(args, :join_options),
status: Map.get(args, :status),
online_address: Map.get(args, :online_address),
phone_address: Map.get(args, :phone_address)
}
} }
end end
end end

View File

@ -62,6 +62,9 @@ defmodule Mobilizon.Service.ActivityPub.Converters.Event do
"category" => object["category"], "category" => object["category"],
"visibility" => visibility, "visibility" => visibility,
"join_options" => object["joinOptions"], "join_options" => object["joinOptions"],
"status" => object["status"],
"online_address" => object["onlineAddress"],
"phone_address" => object["phoneAddress"],
"url" => object["id"], "url" => object["id"],
"uuid" => object["uuid"], "uuid" => object["uuid"],
"tags" => tags, "tags" => tags,

View File

@ -329,6 +329,9 @@ defmodule Mobilizon.Service.ActivityPub.Utils do
"actor" => actor, "actor" => actor,
"id" => url || Routes.page_url(Endpoint, :event, uuid), "id" => url || Routes.page_url(Endpoint, :event, uuid),
"joinOptions" => metadata.join_options, "joinOptions" => metadata.join_options,
"status" => metadata.status,
"onlineAddress" => metadata.online_address,
"phoneAddress" => metadata.phone_address,
"uuid" => uuid, "uuid" => uuid,
"tag" => "tag" =>
tags |> Enum.uniq() |> Enum.map(fn tag -> %{"type" => "Hashtag", "name" => "##{tag}"} end) tags |> Enum.uniq() |> Enum.map(fn tag -> %{"type" => "Hashtag", "name" => "##{tag}"} end)

View File

@ -173,11 +173,11 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
assert event["description"] == "it will be fine" assert event["description"] == "it will be fine"
assert event["begins_on"] == begins_on assert event["begins_on"] == begins_on
assert event["ends_on"] == ends_on assert event["ends_on"] == ends_on
# assert event["status"] == "TENTATIVE" assert event["status"] == "TENTATIVE"
# assert event["visibility"] == "UNLISTED" assert event["visibility"] == "UNLISTED"
assert event["organizer_actor"]["id"] == "#{actor.id}" assert event["organizer_actor"]["id"] == "#{actor.id}"
# assert event["online_address"] == "toto@example.com" assert event["online_address"] == "toto@example.com"
# assert event["phone_address"] == "0000000000" assert event["phone_address"] == "0000000000"
assert event["category"] == "super_category" assert event["category"] == "super_category"
assert event["options"]["maximumAttendeeCapacity"] == 30 assert event["options"]["maximumAttendeeCapacity"] == 30
assert event["options"]["showRemainingAttendeeCapacity"] == true assert event["options"]["showRemainingAttendeeCapacity"] == true
@ -566,9 +566,9 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
assert event_res["description"] == "description updated" assert event_res["description"] == "description updated"
assert event_res["begins_on"] == "#{begins_on}" assert event_res["begins_on"] == "#{begins_on}"
assert event_res["ends_on"] == "#{ends_on}" assert event_res["ends_on"] == "#{ends_on}"
# assert eventResponse["status"] == "TENTATIVE" assert event_res["status"] == "TENTATIVE"
# assert eventResponse["online_address"] == "toto@example.com" assert event_res["online_address"] == "toto@example.com"
# assert eventResponse["phone_address"] == "0000000000" assert event_res["phone_address"] == "0000000000"
assert event_res["category"] == "birthday" assert event_res["category"] == "birthday"
assert event_res["options"]["maximumAttendeeCapacity"] == 30 assert event_res["options"]["maximumAttendeeCapacity"] == 30