DEV: Create post actions without creating a notification and store custom data. (#15397)

I plan to use this in an upcoming discourse-reactions PR, where I want to like a post without notifying the user, so I can instead create a reaction notification.

Additionally, we decouple the a11y attributes from the icon itself, which will let us extend the widget's icon without losing them.
This commit is contained in:
Roman Rizzi
2021-12-27 11:25:37 -03:00
committed by GitHub
parent 0b34d5ac6c
commit e005e3f153
5 changed files with 46 additions and 7 deletions

View File

@@ -1869,4 +1869,21 @@ describe PostAlerter do
expect(email).to eq(last_email)
end
end
describe 'storing custom data' do
let(:custom_data) { 'custom_string' }
it 'stores custom data inside a notification' do
PostAlerter.new.create_notification(
admin,
Notification.types[:liked],
post,
custom_data: { custom_key: custom_data }
)
liked_notification = Notification.where(notification_type: Notification.types[:liked]).last
expect(liked_notification.data_hash[:custom_key]).to eq(custom_data)
end
end
end