2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.Factory do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Factory for fixtures with ExMachina
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
# with Ecto
|
2018-10-11 17:37:39 +02:00
|
|
|
use ExMachina.Ecto, repo: Mobilizon.Repo
|
2019-04-25 19:05:05 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
alias MobilizonWeb.Router.Helpers, as: Routes
|
|
|
|
alias MobilizonWeb.Endpoint
|
2019-06-05 18:29:39 +02:00
|
|
|
alias MobilizonWeb.Upload
|
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,
|
|
|
|
confirmation_token: nil
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-05-30 18:59:13 +02:00
|
|
|
def actor_factory do
|
2018-06-14 18:15:27 +02:00
|
|
|
key = :public_key.generate_key({:rsa, 2048, 65_537})
|
2018-06-14 17:25:55 +02:00
|
|
|
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
|
2018-06-14 18:15:27 +02:00
|
|
|
pem = [entry] |> :public_key.pem_encode() |> String.trim_trailing()
|
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: [],
|
2018-06-14 17:25:55 +02:00
|
|
|
keys: pem,
|
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),
|
|
|
|
outbox_url: Actor.build_url(preferred_username, :outbox),
|
2018-07-27 10:45:35 +02:00
|
|
|
user: nil
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-01 14:45:18 +02:00
|
|
|
def group_factory do
|
|
|
|
struct!(
|
|
|
|
actor_factory(),
|
|
|
|
%{
|
|
|
|
type: :Group
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def follower_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Follower{
|
2018-08-01 14:45:18 +02:00
|
|
|
target_actor: build(:actor),
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-11-23 15:03:53 +01:00
|
|
|
def tag_factory do
|
|
|
|
%Mobilizon.Events.Tag{
|
|
|
|
title: "MyTag",
|
|
|
|
slug: sequence("MyTag")
|
|
|
|
}
|
|
|
|
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},
|
2018-01-17 11:39:01 +01:00
|
|
|
floor: "Myfloor",
|
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()
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.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,
|
2018-11-27 17:54:54 +01:00
|
|
|
in_reply_to_comment: nil,
|
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,
|
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-04-25 19:05:05 +02:00
|
|
|
url: Routes.page_url(Endpoint, :event, uuid),
|
2019-01-21 15:08:22 +01:00
|
|
|
uuid: uuid
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
def participant_factory do
|
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-02-07 16:37:40 +01:00
|
|
|
role: :creator
|
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
|
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),
|
2019-03-01 17:11:28 +01:00
|
|
|
role: :not_approved
|
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)
|
|
|
|
|
|
|
|
%{
|
|
|
|
"url" => [%{"href" => url, "mediaType" => "image/jpeg"}],
|
|
|
|
"size" => 13_227,
|
|
|
|
"type" => "Image"
|
|
|
|
} = 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,
|
|
|
|
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 17:56:50 +01:00
|
|
|
end
|