debian-mirror-gitlab/spec/serializers/admin/abuse_report_entity_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.5 KiB
Ruby
Raw Normal View History

2023-05-27 22:25:52 +05:30
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Admin::AbuseReportEntity, feature_category: :insider_threat do
2023-06-20 00:43:36 +05:30
include Gitlab::Routing
let(:abuse_report) { build_stubbed(:abuse_report) }
2023-05-27 22:25:52 +05:30
let(:entity) do
described_class.new(abuse_report)
end
2023-06-20 00:43:36 +05:30
before do
allow_next_instance_of(described_class) do |instance|
allow(instance).to receive(:markdown_field).with(abuse_report, :message).and_return(abuse_report.message)
end
end
2023-05-27 22:25:52 +05:30
describe '#as_json' do
subject(:entity_hash) { entity.as_json }
it 'exposes correct attributes' do
expect(entity_hash.keys).to include(
:category,
2023-06-20 00:43:36 +05:30
:created_at,
2023-05-27 22:25:52 +05:30
:updated_at,
:reported_user,
2023-06-20 00:43:36 +05:30
:reporter,
:reported_user_path,
:reporter_path,
:user_blocked,
:block_user_path,
:remove_report_path,
:remove_user_and_report_path,
:message
2023-05-27 22:25:52 +05:30
)
end
it 'correctly exposes `reported user`' do
2023-06-20 00:43:36 +05:30
expect(entity_hash[:reported_user].keys).to match_array([:name, :created_at])
2023-05-27 22:25:52 +05:30
end
it 'correctly exposes `reporter`' do
expect(entity_hash[:reporter].keys).to match_array([:name])
end
2023-06-20 00:43:36 +05:30
it 'correctly exposes :reported_user_path' do
expect(entity_hash[:reported_user_path]).to eq user_path(abuse_report.user)
end
it 'correctly exposes :reporter_path' do
expect(entity_hash[:reporter_path]).to eq user_path(abuse_report.reporter)
end
describe 'user_blocked' do
subject(:user_blocked) { entity_hash[:user_blocked] }
context 'when user is blocked' do
before do
allow(abuse_report.user).to receive(:blocked?).and_return(true)
end
it { is_expected.to be true }
end
context 'when user is not blocked' do
before do
allow(abuse_report.user).to receive(:blocked?).and_return(false)
end
it { is_expected.to be false }
end
end
it 'correctly exposes :block_user_path' do
expect(entity_hash[:block_user_path]).to eq block_admin_user_path(abuse_report.user)
end
it 'correctly exposes :remove_report_path' do
expect(entity_hash[:remove_report_path]).to eq admin_abuse_report_path(abuse_report)
end
it 'correctly exposes :remove_user_and_report_path' do
expect(entity_hash[:remove_user_and_report_path]).to eq admin_abuse_report_path(abuse_report, remove_user: true)
end
it 'correctly exposes :message' do
expect(entity_hash[:message]).to eq(abuse_report.message)
end
2023-05-27 22:25:52 +05:30
end
end