2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe ReviewableQueuedPostSerializer do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2019-01-03 12:03:01 -05:00
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "new topic" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:reviewable) { Fabricate(:reviewable_queued_post_topic) }
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
it "allows us to edit category / title" do
|
|
|
|
json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
|
|
|
|
payload = json[:payload]
|
|
|
|
expect(payload['raw']).to eq('hello world post contents.')
|
|
|
|
expect(payload['title']).to eq('queued post title')
|
|
|
|
expect(payload['tags']).to eq(['cool', 'neat'])
|
|
|
|
expect(json[:topic_id]).to be_blank
|
|
|
|
expect(json[:can_edit]).to eq(true)
|
|
|
|
|
|
|
|
fields = json[:editable_fields]
|
|
|
|
expect(fields).to be_present
|
|
|
|
|
|
|
|
category_field = fields.find { |f| f[:id] == 'category_id' }
|
|
|
|
expect(category_field).to be_present
|
|
|
|
expect(category_field[:type]).to eq(:category)
|
|
|
|
|
|
|
|
title_field = fields.find { |f| f[:id] == 'payload.title' }
|
|
|
|
expect(title_field).to be_present
|
|
|
|
expect(title_field[:type]).to eq(:text)
|
|
|
|
|
|
|
|
raw_field = fields.find { |f| f[:id] == 'payload.raw' }
|
|
|
|
expect(raw_field).to be_present
|
|
|
|
expect(raw_field[:type]).to eq(:editor)
|
|
|
|
|
|
|
|
tags_field = fields.find { |f| f[:id] == 'payload.tags' }
|
|
|
|
expect(tags_field).to be_present
|
|
|
|
expect(tags_field[:type]).to eq(:tags)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "reply to an existing topic" do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:reviewable) { Fabricate(:reviewable_queued_post) }
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
it "includes correct user fields" do
|
|
|
|
json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
|
|
|
|
payload = json[:payload]
|
|
|
|
|
|
|
|
expect(payload['raw']).to eq('hello world post contents.')
|
|
|
|
expect(payload['title']).to be_blank
|
2019-07-19 11:56:14 -04:00
|
|
|
expect(payload['via_email']).to eq(true)
|
|
|
|
expect(payload['raw_email']).to eq('store_me')
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(json[:topic_id]).to eq(reviewable.topic_id)
|
2019-04-01 14:28:57 -04:00
|
|
|
expect(json[:topic_url]).to eq(reviewable.topic.url)
|
2019-01-03 12:03:01 -05:00
|
|
|
expect(json[:can_edit]).to eq(true)
|
|
|
|
|
|
|
|
fields = json[:editable_fields]
|
|
|
|
expect(fields).to be_present
|
|
|
|
|
|
|
|
expect(fields.any? { |f| f[:id] == 'payload.title' }).to eq(false)
|
|
|
|
expect(fields.any? { |f| f[:id] == 'category_id' }).to eq(false)
|
|
|
|
|
|
|
|
raw_field = fields.find { |f| f[:id] == 'payload.raw' }
|
|
|
|
expect(raw_field).to be_present
|
|
|
|
expect(raw_field[:type]).to eq(:editor)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|