2022-04-21 17:23:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe UserBookmarkListSerializer do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:user)
|
2022-04-21 17:23:42 -05:00
|
|
|
|
|
|
|
context "for polymorphic bookmarks" do
|
|
|
|
before do
|
2022-05-08 18:37:23 -05:00
|
|
|
register_test_bookmarkable
|
2022-04-21 17:23:42 -05:00
|
|
|
Fabricate(:topic_user, user: user, topic: post_bookmark.bookmarkable.topic)
|
|
|
|
Fabricate(:topic_user, user: user, topic: topic_bookmark.bookmarkable)
|
|
|
|
user_bookmark
|
|
|
|
end
|
|
|
|
|
2023-03-07 18:39:12 -06:00
|
|
|
after { DiscoursePluginRegistry.reset! }
|
|
|
|
|
2022-04-21 17:23:42 -05:00
|
|
|
let(:post_bookmark) { Fabricate(:bookmark, user: user, bookmarkable: Fabricate(:post)) }
|
|
|
|
let(:topic_bookmark) { Fabricate(:bookmark, user: user, bookmarkable: Fabricate(:topic)) }
|
|
|
|
let(:user_bookmark) { Fabricate(:bookmark, user: user, bookmarkable: Fabricate(:user)) }
|
|
|
|
|
|
|
|
def run_serializer
|
2023-07-28 06:53:46 -05:00
|
|
|
bookmark_list = UserBookmarkList.new(user: user, guardian: Guardian.new(user))
|
2022-04-21 17:23:42 -05:00
|
|
|
bookmark_list.load
|
|
|
|
UserBookmarkListSerializer.new(bookmark_list)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "chooses the correct class of serializer for all the bookmarkable types" do
|
|
|
|
serializer = run_serializer
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(serializer.bookmarks.map(&:class).map(&:to_s)).to match_array(
|
|
|
|
%w[UserTestBookmarkSerializer UserTopicBookmarkSerializer UserPostBookmarkSerializer],
|
|
|
|
)
|
2022-04-21 17:23:42 -05:00
|
|
|
end
|
2024-04-17 09:23:47 -05:00
|
|
|
|
|
|
|
it "serializes categories" do
|
|
|
|
topic_category = Fabricate(:category)
|
|
|
|
topic_bookmark.bookmarkable.update!(category: topic_category)
|
|
|
|
post_category = Fabricate(:category)
|
|
|
|
post_bookmark.bookmarkable.topic.update!(category: post_category)
|
|
|
|
|
|
|
|
serializer = run_serializer
|
|
|
|
|
|
|
|
expect(serializer.categories).to contain_exactly(topic_category, post_category)
|
|
|
|
end
|
2022-04-21 17:23:42 -05:00
|
|
|
end
|
|
|
|
end
|