Skip to content

Commit

Permalink
Create spec for report notify? policy
Browse files Browse the repository at this point in the history
  • Loading branch information
krauselukas authored and danidoni committed Oct 2, 2023
1 parent e245a71 commit 02b968d
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/api/spec/policies/report_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

let(:user) { create(:confirmed_user) }

before do
Flipper.enable(:content_moderation)
end

permissions :show? do
context 'when the current user is the owner of the report' do
let(:report) { create(:report, user: user) }
Expand All @@ -27,10 +31,6 @@
end

permissions :create? do
before do
Flipper.enable(:content_moderation, user)
end

context 'when the current user has already reported it' do
let(:reported_comment) { create(:comment_package) }
let(:report) { build(:report, user: user, reportable: reported_comment) }
Expand Down Expand Up @@ -101,4 +101,35 @@
end
end
end

permissions :notify? do
let(:staff_user) { create(:staff_user) }
let(:admin_user) { create(:admin_user) }

context 'when there is no user with moderator role' do
it 'notifies admin users' do
expect(subject).to permit(admin_user, Report)
end

it 'notifies staff users' do
expect(subject).to permit(staff_user, Report)
end
end

context 'when there is a user with moderator role' do
let!(:moderator_user) { create(:moderator) }

it 'does not notify admin users' do
expect(subject).not_to(permit(admin_user, Report))
end

it 'does not notify staff users' do
expect(subject).not_to(permit(staff_user, Report))
end

it 'notifies the moderator' do
expect(subject).to permit(moderator_user, Report)
end
end
end
end

0 comments on commit 02b968d

Please sign in to comment.