mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 11:20:57 -06:00
0ca1152c1c
This is so we can join the Notification table onto the Bookmark table. A slight refactor was needed to ensure that the required values are always included and the consumer does not need to think about this. The discourse-chat and discourse-data-explorer plugins will be updated to take advantage of this commit.
64 lines
2.5 KiB
Ruby
64 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe BaseBookmarkable do
|
|
fab!(:bookmark) { Fabricate(:bookmark, bookmarkable: Fabricate(:post)) }
|
|
|
|
describe "#send_reminder_notification" do
|
|
it "raises an error if the data, data.bookmarkable_url, or data.title values are missing from notification_data" do
|
|
expect { BaseBookmarkable.send_reminder_notification(bookmark, {}) }.to raise_error(Discourse::InvalidParameters)
|
|
expect { BaseBookmarkable.send_reminder_notification(bookmark, { data: {} }) }.to raise_error(Discourse::InvalidParameters)
|
|
expect { BaseBookmarkable.send_reminder_notification(bookmark, { data: { title: "test", bookmarkable_url: "test" } }) }.not_to raise_error
|
|
end
|
|
|
|
it "creates a Notification with the required data from the bookmark" do
|
|
BaseBookmarkable.send_reminder_notification(
|
|
bookmark,
|
|
{
|
|
topic_id: bookmark.bookmarkable.topic_id,
|
|
post_number: bookmark.bookmarkable.post_number,
|
|
data: {
|
|
title: bookmark.bookmarkable.topic.title,
|
|
bookmarkable_url: bookmark.bookmarkable.url
|
|
}
|
|
}
|
|
)
|
|
notif = bookmark.user.notifications.last
|
|
expect(notif.notification_type).to eq(Notification.types[:bookmark_reminder])
|
|
expect(notif.topic_id).to eq(bookmark.bookmarkable.topic_id)
|
|
expect(notif.post_number).to eq(bookmark.bookmarkable.post_number)
|
|
expect(notif.data).to eq(
|
|
{
|
|
title: bookmark.bookmarkable.topic.title,
|
|
bookmarkable_url: bookmark.bookmarkable.url,
|
|
display_username: bookmark.user.username,
|
|
bookmark_name: bookmark.name,
|
|
bookmark_id: bookmark.id
|
|
}.to_json
|
|
)
|
|
end
|
|
|
|
it "does not allow the consumer to override display_username, bookmark_name, or bookmark_id" do
|
|
BaseBookmarkable.send_reminder_notification(
|
|
bookmark,
|
|
{
|
|
topic_id: bookmark.bookmarkable.topic_id,
|
|
post_number: bookmark.bookmarkable.post_number,
|
|
data: {
|
|
title: bookmark.bookmarkable.topic.title,
|
|
bookmarkable_url: bookmark.bookmarkable.url,
|
|
display_username: "bad username",
|
|
bookmark_name: "bad name",
|
|
bookmark_id: -89854
|
|
}
|
|
}
|
|
)
|
|
|
|
notif = bookmark.user.notifications.last
|
|
data = JSON.parse(notif[:data])
|
|
expect(data[:display_username]).not_to eq("bad username")
|
|
expect(data[:name]).not_to eq("bad name")
|
|
expect(data[:bookmark_id]).not_to eq(-89854)
|
|
end
|
|
end
|
|
end
|