mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
What is the problem? The review queue throws a JavaScript error when processing MessageBus updates: ``` MESSAGE BUS FAIL: callback /reviewable_action caused exception TypeError: Cannot read properties of undefined (reading 'includes') ``` The bug flow is: 1. `Reviewable::PerformResult#initialize` only sets `@remove_reviewable_ids` when `success?` is true, leaving it nil otherwise 2. `ReviewablePerformResultSerializer` serializes nil as JSON null 3. MessageBus publishes this to `/reviewable_action` channel 4. The JS `_updateStatus` callback in `ReviewableItem` receives data with `remove_reviewable_ids` as null/undefined 5. Calling `.includes()` on null throws TypeError What is the solution? Always initialize `@remove_reviewable_ids` as an array in `Reviewable::PerformResult#initialize` (empty for failures, containing the reviewable id for successes). Also add defensive optional chaining in the JS `ReviewableItem#_updateStatus` callback and update the truthy check in `ReviewableItem#_performResult` to verify array length since `[]` is truthy in JavaScript.
19 lines
554 B
Ruby
Vendored
19 lines
554 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
RSpec.describe Reviewable::PerformResult do
|
|
fab!(:reviewable, :reviewable_queued_post)
|
|
|
|
describe "#initialize" do
|
|
it "sets remove_reviewable_ids to array with reviewable id on success" do
|
|
result = described_class.new(reviewable, :success)
|
|
|
|
expect(result.remove_reviewable_ids).to eq([reviewable.id])
|
|
end
|
|
|
|
it "sets remove_reviewable_ids to empty array on failure" do
|
|
result = described_class.new(reviewable, :failure)
|
|
|
|
expect(result.remove_reviewable_ids).to eq([])
|
|
end
|
|
end
|
|
end
|