2019-11-05 17:49:40 +01:00
|
|
|
defmodule Mobilizon.Service.ICalendarTest do
|
2022-03-23 15:22:14 +01:00
|
|
|
use Mobilizon.DataCase
|
2019-11-05 17:49:40 +01:00
|
|
|
|
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2020-01-28 20:15:59 +01:00
|
|
|
alias ICalendar.Value
|
|
|
|
|
|
|
|
alias Mobilizon.Addresses.Address
|
2021-03-26 15:40:10 +01:00
|
|
|
alias Mobilizon.Events.{Event, FeedToken}
|
2020-01-28 20:15:59 +01:00
|
|
|
alias Mobilizon.Service.Export.ICalendar, as: ICalendarService
|
|
|
|
|
2019-11-05 17:49:40 +01:00
|
|
|
describe "export an event to ics" do
|
|
|
|
test "export basic infos" do
|
|
|
|
%Event{} = event = insert(:event)
|
|
|
|
|
|
|
|
ics = """
|
|
|
|
BEGIN:VCALENDAR
|
|
|
|
CALSCALE:GREGORIAN
|
|
|
|
VERSION:2.0
|
2021-01-15 09:49:25 +01:00
|
|
|
PRODID:-//Elixir ICalendar//Mobilizon #{Mobilizon.Config.instance_version()}//EN
|
2019-11-05 17:49:40 +01:00
|
|
|
BEGIN:VEVENT
|
2021-11-26 14:30:46 +01:00
|
|
|
CATEGORIES:#{Enum.map_join(event.tags, ",", & &1.title)}
|
2019-11-05 17:49:40 +01:00
|
|
|
DESCRIPTION:Ceci est une description avec une première phrase assez longue\\,\\n puis sur une seconde ligne
|
2021-01-15 09:49:25 +01:00
|
|
|
DTEND:#{Value.to_ics(event.ends_on)}Z
|
|
|
|
DTSTAMP:#{Value.to_ics(event.publish_at)}Z
|
|
|
|
DTSTART:#{Value.to_ics(event.begins_on)}Z
|
2019-11-05 17:49:40 +01:00
|
|
|
GEO:#{event.physical_address |> Address.coords() |> Tuple.to_list() |> Enum.join(";")}
|
|
|
|
LOCATION:#{Address.representation(event.physical_address)}
|
2021-11-09 11:46:54 +01:00
|
|
|
ORGANIZER:#{event.organizer_actor.name}
|
2023-10-11 17:08:31 +02:00
|
|
|
STATUS:#{event.status |> to_string() |> String.upcase()}
|
2019-11-05 17:49:40 +01:00
|
|
|
SUMMARY:#{event.title}
|
|
|
|
UID:#{event.uuid}
|
|
|
|
URL:#{event.url}
|
|
|
|
END:VEVENT
|
|
|
|
END:VCALENDAR
|
|
|
|
"""
|
|
|
|
|
|
|
|
assert {:ok, ics} == ICalendarService.export_public_event(event)
|
|
|
|
end
|
|
|
|
end
|
2021-03-26 15:40:10 +01:00
|
|
|
|
|
|
|
describe "export the instance's public events" do
|
|
|
|
test "succeds" do
|
|
|
|
%Event{} = event = insert(:event, title: "I'm public")
|
|
|
|
%Event{} = event2 = insert(:event, visibility: :private, title: "I'm private")
|
|
|
|
%Event{} = event3 = insert(:event, title: "Another public")
|
|
|
|
|
|
|
|
{:commit, ics} = ICalendarService.create_cache("instance")
|
|
|
|
assert ics =~ event.title
|
|
|
|
refute ics =~ event2.title
|
|
|
|
assert ics =~ event3.title
|
|
|
|
end
|
2021-06-09 01:17:46 +02:00
|
|
|
|
|
|
|
test "with 50 events" do
|
|
|
|
Enum.each(0..50, fn i ->
|
|
|
|
%Event{} = insert(:event, title: "Event #{i}")
|
|
|
|
end)
|
|
|
|
|
|
|
|
{:commit, ics} = ICalendarService.create_cache("instance")
|
|
|
|
|
|
|
|
Enum.each(0..50, fn i ->
|
|
|
|
assert ics =~ "Event #{i}"
|
|
|
|
end)
|
|
|
|
end
|
2021-03-26 15:40:10 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "export an actor's events from a token" do
|
|
|
|
test "an actor feedtoken" do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
|
|
|
%FeedToken{token: token} = insert(:feed_token, user: user, actor: actor)
|
|
|
|
event = insert(:event)
|
|
|
|
insert(:participant, event: event, actor: actor, role: :participant)
|
|
|
|
|
2021-03-26 19:01:55 +01:00
|
|
|
{:commit, ics} = ICalendarService.create_cache("token_#{ShortUUID.encode!(token)}")
|
2021-03-26 15:40:10 +01:00
|
|
|
assert ics =~ event.title
|
|
|
|
end
|
|
|
|
end
|
2019-11-05 17:49:40 +01:00
|
|
|
end
|