FIX: Polymorphic bookmarks for new user narrative bot (#16683)

This commit allows the new user narrative bot to work
with polymorphic bookmarks, gated behind the
use_polymorphic_bookmarks site setting.
This commit is contained in:
Martin Brennan
2022-05-09 16:19:18 +10:00
committed by GitHub
parent 222c8d9b6a
commit 4d0ac8636c
3 changed files with 22 additions and 6 deletions

View File

@ -248,7 +248,22 @@ describe DiscourseNarrativeBot::NewUserNarrative do
end
end
it 'should create the right reply when bookmarks with reminders are enabled' do
it 'adds an after commit model callback to bookmark' do
Jobs.run_later!
bookmark = Fabricate(:bookmark, post: Fabricate(:post))
expect_job_enqueued(job: :bot_input, args: { user_id: bookmark.user_id, post_id: bookmark.post_id, input: "bookmark" })
end
it 'adds an after commit model callback to bookmark for polymorphic bookmarks (but only for post polymorphic bookmarks)' do
SiteSetting.use_polymorphic_bookmarks = true
Jobs.run_later!
bookmark = Fabricate(:bookmark, bookmarkable: Fabricate(:post))
expect_job_enqueued(job: :bot_input, args: { user_id: bookmark.user_id, post_id: bookmark.bookmarkable_id, input: "bookmark" })
bookmark2 = Fabricate(:bookmark, bookmarkable: Fabricate(:topic))
expect_not_enqueued_with(job: :bot_input, args: { user_id: bookmark.user_id, post_id: kind_of(Integer), input: "bookmark" })
end
it 'should create the right reply when the bookmark is created' do
post.update!(user: discobot_user)
narrative.expects(:enqueue_timeout_job).with(user)