FIX: correctly pass topic/posts context (#26882)
This case had not been tested end to end as `Discourse.track_events` was not working when wrapping `send_message`. Because of this lack of end to end test, a regression has been created when renaming the expected context properties. This commit fixes the regression and write a slightly convulted, but effective end to end test.
This commit is contained in:
parent
95885645d9
commit
00d88766b2
|
@ -7,7 +7,7 @@ export function extractCurrentTopicInfo(context) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = { topic_id: topic.id };
|
const info = { context_topic_id: topic.id };
|
||||||
const currentPostNumber = parseInt(topic.current_post_number, 10);
|
const currentPostNumber = parseInt(topic.current_post_number, 10);
|
||||||
const posts = topic.postStream.posts;
|
const posts = topic.postStream.posts;
|
||||||
|
|
||||||
|
@ -23,7 +23,11 @@ export function extractCurrentTopicInfo(context) {
|
||||||
!post.hidden && !post.deleted_at && post.post_number > currentPostNumber
|
!post.hidden && !post.deleted_at && post.post_number > currentPostNumber
|
||||||
);
|
);
|
||||||
|
|
||||||
info.post_ids = [previousPost?.id, currentPost?.id, nextPost?.id];
|
info.context_post_ids = [
|
||||||
|
previousPost?.id,
|
||||||
|
currentPost?.id,
|
||||||
|
nextPost?.id,
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,4 +104,39 @@ RSpec.describe "Send message", type: :system do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when sending message from drawer" do
|
||||||
|
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
|
||||||
|
let(:topic_page) { PageObjects::Pages::Topic.new }
|
||||||
|
|
||||||
|
fab!(:post_1) { Fabricate(:post) }
|
||||||
|
fab!(:post_2) { Fabricate(:post, topic: post_1.topic) }
|
||||||
|
fab!(:channel_1) { Fabricate(:chat_channel) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in(user_1)
|
||||||
|
channel_1.add(user_1)
|
||||||
|
Jobs.run_immediately!
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has topic context" do
|
||||||
|
tested_context = {}
|
||||||
|
blk = Proc.new { |message, channel, user, context| tested_context = context }
|
||||||
|
|
||||||
|
begin
|
||||||
|
DiscourseEvent.on(:chat_message_created, &blk)
|
||||||
|
topic_page.visit_topic(post_1.topic)
|
||||||
|
chat_page.open_from_header
|
||||||
|
drawer_page.open_channel(channel_1)
|
||||||
|
channel_page.send_message
|
||||||
|
|
||||||
|
try_until_success do
|
||||||
|
expect(tested_context.dig(:context, :post_ids)).to eq([post_1.id, post_2.id])
|
||||||
|
expect(tested_context.dig(:context, :topic_id)).to eq(post_1.topic_id)
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
DiscourseEvent.off(:chat_message_created, &blk)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue