2018-10-11 15:37:39 +00:00
|
|
|
defmodule Mobilizon.Factory do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
2019-09-08 22:52:49 +00:00
|
|
|
Factory for fixtures with ExMachina.
|
2018-01-14 16:56:50 +00:00
|
|
|
"""
|
2019-09-08 22:52:49 +00:00
|
|
|
|
2019-09-07 23:49:56 +00:00
|
|
|
use ExMachina.Ecto, repo: Mobilizon.Storage.Repo
|
2019-09-08 22:52:49 +00:00
|
|
|
|
2019-04-25 17:05:05 +00:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-08 22:52:49 +00:00
|
|
|
alias Mobilizon.Crypto
|
|
|
|
|
2019-04-25 17:05:05 +00:00
|
|
|
alias MobilizonWeb.Router.Helpers, as: Routes
|
|
|
|
alias MobilizonWeb.Endpoint
|
2019-06-05 16:29:39 +00:00
|
|
|
alias MobilizonWeb.Upload
|
2018-01-13 22:33:03 +00:00
|
|
|
|
|
|
|
def user_factory do
|
2019-03-05 16:23:05 +00:00
|
|
|
%Mobilizon.Users.User{
|
2018-01-13 22:33:03 +00:00
|
|
|
password_hash: "Jane Smith",
|
|
|
|
email: sequence(:email, &"email-#{&1}@example.com"),
|
2019-03-06 17:45:26 +00:00
|
|
|
role: :user,
|
2019-02-14 13:19:55 +00:00
|
|
|
confirmed_at: DateTime.utc_now() |> DateTime.truncate(:second),
|
2019-01-11 13:07:14 +00:00
|
|
|
confirmation_sent_at: nil,
|
|
|
|
confirmation_token: nil
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-05-30 16:59:13 +00:00
|
|
|
def actor_factory do
|
2018-06-14 15:25:55 +00:00
|
|
|
preferred_username = sequence("thomas")
|
2018-07-27 08:45:35 +00:00
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Actor{
|
2018-06-14 15:25:55 +00:00
|
|
|
preferred_username: preferred_username,
|
2018-01-13 22:33:03 +00:00
|
|
|
domain: nil,
|
2018-11-27 16:54:54 +00:00
|
|
|
followers: [],
|
|
|
|
followings: [],
|
2019-09-08 22:52:49 +00:00
|
|
|
keys: Crypto.generate_rsa_2048_private_key(),
|
2018-08-01 12:45:18 +00:00
|
|
|
type: :Person,
|
2019-05-22 12:12:11 +00:00
|
|
|
avatar: build(:file, name: "Avatar"),
|
|
|
|
banner: build(:file, name: "Banner"),
|
2019-04-25 17:05:05 +00: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 14:40:59 +00:00
|
|
|
inbox_url: Actor.build_url(preferred_username, :inbox),
|
2019-04-25 17:05:05 +00:00
|
|
|
outbox_url: Actor.build_url(preferred_username, :outbox),
|
2018-07-27 08:45:35 +00:00
|
|
|
user: nil
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-01 12:45:18 +00:00
|
|
|
def group_factory do
|
|
|
|
struct!(
|
|
|
|
actor_factory(),
|
|
|
|
%{
|
|
|
|
type: :Group
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def follower_factory do
|
2019-07-30 14:40:59 +00:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Follower{
|
2018-08-01 12:45:18 +00:00
|
|
|
target_actor: build(:actor),
|
2019-07-30 14:40:59 +00:00
|
|
|
actor: build(:actor),
|
|
|
|
id: uuid,
|
|
|
|
url: "#{MobilizonWeb.Endpoint.url()}/follows/#{uuid}"
|
2018-08-01 12:45:18 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
def tag_factory do
|
|
|
|
%Mobilizon.Events.Tag{
|
2019-09-04 16:24:31 +00:00
|
|
|
title: sequence("MyTag"),
|
|
|
|
slug: sequence("my-tag")
|
2018-11-23 14:03:53 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-02-14 13:19:55 +00:00
|
|
|
def tag_relation_factory do
|
|
|
|
%Mobilizon.Events.TagRelation{
|
|
|
|
tag: build(:tag),
|
|
|
|
link: build(:tag)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-17 10:39:01 +00:00
|
|
|
def address_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Addresses.Address{
|
2018-01-17 10:39:01 +00:00
|
|
|
description: sequence("MyAddress"),
|
2019-03-14 17:31:14 +00:00
|
|
|
geom: %Geo.Point{coordinates: {45.75, 4.85}, srid: 4326},
|
2019-07-30 08:35:29 +00:00
|
|
|
url: "http://mobilizon.test/address/#{Ecto.UUID.generate()}",
|
2018-01-17 10:39:01 +00:00
|
|
|
floor: "Myfloor",
|
2019-03-22 14:51:23 +00:00
|
|
|
country: "My Country",
|
|
|
|
locality: "My Locality",
|
|
|
|
region: "My Region",
|
|
|
|
postal_code: "My Postal Code",
|
|
|
|
street: "My Street Address"
|
2018-01-17 10:39:01 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
def comment_factory do
|
2018-08-24 09:34:00 +00:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Comment{
|
2018-06-14 15:25:55 +00:00
|
|
|
text: "My Comment",
|
|
|
|
actor: build(:actor),
|
|
|
|
event: build(:event),
|
2018-08-24 09:34:00 +00:00
|
|
|
uuid: uuid,
|
2018-11-27 16:54:54 +00:00
|
|
|
in_reply_to_comment: nil,
|
2019-04-25 17:05:05 +00:00
|
|
|
url: Routes.page_url(Endpoint, :comment, uuid)
|
2018-06-14 15:25:55 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-13 22:33:03 +00:00
|
|
|
def event_factory do
|
2018-05-30 16:59:13 +00:00
|
|
|
actor = build(:actor)
|
2019-04-11 16:25:32 +00:00
|
|
|
start = Timex.shift(DateTime.utc_now(), hours: 2)
|
2019-01-21 14:08:22 +00:00
|
|
|
uuid = Ecto.UUID.generate()
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Event{
|
2018-11-06 09:30:27 +00: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 14:08:22 +00:00
|
|
|
begins_on: start,
|
|
|
|
ends_on: Timex.shift(start, hours: 2),
|
2018-05-30 16:59:13 +00:00
|
|
|
organizer_actor: actor,
|
2019-02-22 15:54:01 +00:00
|
|
|
category: sequence("something"),
|
2018-07-04 14:23:52 +00:00
|
|
|
physical_address: build(:address),
|
2019-01-14 14:56:07 +00:00
|
|
|
visibility: :public,
|
2019-04-11 16:25:32 +00:00
|
|
|
tags: build_list(3, :tag),
|
2019-04-25 17:05:05 +00:00
|
|
|
url: Routes.page_url(Endpoint, :event, uuid),
|
2019-07-30 14:40:59 +00:00
|
|
|
picture: insert(:picture),
|
2019-08-14 15:45:11 +00:00
|
|
|
uuid: uuid,
|
|
|
|
join_options: :free
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-24 09:34:00 +00:00
|
|
|
def participant_factory do
|
2019-08-14 15:45:11 +00:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Participant{
|
2018-08-24 09:34:00 +00:00
|
|
|
event: build(:event),
|
2019-01-21 14:08:22 +00:00
|
|
|
actor: build(:actor),
|
2019-08-14 15:45:11 +00:00
|
|
|
role: :creator,
|
|
|
|
url: "#{Endpoint.url()}/join/event/#{uuid}",
|
|
|
|
id: uuid
|
2018-08-24 09:34:00 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-13 22:33:03 +00:00
|
|
|
def session_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Session{
|
2018-07-27 08:45:35 +00:00
|
|
|
title: sequence("MySession"),
|
|
|
|
event: build(:event),
|
|
|
|
track: build(:track)
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Track{
|
2018-01-13 22:33:03 +00:00
|
|
|
name: sequence("MyTrack"),
|
|
|
|
event: build(:event)
|
|
|
|
}
|
|
|
|
end
|
2018-01-17 10:39:01 +00:00
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
def bot_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Bot{
|
2018-06-14 15:25:55 +00:00
|
|
|
source: "https://mysource.tld/feed.ics",
|
|
|
|
type: "ics",
|
|
|
|
user: build(:user),
|
2018-07-27 08:45:35 +00:00
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Member{
|
2018-07-27 08:45:35 +00:00
|
|
|
parent: build(:actor),
|
2019-01-25 08:23:44 +00:00
|
|
|
actor: build(:actor),
|
2019-03-01 16:11:28 +00:00
|
|
|
role: :not_approved
|
2018-01-17 10:39:01 +00:00
|
|
|
}
|
|
|
|
end
|
2019-03-08 11:25:06 +00: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 12:12:11 +00:00
|
|
|
|
|
|
|
def file_factory do
|
2019-06-05 16:29:39 +00: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)
|
|
|
|
|
|
|
|
%{
|
|
|
|
"url" => [%{"href" => url, "mediaType" => "image/jpeg"}],
|
|
|
|
"size" => 13_227,
|
|
|
|
"type" => "Image"
|
|
|
|
} = data
|
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
%Mobilizon.Media.File{
|
|
|
|
name: "My Picture",
|
2019-06-05 16:29:39 +00:00
|
|
|
url: url,
|
2019-06-03 15:13:47 +00:00
|
|
|
content_type: "image/png",
|
|
|
|
size: 13_120
|
2019-05-22 12:12:11 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def picture_factory do
|
|
|
|
%Mobilizon.Media.Picture{
|
2019-05-31 15:58:03 +00:00
|
|
|
file: build(:file),
|
|
|
|
actor: build(:actor)
|
2019-05-22 12:12:11 +00:00
|
|
|
}
|
|
|
|
end
|
2019-07-23 11:49:22 +00:00
|
|
|
|
|
|
|
def report_factory do
|
|
|
|
%Mobilizon.Reports.Report{
|
|
|
|
content: "This is problematic",
|
|
|
|
status: :open,
|
|
|
|
uri: "http://mobilizon.test/report/deae1020-54b8-47df-9eea-d8c0e943e57f/activity",
|
|
|
|
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
|
2018-01-14 16:56:50 +00:00
|
|
|
end
|