2022-11-02 21:41:30 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
Fabricator(:chat_channel) do
|
|
|
|
name do
|
2022-11-09 08:28:31 +08:00
|
|
|
sequence(:name) do |n|
|
|
|
|
random_name = [
|
|
|
|
"Gaming Lounge",
|
|
|
|
"Music Lodge",
|
|
|
|
"Random",
|
|
|
|
"Politics",
|
|
|
|
"Sports Center",
|
|
|
|
"Kino Buffs",
|
|
|
|
].sample
|
|
|
|
"#{random_name} #{n}"
|
|
|
|
end
|
2022-11-02 21:41:30 +08:00
|
|
|
end
|
|
|
|
chatable { Fabricate(:category) }
|
2022-11-09 08:28:31 +08:00
|
|
|
type do |attrs|
|
|
|
|
attrs[:chatable_type] == "Category" || attrs[:chatable]&.is_a?(Category) ? "CategoryChannel" : "DirectMessageChannel"
|
|
|
|
end
|
2022-11-02 21:41:30 +08:00
|
|
|
status { :open }
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:category_channel, from: :chat_channel, class_name: :category_channel) {}
|
|
|
|
|
2022-11-02 22:53:36 +08:00
|
|
|
Fabricator(:direct_message_channel, from: :chat_channel, class_name: :direct_message_channel) do
|
2022-11-02 21:41:30 +08:00
|
|
|
transient :users
|
|
|
|
chatable do |attrs|
|
2022-11-02 22:53:36 +08:00
|
|
|
Fabricate(:direct_message, users: attrs[:users] || [Fabricate(:user), Fabricate(:user)])
|
2022-11-02 21:41:30 +08:00
|
|
|
end
|
|
|
|
status { :open }
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:chat_message) do
|
|
|
|
chat_channel
|
|
|
|
user
|
|
|
|
message "Beep boop"
|
|
|
|
cooked { |attrs| ChatMessage.cook(attrs[:message]) }
|
|
|
|
cooked_version ChatMessage::BAKED_VERSION
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:chat_mention) do
|
|
|
|
chat_message { Fabricate(:chat_message) }
|
|
|
|
user { Fabricate(:user) }
|
|
|
|
notification { Fabricate(:notification) }
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:chat_message_reaction) do
|
|
|
|
chat_message { Fabricate(:chat_message) }
|
|
|
|
user { Fabricate(:user) }
|
|
|
|
emoji { %w[+1 tada heart joffrey_facepalm].sample }
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:chat_upload) do
|
|
|
|
chat_message { Fabricate(:chat_message) }
|
|
|
|
upload { Fabricate(:upload) }
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:chat_message_revision) do
|
|
|
|
chat_message { Fabricate(:chat_message) }
|
|
|
|
old_message { "something old" }
|
|
|
|
new_message { "something new" }
|
2022-11-08 07:06:13 +08:00
|
|
|
user { |attrs| attrs[:chat_message].user }
|
2022-11-02 21:41:30 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:reviewable_chat_message) do
|
|
|
|
reviewable_by_moderator true
|
|
|
|
type "ReviewableChatMessage"
|
|
|
|
created_by { Fabricate(:user) }
|
|
|
|
target_type "ChatMessage"
|
|
|
|
target { Fabricate(:chat_message) }
|
|
|
|
reviewable_scores { |p| [Fabricate.build(:reviewable_score, reviewable_id: p[:id])] }
|
|
|
|
end
|
|
|
|
|
2022-11-02 22:53:36 +08:00
|
|
|
Fabricator(:direct_message) { users { [Fabricate(:user), Fabricate(:user)] } }
|
2022-11-02 21:41:30 +08:00
|
|
|
|
|
|
|
Fabricator(:chat_webhook_event) do
|
|
|
|
chat_message { Fabricate(:chat_message) }
|
|
|
|
incoming_chat_webhook do |attrs|
|
|
|
|
Fabricate(:incoming_chat_webhook, chat_channel: attrs[:chat_message].chat_channel)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:incoming_chat_webhook) do
|
|
|
|
name { sequence(:name) { |i| "#{i + 1}" } }
|
|
|
|
key { sequence(:key) { |i| "#{i + 1}" } }
|
|
|
|
chat_channel { Fabricate(:chat_channel, chatable: Fabricate(:category)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:user_chat_channel_membership) do
|
|
|
|
user
|
|
|
|
chat_channel
|
|
|
|
following true
|
|
|
|
end
|
|
|
|
|
|
|
|
Fabricator(:user_chat_channel_membership_for_dm, from: :user_chat_channel_membership) do
|
|
|
|
user
|
|
|
|
chat_channel
|
|
|
|
following true
|
|
|
|
desktop_notification_level 2
|
|
|
|
mobile_notification_level 2
|
|
|
|
end
|