2021-01-18 16:53:49 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe UserBookmarkList do
|
|
|
|
let(:params) { {} }
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
let(:list) { UserBookmarkList.new(user: user, guardian: Guardian.new(user), params: params) }
|
|
|
|
|
2022-05-22 19:07:15 -05:00
|
|
|
before do
|
|
|
|
register_test_bookmarkable
|
2021-01-18 16:53:49 -06:00
|
|
|
|
2022-05-22 19:07:15 -05:00
|
|
|
Fabricate(:topic_user, user: user, topic: post_bookmark.bookmarkable.topic)
|
|
|
|
Fabricate(:topic_user, user: user, topic: topic_bookmark.bookmarkable)
|
|
|
|
user_bookmark
|
|
|
|
end
|
2022-04-21 17:23:42 -05:00
|
|
|
|
2023-03-07 18:39:12 -06:00
|
|
|
after { DiscoursePluginRegistry.reset! }
|
|
|
|
|
2022-05-22 19:07:15 -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)) }
|
2022-04-21 17:23:42 -05:00
|
|
|
|
2022-05-22 19:07:15 -05:00
|
|
|
it "returns all types of bookmarks" do
|
|
|
|
list.load
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(list.bookmarks.map(&:id)).to match_array(
|
|
|
|
[post_bookmark.id, topic_bookmark.id, user_bookmark.id],
|
|
|
|
)
|
2022-09-01 05:04:00 -05:00
|
|
|
expect(list.has_more).to eq(false)
|
2021-01-18 16:53:49 -06:00
|
|
|
end
|
|
|
|
|
2022-05-22 19:07:15 -05:00
|
|
|
it "defaults to 20 per page" do
|
|
|
|
expect(list.per_page).to eq(20)
|
|
|
|
end
|
2022-04-21 17:23:42 -05:00
|
|
|
|
2022-05-22 19:07:15 -05:00
|
|
|
context "when the per_page param is too high" do
|
|
|
|
let(:params) { { per_page: 1000 } }
|
2021-01-18 16:53:49 -06:00
|
|
|
|
2022-05-22 19:07:15 -05:00
|
|
|
it "does not allow more than X bookmarks to be requested per page" do
|
|
|
|
22.times do
|
|
|
|
bookmark = Fabricate(:bookmark, user: user, bookmarkable: Fabricate(:post))
|
|
|
|
Fabricate(:topic_user, topic: bookmark.bookmarkable.topic, user: user)
|
|
|
|
end
|
|
|
|
expect(list.load.count).to eq(20)
|
2021-01-18 16:53:49 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|