A platform for community discussion. Free, open, simple.
DEV: improves reliability of delete/restore/update specs (#24265)
Joffrey JAFFEUX039d060832c7
diff --git a/plugins/chat/app/services/chat/create_message.rb b/plugins/chat/app/services/chat/create_message.rbindex 9f578f6e988..51e14ddf01e 100644--- a/plugins/chat/app/services/chat/create_message.rb+++ b/plugins/chat/app/services/chat/create_message.rb@@ -44,7 +44,7 @@ module Chatstep :process_direct_message_channelendstep :publish_new_thread- step :publish_new_message_events+ step :processstep :publish_user_tracking_stateclass Contract@@ -175,17 +175,15 @@ module ChatChat::Publisher.publish_thread_created!(channel, reply, thread.id)end- def publish_new_message_events(channel:, message_instance:, contract:, **)- staged_id = contract.staged_id-+ def process(channel:, message_instance:, contract:, **)if contract.process_inlineJobs::Chat::ProcessMessage.new.execute(- { chat_message_id: message_instance.id, staged_id: staged_id },+ { chat_message_id: message_instance.id, staged_id: contract.staged_id },)elseJobs.enqueue(Jobs::Chat::ProcessMessage,- { chat_message_id: message_instance.id, staged_id: staged_id },+ { chat_message_id: message_instance.id, staged_id: contract.staged_id },)endenddiff --git a/plugins/chat/assets/javascripts/discourse/models/chat-message.js b/plugins/chat/assets/javascripts/discourse/models/chat-message.jsindex dfd23414582..c7ddb899019 100644--- a/plugins/chat/assets/javascripts/discourse/models/chat-message.js+++ b/plugins/chat/assets/javascripts/discourse/models/chat-message.js@@ -26,7 +26,7 @@ export default class ChatMessage {@tracked selected;@tracked channel;@tracked staged;- @tracked processed;+ @tracked processed = true;@tracked draftSaved;@tracked draft;@tracked createdAt;diff --git a/plugins/chat/spec/integration/thread_replies_count_cache_accuracy_spec.rb b/plugins/chat/spec/integration/thread_replies_count_cache_accuracy_spec.rbindex 81daf5fc3a5..dfcc1747739 100644--- a/plugins/chat/spec/integration/thread_replies_count_cache_accuracy_spec.rb+++ b/plugins/chat/spec/integration/thread_replies_count_cache_accuracy_spec.rb@@ -51,21 +51,14 @@ RSpec.describe "Chat::Thread replies_count cache accuracy" do# Lose the cache intentionally.Chat::Thread.clear_caches!(thread.id)message_to_destroy = thread.last_message- Chat::TrashMessage.call(- message_id: message_to_destroy.id,- channel_id: thread.channel_id,- guardian: guardian,- )+ trash_message!(message_to_destroy, user: guardian.user)expect(thread.replies_count_cache).to eq(5)expect(thread.reload.replies_count).to eq(5)# Lose the cache intentionally.Chat::Thread.clear_caches!(thread.id)- Chat::RestoreMessage.call(- message_id: message_to_destroy.id,- channel_id: thread.channel_id,- guardian: guardian,- )++ restore_message!(message_to_destroy, user: guardian.user)expect(thread.replies_count_cache).to eq(6)expect(thread.reload.replies_count).to eq(6)enddiff --git a/plugins/chat/spec/models/chat/message_spec.rb b/plugins/chat/spec/models/chat/message_spec.rbindex 8a268fa9a24..0185834f260 100644--- a/plugins/chat/spec/models/chat/message_spec.rb+++ b/plugins/chat/spec/models/chat/message_spec.rb@@ -510,7 +510,7 @@ describe Chat::Message doit "keeps the same hashtags the user has permission to after rebake" dogroup.add(chat_message.user)- update_message(+ update_message!(chat_message,user: chat_message.user,text:@@ -538,7 +538,7 @@ describe Chat::Message doit "creates newly added mentions" doexisting_mention_ids = message.chat_mentions.pluck(:id)- update_message(+ update_message!(message,user: message.user,text: message.message + " @#{user3.username} @#{user4.username} ",@@ -552,14 +552,14 @@ describe Chat::Message doit "drops removed mentions" do# user 2 is not mentioned anymore- update_message(message, user: message.user, text: "Hey @#{user1.username}")+ update_message!(message, user: message.user, text: "Hey @#{user1.username}")expect(message.chat_mentions.pluck(:user_id)).to contain_exactly(user1.id)endit "changes nothing if passed mentions are identical to existing mentions" doexisting_mention_ids = message.chat_mentions.pluck(:id)- update_message(message, user: message.user, text: message.message)+ update_message!(message, user: message.user, text: message.message)expect(message.chat_mentions.pluck(:user_id)).to match_array(already_mentioned)expect(message.chat_mentions.pluck(:id)).to include(*existing_mention_ids) # the mentions weren't recreateddiff --git a/plugins/chat/spec/plugin_helper.rb b/plugins/chat/spec/plugin_helper.rbindex 8824f36bc70..7925d56f746 100644--- a/plugins/chat/spec/plugin_helper.rb+++ b/plugins/chat/spec/plugin_helper.rb@@ -68,7 +68,7 @@ module ChatSpecHelpers)end- def update_message(message, text: nil, user: Discourse.system_user, upload_ids: nil)+ def update_message!(message, text: nil, user: Discourse.system_user, upload_ids: nil)result =Chat::UpdateMessage.call(guardian: user.guardian,@@ -80,6 +80,28 @@ module ChatSpecHelpersservice_failed!(result) if result.failure?result.message_instanceend++ def trash_message!(message, user: Discourse.system_user)+ result =+ Chat::TrashMessage.call(+ message_id: message.id,+ channel_id: message.chat_channel_id,+ guardian: user.guardian,+ )+ service_failed!(result) if result.failure?+ result+ end++ def restore_message!(message, user: Discourse.system_user)+ result =+ Chat::RestoreMessage.call(+ message_id: message.id,+ channel_id: message.chat_channel_id,+ guardian: user.guardian,+ )+ service_failed!(result) if result.failure?+ result+ endendRSpec.configure do |config|diff --git a/plugins/chat/spec/requests/chat/api/channel_threads_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channel_threads_controller_spec.rbindex 9f3f3da1cc7..ccabfaf758b 100644--- a/plugins/chat/spec/requests/chat/api/channel_threads_controller_spec.rb+++ b/plugins/chat/spec/requests/chat/api/channel_threads_controller_spec.rb@@ -120,7 +120,7 @@ RSpec.describe Chat::Api::ChannelThreadsController doendit "has preloaded chat mentions and users for the thread original message" do- update_message(+ update_message!(thread_1.original_message,user: thread_1.original_message.user,text: "@#{current_user.username} hello and @#{thread_2.original_message_user.username}!",diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex cc664a8db69..50729243847 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -277,7 +277,7 @@ RSpec.describe "Chat channel", type: :system doendit "renders safe HTML like mentions (which are just links) in the reply-to" do- update_message(+ update_message!(message_2,user: other_user,text: "@#{other_user.username} <mark>not marked</mark>",diff --git a/plugins/chat/spec/system/deleted_message_spec.rb b/plugins/chat/spec/system/deleted_message_spec.rbindex c4a0e12b08e..62427b251a2 100644--- a/plugins/chat/spec/system/deleted_message_spec.rb+++ b/plugins/chat/spec/system/deleted_message_spec.rb@@ -83,10 +83,10 @@ RSpec.describe "Deleted message", type: :system doit "groups them" dochat_page.visit_channel(channel_1)- channel_page.messages.delete(message_1)- channel_page.messages.delete(message_3)- channel_page.messages.delete(message_4)- channel_page.messages.delete(message_6)+ trash_message!(message_1)+ trash_message!(message_3)+ trash_message!(message_4)+ trash_message!(message_6)expect(channel_page.messages).to have_deleted_messages(message_1, message_6)expect(channel_page.messages).to have_deleted_message(message_4, count: 2)diff --git a/plugins/chat/spec/system/message_thread_indicator_spec.rb b/plugins/chat/spec/system/message_thread_indicator_spec.rbindex 6ee0ca5093c..60a62473b96 100644--- a/plugins/chat/spec/system/message_thread_indicator_spec.rb+++ b/plugins/chat/spec/system/message_thread_indicator_spec.rb@@ -124,7 +124,7 @@ describe "Thread indicator for chat messages", type: :system doendit "shows an excerpt of the last reply in the thread" do- update_message(+ update_message!(thread_1.original_message,user: thread_1.original_message.user,text: "test for excerpt",@@ -141,7 +141,7 @@ describe "Thread indicator for chat messages", type: :system donew_user = Fabricate(:user)chat_system_user_bootstrap(user: new_user, channel: channel)original_last_reply = thread_1.last_message- update_message(original_last_reply, user: original_last_reply.user, text: "test for excerpt")+ update_message!(original_last_reply, user: original_last_reply.user, text: "test for excerpt")chat_page.visit_channel(channel)diff --git a/plugins/chat/spec/system/page_objects/chat/components/message.rb b/plugins/chat/spec/system/page_objects/chat/components/message.rbindex 83d6b506d66..677e7f5fc45 100644--- a/plugins/chat/spec/system/page_objects/chat/components/message.rb+++ b/plugins/chat/spec/system/page_objects/chat/components/message.rb@@ -96,7 +96,7 @@ module PageObjectsif args[:not_processed]selector += ".-not-processed"else- selector += ".-processed"+ selector += ".-processed.-persisted"endselector += "[data-id=\"#{args[:id]}\"]" if args[:id]diff --git a/plugins/chat/spec/system/reply_to_message/full_page_spec.rb b/plugins/chat/spec/system/reply_to_message/full_page_spec.rbindex fbc1eaa90e8..a1a7186db1d 100644--- a/plugins/chat/spec/system/reply_to_message/full_page_spec.rb+++ b/plugins/chat/spec/system/reply_to_message/full_page_spec.rb@@ -99,7 +99,7 @@ RSpec.describe "Reply to message - channel - full page", type: :system doit "renders safe HTML from the original message excerpt" doother_user = Fabricate(:user)- update_message(+ update_message!(original_message,user: current_user,text: "@#{other_user.username} <mark>not marked</mark>",diff --git a/plugins/chat/spec/system/thread_list/full_page_spec.rb b/plugins/chat/spec/system/thread_list/full_page_spec.rbindex 67ccfa8d9f9..33b748c9c1c 100644--- a/plugins/chat/spec/system/thread_list/full_page_spec.rb+++ b/plugins/chat/spec/system/thread_list/full_page_spec.rb@@ -90,7 +90,7 @@ describe "Thread list in side panel | full page", type: :system doendit "shows an excerpt of the original message of the thread", inline: true do- update_message(+ update_message!(thread_1.original_message,user: thread_1.original_message.user,text: "This is a long message for the excerpt",@@ -157,11 +157,7 @@ describe "Thread list in side panel | full page", type: :system doexpect(thread_list_page).to have_thread(thread_1)- Chat::TrashMessage.call(- message_id: thread_1.original_message.id,- channel_id: thread_1.channel.id,- guardian: other_user.guardian,- )+ trash_message!(thread_1.original_message, user: other_user)expect(thread_list_page).to have_no_thread(thread_1)enddiff --git a/plugins/chat/spec/system/thread_preview_spec.rb b/plugins/chat/spec/system/thread_preview_spec.rbindex 0eb692732a9..a4f87233067 100644--- a/plugins/chat/spec/system/thread_preview_spec.rb+++ b/plugins/chat/spec/system/thread_preview_spec.rb@@ -51,13 +51,7 @@ describe "Thread preview", type: :system docontext "when message has thread with deleted original message" dofab!(:thread_1) { Fabricate(:chat_thread, channel: channel_1, original_message: message_1) }- before do- Chat::TrashMessage.call(- message_id: message_1.id,- channel_id: channel_1.id,- guardian: message_1.user.guardian,- )- end+ before { trash_message!(message_1, user: message_1.user) }it "shows preview" dochat_page.visit_channel(channel_1)