2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe ReviewableSerializer do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:reviewable) { Fabricate(:reviewable_queued_post) }
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2019-01-03 11:03:01 -06:00
|
|
|
|
|
|
|
it "serializes all the fields" do
|
2019-04-10 04:25:45 -05:00
|
|
|
json = described_class.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
2019-01-03 11:03:01 -06:00
|
|
|
|
|
|
|
expect(json[:id]).to eq(reviewable.id)
|
2021-12-08 11:12:24 -06:00
|
|
|
expect(json[:status]).to eq(reviewable.status_for_database)
|
2019-01-03 11:03:01 -06:00
|
|
|
expect(json[:type]).to eq(reviewable.type)
|
|
|
|
expect(json[:created_at]).to eq(reviewable.created_at)
|
|
|
|
expect(json[:category_id]).to eq(reviewable.category_id)
|
|
|
|
expect(json[:can_edit]).to eq(true)
|
|
|
|
expect(json[:version]).to eq(0)
|
2019-04-10 04:25:45 -05:00
|
|
|
expect(json[:removed_topic_id]).to be_nil
|
|
|
|
end
|
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
it "Includes the removed topic id when the topis was deleted" do
|
2019-04-10 04:25:45 -05:00
|
|
|
reviewable.topic.trash!(admin)
|
|
|
|
json = described_class.new(reviewable.reload, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
expect(json[:removed_topic_id]).to eq reviewable.topic_id
|
2019-01-03 11:03:01 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "will not throw an error when the payload is `nil`" do
|
|
|
|
reviewable.payload = nil
|
2023-01-09 05:18:21 -06:00
|
|
|
json =
|
|
|
|
ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
expect(json["payload"]).to be_blank
|
2019-01-03 11:03:01 -06:00
|
|
|
end
|
2019-06-10 10:33:10 -05:00
|
|
|
|
|
|
|
describe "urls" do
|
|
|
|
it "links to the flagged post" do
|
|
|
|
fp = Fabricate(:reviewable_flagged_post)
|
|
|
|
json = described_class.new(fp, scope: Guardian.new(admin), root: nil).as_json
|
2019-11-14 17:57:24 -06:00
|
|
|
expect(json[:target_url]).to eq(Discourse.base_url + fp.post.url)
|
2019-06-10 10:33:10 -05:00
|
|
|
expect(json[:topic_url]).to eq(fp.topic.url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "supports deleted topics" do
|
|
|
|
fp = Fabricate(:reviewable_flagged_post)
|
|
|
|
fp.topic.trash!(admin)
|
|
|
|
fp.reload
|
|
|
|
|
|
|
|
json = described_class.new(fp, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
expect(json[:topic_url]).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "links to the queued post" do
|
|
|
|
json = described_class.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
expect(json[:target_url]).to eq(reviewable.topic.url)
|
|
|
|
expect(json[:topic_url]).to eq(reviewable.topic.url)
|
|
|
|
end
|
|
|
|
end
|
2019-01-03 11:03:01 -06:00
|
|
|
end
|