docbrown/spec/system/feedback_message_spec.rb
Daniel Uber f2a8cbce7e
Remove "connect" feedback message special treatment (#16167)
* Remove special handling of "connect" feedback by name

The special casing was related to "connect" feedback having both a
reporter and an offender. Check for offender instead.

Additionally, there was special casing in the controller to rate-limit
connect feedback separately from other channels. Since connect doesn't
exist, we should not need this.

There's a small bit of functionality (when I post to feedback_messages, the
number of feedback messages increases) that was removed from the test
case, we can add that back (and "connect" type, and
offender_id attributes) since it looks like it might have been a
useful assertion.

* Add back feedback message controller creates feedback message case

This was removed in the last commit because it was in a "connect" chat
channel context, but the basic "should persist a record" test was
otherwise valid. Submit an abuse-report rather than a connect message
report.

* typo

feeedback, woops.
2022-01-19 08:32:10 -06:00

49 lines
1.5 KiB
Ruby

require "rails_helper"
RSpec.describe "Feedback report", type: :system do
let(:user) { create(:user) }
let(:message) { Faker::Lorem.paragraph }
let(:url) { Faker::Lorem.sentence }
context "when user create a report abuse feedback message" do
before do
sign_in user
end
it "feedback message should increase by one", js: true do
expect do
post "/feedback_messages", params: {
feedback_message: {
message: message,
feedback_type: "abuse-reports",
category: "rude or vulgar",
reported_url: url
}
}, as: :json
end.to change(FeedbackMessage, :count).by(1)
end
end
context "when user creates too many report abuse feedback messages" do
let(:rate_limit_checker) { RateLimitChecker.new(user) }
before do
# avoid hitting new user rate limit check
allow(user).to receive(:created_at).and_return(1.week.ago)
allow(RateLimitChecker).to receive(:new).and_return(rate_limit_checker)
allow(rate_limit_checker).to receive(:limit_by_action)
.with(:feedback_message_creation)
.and_return(true)
end
it "displays a rate limit warning", :flaky, js: true do
visit report_abuse_path
choose("Other")
fill_in "feedback_message_message", with: message
fill_in "feedback_message_reported_url", with: url
click_button "Send Feedback"
expect(page).to have_current_path("/feedback_messages")
expect(page).to have_text("Rate limit reached")
end
end
end