2017-12-05 01:14:43 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Admin::BackupsController do
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "parameters" do
|
|
|
|
it "returns 404 without a valid filter" do
|
|
|
|
get "/admin/moderation_history.json"
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).not_to be_successful
|
2017-12-05 01:14:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 without a valid id" do
|
|
|
|
get "/admin/moderation_history.json?filter=topic"
|
2018-06-05 15:29:17 +08:00
|
|
|
expect(response).not_to be_successful
|
2017-12-05 01:14:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "for a post" do
|
|
|
|
it "returns an empty array when the post doesn't exist" do
|
|
|
|
get "/admin/moderation_history.json?filter=post&post_id=99999999"
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-12-05 01:14:43 +08:00
|
|
|
expect(::JSON.parse(response.body)['moderation_history']).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a history when the post exists" do
|
|
|
|
p = Fabricate(:post)
|
2018-06-05 15:29:17 +08:00
|
|
|
p = Fabricate(:post, topic: p.topic)
|
2017-12-05 01:14:43 +08:00
|
|
|
PostDestroyer.new(Discourse.system_user, p).destroy
|
|
|
|
get "/admin/moderation_history.json?filter=post&post_id=#{p.id}"
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-12-05 01:14:43 +08:00
|
|
|
expect(::JSON.parse(response.body)['moderation_history']).to be_present
|
|
|
|
end
|
|
|
|
|
2018-11-22 10:22:23 +08:00
|
|
|
it 'includes post approval record' do
|
|
|
|
queued_post = Fabricate(:queued_post)
|
|
|
|
post = queued_post.approve!(Discourse.system_user)
|
|
|
|
|
|
|
|
get "/admin/moderation_history.json?filter=post&post_id=#{post.id}"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
moderation_history = JSON.parse(response.body)['moderation_history'].first
|
|
|
|
expect(moderation_history['action_name']).to eq('post_approved')
|
|
|
|
end
|
2017-12-05 01:14:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "for a topic" do
|
|
|
|
it "returns empty history when the topic doesn't exist" do
|
|
|
|
get "/admin/moderation_history.json?filter=topic&topic_id=1234"
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-12-05 01:14:43 +08:00
|
|
|
expect(::JSON.parse(response.body)['moderation_history']).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a history when the topic exists" do
|
|
|
|
p = Fabricate(:post)
|
|
|
|
PostDestroyer.new(Discourse.system_user, p).destroy
|
|
|
|
get "/admin/moderation_history.json?filter=topic&topic_id=#{p.topic_id}"
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2017-12-05 01:14:43 +08:00
|
|
|
expect(::JSON.parse(response.body)['moderation_history']).to be_present
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|