mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 04:43:43 +08:00
56f42d89c5
When creating a bookmark reminder that deletes the bookmark on reminder, if the user clicked on the notification and got taken to the post in the topic the bookmark icon still showed as blue with the reminder clock indicator. This was because the response JSON for reloading a topic post was not including the bookmark attributes, not even the bookmarked boolean. We now return the correct attributes in the serializer, and if bookmarked is false we clear all the bookmark related attributes on the post for the notification to make sure nothing of the old bookmark remains in the UI. This was only a problem if the user did not refresh the app completely inbetween setting the reminder and receiving the notification.
44 lines
1.2 KiB
Ruby
44 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe WebHookPostSerializer do
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
fab!(:post) { Fabricate(:post) }
|
|
|
|
def serialized_for_user(u)
|
|
WebHookPostSerializer.new(post, scope: Guardian.new(u), root: false).as_json
|
|
end
|
|
|
|
it 'should only include the required keys' do
|
|
count = serialized_for_user(admin).keys.count
|
|
difference = count - 41
|
|
|
|
expect(difference).to eq(0), lambda {
|
|
message = +""
|
|
|
|
if difference < 0
|
|
message << "#{difference * -1} key(s) have been removed from this serializer."
|
|
else
|
|
message << "#{difference} key(s) have been added to this serializer."
|
|
end
|
|
|
|
message << "\nPlease verify if those key(s) are required as part of the web hook's payload."
|
|
}
|
|
end
|
|
|
|
it 'should only include deleted topic title for staffs' do
|
|
topic = post.topic
|
|
PostDestroyer.new(Discourse.system_user, post).destroy
|
|
post.reload
|
|
|
|
[nil, post.user, Fabricate(:user)].each do |user|
|
|
expect(serialized_for_user(user)[:topic_title]).to eq(nil)
|
|
end
|
|
|
|
[Fabricate(:moderator), admin].each do |user|
|
|
expect(serialized_for_user(user)[:topic_title]).to eq(topic.title)
|
|
end
|
|
end
|
|
end
|