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
|
|
|
|
|
|
|
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
|
|
|
|
|
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-02-18 08:57:00 +01:00
|
|
|
user_id: nil
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
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,
|
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),
|
|
|
|
visibility: :public
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
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),
|
|
|
|
user: nil
|
2018-08-01 14:45:18 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
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,
|
2020-01-28 19:18:33 +01:00
|
|
|
url: "#{Endpoint.url()}/follows/#{uuid}"
|
2018-08-01 14:45:18 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
2019-02-14 14:19:55 +01:00
|
|
|
def tag_relation_factory do
|
|
|
|
%Mobilizon.Events.TagRelation{
|
|
|
|
tag: build(:tag),
|
|
|
|
link: build(:tag)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
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-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,
|
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
|
|
|
|
|
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,
|
2019-02-22 16:54:01 +01:00
|
|
|
category: sequence("something"),
|
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: [],
|
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),
|
2019-07-30 16:40:59 +02:00
|
|
|
picture: insert(:picture),
|
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: %{},
|
|
|
|
status: :confirmed
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
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,
|
|
|
|
id: uuid,
|
|
|
|
url: "#{Endpoint.url()}/member/#{uuid}"
|
2018-01-17 11:39:01 +01:00
|
|
|
}
|
|
|
|
end
|
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
|
|
|
|
|
|
|
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",
|
|
|
|
url: url,
|
|
|
|
size: 13_227
|
2019-06-05 18:29:39 +02:00
|
|
|
} = data
|
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
%Mobilizon.Media.File{
|
|
|
|
name: "My Picture",
|
2019-06-05 18:29:39 +02:00
|
|
|
url: url,
|
2019-06-03 17:13:47 +02:00
|
|
|
content_type: "image/png",
|
|
|
|
size: 13_120
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def picture_factory do
|
|
|
|
%Mobilizon.Media.Picture{
|
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
|
|
|
|
|
|
|
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),
|
|
|
|
event: build(:event),
|
|
|
|
comments: build_list(1, :comment)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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(),
|
|
|
|
url: Routes.page_url(Endpoint, :post, uuid)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def tombstone_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
|
|
|
%Mobilizon.Tombstone{
|
|
|
|
uri: "https://mobilizon.test/comments/#{uuid}",
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def discussion_factory do
|
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
actor = build(:actor)
|
|
|
|
group = build(:group)
|
|
|
|
comment = build(:comment, actor: actor, attributed_to: group)
|
|
|
|
slug = "my-awesome-discussion-#{ShortUUID.encode!(uuid)}"
|
|
|
|
|
|
|
|
%Mobilizon.Discussions.Discussion{
|
|
|
|
title: "My Awesome discussion",
|
|
|
|
slug: slug,
|
|
|
|
creator: actor,
|
|
|
|
actor: group,
|
|
|
|
id: uuid,
|
|
|
|
last_comment: comment,
|
|
|
|
comments: [comment],
|
|
|
|
url: Routes.page_url(Endpoint, :discussion, group.preferred_username, slug)
|
|
|
|
}
|
|
|
|
end
|
2018-01-14 17:56:50 +01:00
|
|
|
end
|