2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.Factory do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
2019-09-09 00:52:49 +02:00
|
|
|
Factory for fixtures with ExMachina.
|
2018-01-14 17:56:50 +01:00
|
|
|
"""
|
2019-09-09 00:52:49 +02:00
|
|
|
|
2019-09-08 01:49:56 +02:00
|
|
|
use ExMachina.Ecto, repo: Mobilizon.Storage.Repo
|
2019-09-09 00:52:49 +02:00
|
|
|
|
2019-04-25 19:05:05 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-09 00:52:49 +02:00
|
|
|
alias Mobilizon.Crypto
|
|
|
|
|
2020-01-28 19:18:33 +01:00
|
|
|
alias Mobilizon.Web.{Endpoint, Upload}
|
2020-01-26 21:36:50 +01:00
|
|
|
alias Mobilizon.Web.Router.Helpers, as: Routes
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec user_factory :: Mobilizon.Users.User.t()
|
2018-01-13 23:33:03 +01:00
|
|
|
def user_factory do
|
2019-03-05 17:23:05 +01:00
|
|
|
%Mobilizon.Users.User{
|
2018-01-13 23:33:03 +01:00
|
|
|
password_hash: "Jane Smith",
|
|
|
|
email: sequence(:email, &"email-#{&1}@example.com"),
|
2019-03-06 18:45:26 +01:00
|
|
|
role: :user,
|
2019-02-14 14:19:55 +01:00
|
|
|
confirmed_at: DateTime.utc_now() |> DateTime.truncate(:second),
|
2019-01-11 14:07:14 +01:00
|
|
|
confirmation_sent_at: nil,
|
2020-06-27 19:12:45 +02:00
|
|
|
confirmation_token: nil,
|
|
|
|
provider: nil
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec settings_factory :: Mobilizon.Users.Setting.t()
|
2020-02-18 08:57:00 +01:00
|
|
|
def settings_factory do
|
|
|
|
%Mobilizon.Users.Setting{
|
|
|
|
timezone: nil,
|
|
|
|
notification_on_day: false,
|
|
|
|
notification_each_week: false,
|
|
|
|
notification_before_event: false,
|
2020-06-08 12:28:19 +02:00
|
|
|
notification_pending_participation: :one_day,
|
2020-11-06 11:34:32 +01:00
|
|
|
notification_pending_membership: :one_day,
|
2021-06-04 16:32:26 +02:00
|
|
|
group_notifications: :one_day,
|
|
|
|
last_notification_sent: nil,
|
|
|
|
user: build(:user)
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec actor_factory :: Mobilizon.Actors.Actor.t()
|
2018-05-30 18:59:13 +02:00
|
|
|
def actor_factory do
|
2018-06-14 17:25:55 +02:00
|
|
|
preferred_username = sequence("thomas")
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Actor{
|
2018-06-14 17:25:55 +02:00
|
|
|
preferred_username: preferred_username,
|
2021-10-21 17:55:16 +02:00
|
|
|
name: sequence("Thomas Named"),
|
2018-01-13 23:33:03 +01:00
|
|
|
domain: nil,
|
2018-11-27 17:54:54 +01:00
|
|
|
followers: [],
|
|
|
|
followings: [],
|
2019-09-09 00:52:49 +02:00
|
|
|
keys: Crypto.generate_rsa_2048_private_key(),
|
2018-08-01 14:45:18 +02:00
|
|
|
type: :Person,
|
2019-05-22 14:12:11 +02:00
|
|
|
avatar: build(:file, name: "Avatar"),
|
|
|
|
banner: build(:file, name: "Banner"),
|
2019-04-25 19:05:05 +02:00
|
|
|
url: Actor.build_url(preferred_username, :page),
|
|
|
|
followers_url: Actor.build_url(preferred_username, :followers),
|
|
|
|
following_url: Actor.build_url(preferred_username, :following),
|
2019-07-30 16:40:59 +02:00
|
|
|
inbox_url: Actor.build_url(preferred_username, :inbox),
|
2019-04-25 19:05:05 +02:00
|
|
|
outbox_url: Actor.build_url(preferred_username, :outbox),
|
2020-02-18 08:57:00 +01:00
|
|
|
shared_inbox_url: "#{Endpoint.url()}/inbox",
|
2020-02-14 17:56:36 +01:00
|
|
|
last_refreshed_at: DateTime.utc_now(),
|
2020-09-02 17:42:17 +02:00
|
|
|
user: build(:user),
|
2021-01-20 18:16:44 +01:00
|
|
|
visibility: :public,
|
|
|
|
manually_approves_followers: false
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec group_factory :: Mobilizon.Actors.Actor.t()
|
2018-08-01 14:45:18 +02:00
|
|
|
def group_factory do
|
2020-02-18 08:57:00 +01:00
|
|
|
preferred_username = sequence("myGroup")
|
|
|
|
|
2018-08-01 14:45:18 +02:00
|
|
|
struct!(
|
|
|
|
actor_factory(),
|
|
|
|
%{
|
2020-02-18 08:57:00 +01:00
|
|
|
preferred_username: preferred_username,
|
|
|
|
type: :Group,
|
|
|
|
url: Actor.build_url(preferred_username, :page),
|
|
|
|
followers_url: Actor.build_url(preferred_username, :followers),
|
|
|
|
following_url: Actor.build_url(preferred_username, :following),
|
|
|
|
members_url: Actor.build_url(preferred_username, :members),
|
|
|
|
resources_url: Actor.build_url(preferred_username, :resources),
|
|
|
|
inbox_url: Actor.build_url(preferred_username, :inbox),
|
|
|
|
outbox_url: Actor.build_url(preferred_username, :outbox),
|
2021-10-21 17:55:16 +02:00
|
|
|
user: nil,
|
|
|
|
physical_address: build(:address)
|
2018-08-01 14:45:18 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec instance_actor_factory :: Mobilizon.Actors.Actor.t()
|
2020-10-14 09:45:58 +02:00
|
|
|
def instance_actor_factory do
|
|
|
|
preferred_username = "relay"
|
|
|
|
domain = "#{sequence("mydomain")}.com"
|
|
|
|
|
|
|
|
struct!(
|
|
|
|
actor_factory(),
|
|
|
|
%{
|
|
|
|
preferred_username: preferred_username,
|
|
|
|
type: :Application,
|
|
|
|
url: "http://#{domain}/#{preferred_username}",
|
|
|
|
followers_url: Actor.build_url(preferred_username, :followers),
|
|
|
|
following_url: Actor.build_url(preferred_username, :following),
|
|
|
|
members_url: Actor.build_url(preferred_username, :members),
|
|
|
|
resources_url: Actor.build_url(preferred_username, :resources),
|
|
|
|
inbox_url: Actor.build_url(preferred_username, :inbox),
|
|
|
|
outbox_url: Actor.build_url(preferred_username, :outbox),
|
|
|
|
user: nil,
|
|
|
|
domain: domain
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec follower_factory :: Mobilizon.Actors.Follower.t()
|
2018-08-01 14:45:18 +02:00
|
|
|
def follower_factory do
|
2019-07-30 16:40:59 +02:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Follower{
|
2018-08-01 14:45:18 +02:00
|
|
|
target_actor: build(:actor),
|
2019-07-30 16:40:59 +02:00
|
|
|
actor: build(:actor),
|
|
|
|
id: uuid,
|
2021-01-20 18:16:44 +01:00
|
|
|
url: "#{Endpoint.url()}/follows/#{uuid}",
|
|
|
|
approved: false
|
2018-08-01 14:45:18 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec tag_factory :: Mobilizon.Events.Tag.t()
|
2018-11-23 15:03:53 +01:00
|
|
|
def tag_factory do
|
|
|
|
%Mobilizon.Events.Tag{
|
2019-09-04 18:24:31 +02:00
|
|
|
title: sequence("MyTag"),
|
|
|
|
slug: sequence("my-tag")
|
2018-11-23 15:03:53 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec tag_relation_factory :: Mobilizon.Events.TagRelation.t()
|
2019-02-14 14:19:55 +01:00
|
|
|
def tag_relation_factory do
|
|
|
|
%Mobilizon.Events.TagRelation{
|
|
|
|
tag: build(:tag),
|
|
|
|
link: build(:tag)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec address_factory :: Mobilizon.Addresses.Address.t()
|
2018-01-17 11:39:01 +01:00
|
|
|
def address_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Addresses.Address{
|
2018-01-17 11:39:01 +01:00
|
|
|
description: sequence("MyAddress"),
|
2019-03-14 18:31:14 +01:00
|
|
|
geom: %Geo.Point{coordinates: {45.75, 4.85}, srid: 4326},
|
2019-07-30 10:35:29 +02:00
|
|
|
url: "http://mobilizon.test/address/#{Ecto.UUID.generate()}",
|
2019-03-22 15:51:23 +01:00
|
|
|
country: "My Country",
|
|
|
|
locality: "My Locality",
|
|
|
|
region: "My Region",
|
|
|
|
postal_code: "My Postal Code",
|
|
|
|
street: "My Street Address"
|
2018-01-17 11:39:01 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec comment_factory :: Mobilizon.Discussions.Comment.t()
|
2018-06-14 17:25:55 +02:00
|
|
|
def comment_factory do
|
2018-08-24 11:34:00 +02:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2020-07-09 17:24:28 +02:00
|
|
|
%Mobilizon.Discussions.Comment{
|
2018-06-14 17:25:55 +02:00
|
|
|
text: "My Comment",
|
|
|
|
actor: build(:actor),
|
|
|
|
event: build(:event),
|
2018-08-24 11:34:00 +02:00
|
|
|
uuid: uuid,
|
2019-10-25 17:43:37 +02:00
|
|
|
mentions: [],
|
2020-11-26 11:41:13 +01:00
|
|
|
media: [],
|
2020-07-09 17:24:28 +02:00
|
|
|
attributed_to: nil,
|
|
|
|
local: true,
|
|
|
|
deleted_at: nil,
|
2019-10-25 17:43:37 +02:00
|
|
|
tags: build_list(3, :tag),
|
2018-11-27 17:54:54 +01:00
|
|
|
in_reply_to_comment: nil,
|
2021-07-29 17:50:47 +02:00
|
|
|
origin_comment: nil,
|
2021-06-02 18:37:17 +02:00
|
|
|
is_announcement: false,
|
2020-08-14 11:32:23 +02:00
|
|
|
published_at: DateTime.utc_now(),
|
2019-04-25 19:05:05 +02:00
|
|
|
url: Routes.page_url(Endpoint, :comment, uuid)
|
2018-06-14 17:25:55 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec event_factory :: Mobilizon.Events.Event.t()
|
2018-01-13 23:33:03 +01:00
|
|
|
def event_factory do
|
2018-05-30 18:59:13 +02:00
|
|
|
actor = build(:actor)
|
2019-04-11 18:25:32 +02:00
|
|
|
start = Timex.shift(DateTime.utc_now(), hours: 2)
|
2019-01-21 15:08:22 +01:00
|
|
|
uuid = Ecto.UUID.generate()
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Event{
|
2018-11-06 10:30:27 +01:00
|
|
|
title: sequence("Ceci est un événement"),
|
|
|
|
description: "Ceci est une description avec une première phrase assez longue,
|
|
|
|
puis sur une seconde ligne",
|
2019-01-21 15:08:22 +01:00
|
|
|
begins_on: start,
|
|
|
|
ends_on: Timex.shift(start, hours: 2),
|
2018-05-30 18:59:13 +02:00
|
|
|
organizer_actor: actor,
|
2020-07-09 17:24:28 +02:00
|
|
|
attributed_to: nil,
|
2022-03-29 09:28:59 +02:00
|
|
|
category: "PARTY",
|
2018-07-04 16:23:52 +02:00
|
|
|
physical_address: build(:address),
|
2019-01-14 15:56:07 +01:00
|
|
|
visibility: :public,
|
2019-04-11 18:25:32 +02:00
|
|
|
tags: build_list(3, :tag),
|
2019-10-25 17:43:37 +02:00
|
|
|
mentions: [],
|
2021-08-10 11:03:03 +02:00
|
|
|
metadata: build_list(2, :event_metadata),
|
2019-12-20 13:04:34 +01:00
|
|
|
local: true,
|
2019-11-05 17:49:40 +01:00
|
|
|
publish_at: DateTime.utc_now(),
|
2019-04-25 19:05:05 +02:00
|
|
|
url: Routes.page_url(Endpoint, :event, uuid),
|
2020-11-26 11:41:13 +01:00
|
|
|
picture: insert(:media),
|
2019-08-14 17:45:11 +02:00
|
|
|
uuid: uuid,
|
2019-10-11 11:50:06 +02:00
|
|
|
join_options: :free,
|
2019-10-25 17:43:37 +02:00
|
|
|
options: %{},
|
2020-02-18 08:57:00 +01:00
|
|
|
participant_stats: %{},
|
2020-09-29 09:53:48 +02:00
|
|
|
status: :confirmed,
|
2020-11-26 11:41:13 +01:00
|
|
|
contacts: [],
|
|
|
|
media: []
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec participant_factory :: Mobilizon.Events.Participant.t()
|
2018-08-24 11:34:00 +02:00
|
|
|
def participant_factory do
|
2019-08-14 17:45:11 +02:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Participant{
|
2018-08-24 11:34:00 +02:00
|
|
|
event: build(:event),
|
2019-01-21 15:08:22 +01:00
|
|
|
actor: build(:actor),
|
2019-08-14 17:45:11 +02:00
|
|
|
role: :creator,
|
|
|
|
url: "#{Endpoint.url()}/join/event/#{uuid}",
|
2019-12-20 13:04:34 +01:00
|
|
|
id: uuid,
|
|
|
|
metadata: %{
|
|
|
|
email: nil,
|
|
|
|
confirmation_token: nil
|
|
|
|
}
|
2018-08-24 11:34:00 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec session_factory :: Mobilizon.Events.Session.t()
|
2018-01-13 23:33:03 +01:00
|
|
|
def session_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Session{
|
2018-07-27 10:45:35 +02:00
|
|
|
title: sequence("MySession"),
|
|
|
|
event: build(:event),
|
|
|
|
track: build(:track)
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec track_factory :: Mobilizon.Events.Track.t()
|
2018-01-13 23:33:03 +01:00
|
|
|
def track_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Track{
|
2018-01-13 23:33:03 +01:00
|
|
|
name: sequence("MyTrack"),
|
|
|
|
event: build(:event)
|
|
|
|
}
|
|
|
|
end
|
2018-01-17 11:39:01 +01:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec bot_factory :: Mobilizon.Actors.Bot.t()
|
2018-06-14 17:25:55 +02:00
|
|
|
def bot_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Bot{
|
2018-06-14 17:25:55 +02:00
|
|
|
source: "https://mysource.tld/feed.ics",
|
|
|
|
type: "ics",
|
|
|
|
user: build(:user),
|
2018-07-27 10:45:35 +02:00
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec member_factory :: Mobilizon.Actors.Member.t()
|
2018-07-27 10:45:35 +02:00
|
|
|
def member_factory do
|
2020-02-18 08:57:00 +01:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Member{
|
2018-07-27 10:45:35 +02:00
|
|
|
parent: build(:actor),
|
2019-01-25 09:23:44 +01:00
|
|
|
actor: build(:actor),
|
2020-02-18 08:57:00 +01:00
|
|
|
role: :not_approved,
|
2022-05-11 11:20:42 +02:00
|
|
|
member_since: nil,
|
2020-02-18 08:57:00 +01:00
|
|
|
id: uuid,
|
|
|
|
url: "#{Endpoint.url()}/member/#{uuid}"
|
2018-01-17 11:39:01 +01:00
|
|
|
}
|
|
|
|
end
|
2019-03-08 12:25:06 +01:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec feed_token_factory :: Mobilizon.Events.FeedToken.t()
|
2019-03-08 12:25:06 +01:00
|
|
|
def feed_token_factory do
|
|
|
|
user = build(:user)
|
|
|
|
|
|
|
|
%Mobilizon.Events.FeedToken{
|
|
|
|
user: user,
|
|
|
|
actor: build(:actor, user: user),
|
|
|
|
token: Ecto.UUID.generate()
|
|
|
|
}
|
|
|
|
end
|
2019-05-22 14:12:11 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec file_factory :: Mobilizon.Medias.File.t()
|
2019-05-22 14:12:11 +02:00
|
|
|
def file_factory do
|
2019-06-05 18:29:39 +02:00
|
|
|
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
|
|
|
|
|
|
|
file = %Plug.Upload{
|
|
|
|
content_type: "image/jpg",
|
|
|
|
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
|
|
|
filename: "image.jpg"
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, data} = Upload.store(file)
|
|
|
|
|
|
|
|
%{
|
2019-10-25 17:43:37 +02:00
|
|
|
content_type: "image/jpeg",
|
|
|
|
name: "image.jpg",
|
2021-08-03 18:47:46 +02:00
|
|
|
url: url
|
2019-06-05 18:29:39 +02:00
|
|
|
} = data
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
%Mobilizon.Medias.File{
|
|
|
|
name: "My Media",
|
2019-06-05 18:29:39 +02:00
|
|
|
url: url,
|
2021-08-22 16:17:20 +02:00
|
|
|
content_type: "image/jpg",
|
2019-06-03 17:13:47 +02:00
|
|
|
size: 13_120
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec media_factory :: Mobilizon.Medias.Media.t()
|
2020-11-26 11:41:13 +01:00
|
|
|
def media_factory do
|
|
|
|
%Mobilizon.Medias.Media{
|
2019-05-31 17:58:03 +02:00
|
|
|
file: build(:file),
|
|
|
|
actor: build(:actor)
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
end
|
2019-07-23 13:49:22 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec report_factory :: Mobilizon.Reports.Report.t()
|
2019-07-23 13:49:22 +02:00
|
|
|
def report_factory do
|
|
|
|
%Mobilizon.Reports.Report{
|
|
|
|
content: "This is problematic",
|
|
|
|
status: :open,
|
2019-11-15 18:36:47 +01:00
|
|
|
url: "http://mobilizon.test/report/deae1020-54b8-47df-9eea-d8c0e943e57f/activity",
|
2019-07-23 13:49:22 +02:00
|
|
|
reported: build(:actor),
|
|
|
|
reporter: build(:actor),
|
2023-06-05 18:32:29 +02:00
|
|
|
events: build_list(1, :event),
|
2019-07-23 13:49:22 +02:00
|
|
|
comments: build_list(1, :comment)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec report_note_factory :: Mobilizon.Reports.Note.t()
|
2019-07-23 13:49:22 +02:00
|
|
|
def report_note_factory do
|
|
|
|
%Mobilizon.Reports.Note{
|
|
|
|
content: "My opinion",
|
|
|
|
moderator: build(:actor),
|
|
|
|
report: build(:report)
|
|
|
|
}
|
|
|
|
end
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec todo_list_factory :: Mobilizon.Todos.TodoList.t()
|
2020-02-18 08:57:00 +01:00
|
|
|
def todo_list_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
|
|
|
%Mobilizon.Todos.TodoList{
|
|
|
|
title: sequence("todo list"),
|
|
|
|
actor: build(:group),
|
|
|
|
id: uuid,
|
2020-08-14 11:32:23 +02:00
|
|
|
url: Routes.page_url(Endpoint, :todo_list, uuid),
|
|
|
|
published_at: DateTime.utc_now()
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec todo_factory :: Mobilizon.Todos.Todo.t()
|
2020-02-18 08:57:00 +01:00
|
|
|
def todo_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
|
|
|
%Mobilizon.Todos.Todo{
|
|
|
|
id: uuid,
|
|
|
|
title: sequence("my todo"),
|
|
|
|
todo_list: build(:todo_list),
|
|
|
|
status: false,
|
|
|
|
due_date: Timex.shift(DateTime.utc_now(), hours: 2),
|
|
|
|
assigned_to: build(:actor),
|
2020-08-12 16:05:34 +02:00
|
|
|
url: Routes.page_url(Endpoint, :todo, uuid),
|
2020-08-14 11:32:23 +02:00
|
|
|
creator: build(:actor),
|
|
|
|
published_at: DateTime.utc_now()
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec resource_factory :: Mobilizon.Resources.Resource.t()
|
2020-02-18 08:57:00 +01:00
|
|
|
def resource_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
title = sequence("my resource")
|
|
|
|
|
|
|
|
%Mobilizon.Resources.Resource{
|
|
|
|
id: uuid,
|
|
|
|
title: title,
|
|
|
|
type: :link,
|
|
|
|
resource_url: "https://somewebsite.com/path",
|
|
|
|
actor: build(:group),
|
|
|
|
creator: build(:actor),
|
|
|
|
parent: nil,
|
2020-08-12 16:05:34 +02:00
|
|
|
url: Routes.page_url(Endpoint, :resource, uuid),
|
2020-08-14 11:32:23 +02:00
|
|
|
published_at: DateTime.utc_now(),
|
2020-02-18 08:57:00 +01:00
|
|
|
path: "/#{title}"
|
|
|
|
}
|
|
|
|
end
|
2020-07-07 15:51:42 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec admin_setting_factory :: Mobilizon.Admin.Setting.t()
|
2020-07-07 15:51:42 +02:00
|
|
|
def admin_setting_factory do
|
|
|
|
%Mobilizon.Admin.Setting{
|
|
|
|
group: sequence("group"),
|
|
|
|
name: sequence("name"),
|
|
|
|
value: sequence("value")
|
|
|
|
}
|
|
|
|
end
|
2020-07-09 17:24:28 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec post_factory :: Mobilizon.Posts.Post.t()
|
2020-07-09 17:24:28 +02:00
|
|
|
def post_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
|
|
|
%Mobilizon.Posts.Post{
|
|
|
|
body: "The <b>HTML</b>body for my Article",
|
|
|
|
title: "My Awesome article",
|
|
|
|
slug: "my-awesome-article-#{ShortUUID.encode!(uuid)}",
|
|
|
|
author: build(:actor),
|
|
|
|
attributed_to: build(:group),
|
|
|
|
id: uuid,
|
|
|
|
draft: false,
|
|
|
|
tags: build_list(3, :tag),
|
|
|
|
visibility: :public,
|
|
|
|
publish_at: DateTime.utc_now(),
|
2020-12-16 11:14:24 +01:00
|
|
|
picture: insert(:media),
|
2020-11-26 11:41:13 +01:00
|
|
|
media: [],
|
2020-07-09 17:24:28 +02:00
|
|
|
url: Routes.page_url(Endpoint, :post, uuid)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec tombstone_factory :: Mobilizon.Tombstone.t()
|
2020-07-09 17:24:28 +02:00
|
|
|
def tombstone_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
|
|
|
%Mobilizon.Tombstone{
|
|
|
|
uri: "https://mobilizon.test/comments/#{uuid}",
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec discussion_factory :: Mobilizon.Discussions.Discussion.t()
|
2020-07-09 17:24:28 +02:00
|
|
|
def discussion_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
actor = build(:actor)
|
|
|
|
group = build(:group)
|
|
|
|
slug = "my-awesome-discussion-#{ShortUUID.encode!(uuid)}"
|
|
|
|
|
|
|
|
%Mobilizon.Discussions.Discussion{
|
|
|
|
title: "My Awesome discussion",
|
|
|
|
slug: slug,
|
|
|
|
creator: actor,
|
|
|
|
actor: group,
|
|
|
|
id: uuid,
|
2021-03-04 11:43:35 +01:00
|
|
|
last_comment: nil,
|
|
|
|
comments: [],
|
2020-07-09 17:24:28 +02:00
|
|
|
url: Routes.page_url(Endpoint, :discussion, group.preferred_username, slug)
|
|
|
|
}
|
|
|
|
end
|
2021-02-24 19:06:48 +01:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec mobilizon_activity_factory :: Mobilizon.Activities.Activity.t()
|
2021-02-24 19:06:48 +01:00
|
|
|
def mobilizon_activity_factory do
|
|
|
|
group = build(:group)
|
|
|
|
actor = build(:actor)
|
|
|
|
event = build(:event, organizer_actor: actor, attributed_to: group)
|
|
|
|
|
|
|
|
%Mobilizon.Activities.Activity{
|
|
|
|
type: :event,
|
|
|
|
subject: :event_created,
|
2021-06-03 17:17:13 +02:00
|
|
|
subject_params: %{
|
|
|
|
"event_title" => event.title,
|
|
|
|
"event_uuid" => event.uuid,
|
|
|
|
"event_id" => event.id
|
|
|
|
},
|
2021-02-24 19:06:48 +01:00
|
|
|
author: actor,
|
|
|
|
group: group,
|
|
|
|
object_type: :event,
|
|
|
|
object_id: to_string(event.id)
|
|
|
|
}
|
|
|
|
end
|
2021-06-03 17:17:13 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec mobilizon_activity_setting_factory :: Mobilizon.Users.ActivitySetting.t()
|
2021-06-03 17:17:13 +02:00
|
|
|
def mobilizon_activity_setting_factory do
|
|
|
|
%Mobilizon.Users.ActivitySetting{
|
|
|
|
key: "event_created",
|
|
|
|
method: "email",
|
|
|
|
enabled: true,
|
|
|
|
user: build(:user)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec push_subscription_factory :: Mobilizon.Users.PushSubscription.t()
|
2021-06-03 17:17:13 +02:00
|
|
|
def push_subscription_factory do
|
|
|
|
%Mobilizon.Users.PushSubscription{
|
|
|
|
digest: "",
|
|
|
|
endpoint: "",
|
|
|
|
auth: "",
|
|
|
|
p256dh: "",
|
|
|
|
user: build(:user)
|
|
|
|
}
|
|
|
|
end
|
2021-07-29 17:50:47 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec share_factory :: Mobilizon.Share.t()
|
2021-07-29 17:50:47 +02:00
|
|
|
def share_factory do
|
|
|
|
%Mobilizon.Share{
|
|
|
|
actor: build(:actor),
|
|
|
|
owner_actor: build(:actor),
|
|
|
|
uri: sequence("https://someshare.uri/p/12")
|
|
|
|
}
|
|
|
|
end
|
2021-08-10 11:03:03 +02:00
|
|
|
|
2021-09-27 09:41:36 +02:00
|
|
|
@spec event_metadata_factory :: Mobilizon.Events.EventMetadata.t()
|
2021-08-10 11:03:03 +02:00
|
|
|
def event_metadata_factory do
|
|
|
|
%Mobilizon.Events.EventMetadata{
|
|
|
|
key: sequence("mz:custom:something"),
|
|
|
|
value: sequence("a value"),
|
|
|
|
type: :string
|
|
|
|
}
|
|
|
|
end
|
2023-03-17 18:10:59 +01:00
|
|
|
|
|
|
|
def auth_application_factory do
|
|
|
|
%Mobilizon.Applications.Application{
|
|
|
|
name: sequence("My app"),
|
|
|
|
client_id: :crypto.strong_rand_bytes(42) |> Base.encode64() |> binary_part(0, 42),
|
|
|
|
client_secret: :crypto.strong_rand_bytes(42) |> Base.encode64() |> binary_part(0, 42),
|
|
|
|
redirect_uris: [sequence("https://someredir.uri")],
|
|
|
|
scope: "read write",
|
|
|
|
website: "https://somewebsite.com"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def auth_application_token_factory do
|
|
|
|
%Mobilizon.Applications.ApplicationToken{
|
|
|
|
authorization_code: sequence("some code"),
|
|
|
|
status: "pending",
|
|
|
|
scope: "read write",
|
|
|
|
user: build(:user),
|
|
|
|
application: build(:auth_application)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def auth_application_device_activation_factory do
|
|
|
|
%Mobilizon.Applications.ApplicationDeviceActivation{
|
|
|
|
user_code: :crypto.strong_rand_bytes(8) |> Base.encode64() |> binary_part(0, 8),
|
|
|
|
device_code: :crypto.strong_rand_bytes(8) |> Base.encode64() |> binary_part(0, 8),
|
|
|
|
status: "pending",
|
|
|
|
scope: "read write",
|
|
|
|
expires_in: 600,
|
|
|
|
user: build(:user),
|
|
|
|
application: build(:auth_application)
|
|
|
|
}
|
|
|
|
end
|
2018-01-14 17:56:50 +01:00
|
|
|
end
|