}
end
- def user_factory do
+ def user_factory(attrs \\ %{}) do
user = %User{
name: sequence(:name, &"Test ใในใ User #{&1}"),
email: sequence(:email, &"user#{&1}@example.com"),
nickname: sequence(:nickname, &"nick#{&1}"),
password_hash: Pbkdf2.hash_pwd_salt("test"),
bio: sequence(:bio, &"Tester Number #{&1}"),
+ is_discoverable: true,
last_digest_emailed_at: NaiveDateTime.utc_now(),
last_refreshed_at: NaiveDateTime.utc_now(),
notification_settings: %Pleroma.User.NotificationSetting{},
ap_enabled: true
}
- %{
- user
- | ap_id: User.ap_id(user),
- follower_address: User.ap_followers(user),
- following_address: User.ap_following(user),
- raw_bio: user.bio
- }
+ urls =
+ if attrs[:local] == false do
+ base_domain = Enum.random(["domain1.com", "domain2.com", "domain3.com"])
+
+ ap_id = "https://#{base_domain}/users/#{user.nickname}"
+
+ %{
+ ap_id: ap_id,
+ follower_address: ap_id <> "/followers",
+ following_address: ap_id <> "/following"
+ }
+ else
+ %{
+ ap_id: User.ap_id(user),
+ follower_address: User.ap_followers(user),
+ following_address: User.ap_following(user)
+ }
+ end
+
+ user
+ |> Map.put(:raw_bio, user.bio)
+ |> Map.merge(urls)
+ |> merge_attributes(attrs)
end
def user_relationship_factory(attrs \\ %{}) do
phrase: "cofe"
}
end
-
- def chat_factory(attrs \\ %{}) do
- user = attrs[:user] || insert(:user)
- recipient = attrs[:recipient] || insert(:user)
-
- %Pleroma.Chat{
- user_id: user.id,
- recipient: recipient.ap_id
- }
- end
-
- def chat_message_factory(attrs \\ %{}) do
- text = sequence(:text, &"This is :moominmamma: chat message #{&1}")
- chat = attrs[:chat] || insert(:chat)
-
- data = %{
- "type" => "ChatMessage",
- "content" => text,
- "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
- "actor" => User.get_by_id(chat.user_id).ap_id,
- "to" => [chat.recipient],
- "published" => DateTime.utc_now() |> DateTime.to_iso8601()
- }
-
- %Pleroma.Object{
- data: merge_attributes(data, Map.get(attrs, :data, %{}))
- }
- end
-
- def chat_message_activity_factory(attrs \\ %{}) do
- chat = attrs[:chat] || insert(:chat)
- chat_message = attrs[:chat_message] || insert(:chat_message, chat: chat)
-
- data_attrs = attrs[:data_attrs] || %{}
- attrs = Map.drop(attrs, [:chat, :chat_message, :data_attrs])
-
- data =
- %{
- "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
- "type" => "Create",
- "actor" => chat_message.data["actor"],
- "to" => chat_message.data["to"],
- "object" => chat_message.data["id"],
- "published" => DateTime.utc_now() |> DateTime.to_iso8601()
- }
- |> Map.merge(data_attrs)
-
- %Pleroma.Activity{
- data: data,
- actor: data["actor"],
- recipients: data["to"]
- }
- |> Map.merge(attrs)
- end
end