* Remove Connect
* Remove more Connect specs
* Remove a lot more Connect code
* 🚮
* It all has to go
* Explicitly add httpclient
* Update application layout
* Remove messages association from User
* Start fixing specs
* reintroduce util function and refactor references
* Remove Connect Cypress test
* Fix more specs
* Remove Connect from listings
* Ignore contact_via_connect column on listings
* Remove contact_via_connect usages
* Ignore mod_chat_channel_id on tags
* Drop Connect tables
* Remove email_connect_messages from user notification settings
* Re-add httpclient 2.8.3
This was mistakenly removed as a merge conflict
* Don't need to exclude removed chat channel file
* Remove unneeded style for chat channels
* Remove unneeded channel list prop type
* Remove chat channels index/connect-link from getPageEntries
* Re-add comment from httpclient in Gemfile
* Remove connect references from mailers
Tag Moderators no longer have a chat channel
No longer will users be notified about new messages (there won't be
any)
No longer will users be notified about channel invites (you can't
invite anyone anymore)
* Don't configure Pusher and remove PUSHER_* from .env_sample
since it's removed from gemfile, the Pusher constant will not resolve, if this is
configured in the environment variables we'll fail to boot.
Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Dan Uber <dan@forem.com>
247 lines
8.3 KiB
Ruby
247 lines
8.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "feedback_messages", type: :request do
|
|
let(:user) { create(:user) }
|
|
|
|
before do
|
|
allow(ForemInstance).to receive(:smtp_enabled?).and_return(true)
|
|
end
|
|
|
|
describe "POST /feedback_messages" do
|
|
def mock_recaptcha_verification
|
|
# rubocop:disable RSpec/AnyInstance
|
|
allow_any_instance_of(FeedbackMessagesController).to(
|
|
receive(:recaptcha_verified?).and_return(true),
|
|
)
|
|
# rubocop:enable RSpec/AnyInstance
|
|
end
|
|
|
|
def mock_recaptcha_config_enabled
|
|
allow(Settings::Authentication).to receive(:recaptcha_secret_key).and_return("someSecretKey")
|
|
allow(Settings::Authentication).to receive(:recaptcha_site_key).and_return("someSiteKey")
|
|
end
|
|
|
|
valid_abuse_report_params = {
|
|
feedback_message: {
|
|
feedback_type: "abuse-reports",
|
|
category: "rude or vulgar",
|
|
reported_url: "https://dev.to",
|
|
message: "this was vulgar"
|
|
}
|
|
}
|
|
|
|
headers = { "HTTP_FASTLY_CLIENT_IP" => "5.6.7.8" }
|
|
|
|
context "with valid params and recaptcha passed" do
|
|
before do
|
|
mock_recaptcha_verification
|
|
end
|
|
|
|
it "creates a feedback message" do
|
|
expect do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end.to change(FeedbackMessage, :count).by(1)
|
|
|
|
feedback_message = FeedbackMessage.last
|
|
expect(feedback_message.message).to eq(
|
|
valid_abuse_report_params[:feedback_message][:message],
|
|
)
|
|
end
|
|
|
|
it "queues a slack message to be sent" do
|
|
sidekiq_assert_enqueued_with(job: Slack::Messengers::Worker) do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end
|
|
|
|
it "doesn't try to send an email" do
|
|
expect do
|
|
perform_enqueued_jobs do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end.not_to change { ActionMailer::Base.deliveries.count }
|
|
end
|
|
end
|
|
|
|
context "with valid params and recaptcha not configured" do
|
|
before do
|
|
allow(Settings::Authentication).to receive(:recaptcha_secret_key).and_return(nil)
|
|
allow(Settings::Authentication).to receive(:recaptcha_site_key).and_return(nil)
|
|
end
|
|
|
|
it "does not show the recaptcha tag" do
|
|
get "/report-abuse"
|
|
expect(response.body).not_to include("recaptcha-tag-container")
|
|
end
|
|
|
|
it "creates a feedback message" do
|
|
expect do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end.to change(FeedbackMessage, :count).by(1)
|
|
end
|
|
end
|
|
|
|
context "when rate limit is reached" do
|
|
it "returns a 429" do
|
|
user = create(:user)
|
|
limiter = user.rate_limiter
|
|
allow(RateLimitChecker).to receive(:new) { limiter }
|
|
allow(limiter).to receive(:limit_by_action).and_return(true)
|
|
|
|
post "/feedback_messages.json", params: valid_abuse_report_params, headers: headers
|
|
expect(response.parsed_body["status"]).to eq("bad_request")
|
|
end
|
|
end
|
|
|
|
context "with valid params but recaptcha not passed" do
|
|
before { mock_recaptcha_config_enabled }
|
|
|
|
it "rerenders page" do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
expect(response.body).to include("Make sure the forms are filled")
|
|
end
|
|
|
|
it "doesn't queues a slack message" do
|
|
sidekiq_assert_no_enqueued_jobs(only: Slack::Messengers::Worker) do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when a user qualifies to bypass the recaptcha submits a report" do
|
|
let(:user) { create(:user, created_at: 3.months.ago) }
|
|
|
|
before do
|
|
mock_recaptcha_config_enabled
|
|
sign_in user
|
|
end
|
|
|
|
it "creates a feedback message reported by the user without recaptcha" do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
|
|
expect(FeedbackMessage.exists?(reporter_id: user.id)).to be(true)
|
|
end
|
|
|
|
it "queues a slack message to be sent" do
|
|
sidekiq_assert_enqueued_jobs(1, only: Slack::Messengers::Worker) do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end
|
|
|
|
it "sends an email when no cache" do
|
|
expect do
|
|
perform_enqueued_jobs do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end.to change { ActionMailer::Base.deliveries.count }.by(1)
|
|
end
|
|
|
|
it "queues a correct email when no cache" do
|
|
mailer_class = NotifyMailer
|
|
mailer = double
|
|
message_delivery = double
|
|
allow(mailer_class).to receive(:with).and_return(mailer)
|
|
allow(mailer).to receive(:feedback_response_email).and_return(message_delivery)
|
|
allow(message_delivery).to receive(:deliver_later)
|
|
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
|
|
expect(mailer_class).to have_received(:with).with(email_to: user.email)
|
|
expect(mailer).to have_received(:feedback_response_email)
|
|
expect(message_delivery).to have_received(:deliver_later)
|
|
end
|
|
|
|
it "doesn't queue an email when cache is set" do
|
|
allow(Rails.cache).to receive(:read).and_return(Time.current)
|
|
expect do
|
|
perform_enqueued_jobs do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end.not_to change { ActionMailer::Base.deliveries.count }
|
|
end
|
|
end
|
|
|
|
context "when a user doesn't qualify to bypass the recaptcha submits a report" do
|
|
let(:user) do
|
|
user = create(:user, created_at: 2.months.ago)
|
|
create(:reaction,
|
|
category: "vomit",
|
|
reactable: user,
|
|
user: create(:user, :trusted),
|
|
status: "confirmed")
|
|
user
|
|
end
|
|
|
|
before do
|
|
mock_recaptcha_config_enabled
|
|
sign_in user
|
|
end
|
|
|
|
it "fails to create a feedback message reported without recaptcha" do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
|
|
expect(FeedbackMessage.exists?(reporter_id: user.id)).to be(false)
|
|
end
|
|
|
|
it "doesn't queue a slack message to be sent" do
|
|
sidekiq_assert_enqueued_jobs(0, only: Slack::Messengers::Worker) do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when a moderator submits a report" do
|
|
let(:user) { create(:user, :tag_moderator) }
|
|
|
|
before do
|
|
mock_recaptcha_config_enabled
|
|
sign_in user
|
|
end
|
|
|
|
it "creates a feedback message reported by the moderator without recaptcha" do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
|
|
expect(FeedbackMessage.exists?(reporter_id: user.id)).to be(true)
|
|
end
|
|
|
|
it "queues a slack message to be sent" do
|
|
sidekiq_assert_enqueued_jobs(1, only: Slack::Messengers::Worker) do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when an anonymous user submits a report" do
|
|
before do
|
|
mock_recaptcha_config_enabled
|
|
mock_recaptcha_verification
|
|
end
|
|
|
|
it "does not add any user as the reporter" do
|
|
post "/feedback_messages", params: valid_abuse_report_params, headers: headers
|
|
|
|
expect(FeedbackMessage.last.reporter).to be(nil)
|
|
end
|
|
|
|
it "queues a slack message to be sent" do
|
|
sidekiq_assert_enqueued_jobs(1, only: Slack::Messengers::Worker) do
|
|
post feedback_messages_path, params: valid_abuse_report_params, headers: headers
|
|
end
|
|
end
|
|
|
|
it "redirects to the index page" do
|
|
post "/feedback_messages", params: valid_abuse_report_params, headers: headers
|
|
|
|
expect(response).to redirect_to(feedback_messages_path)
|
|
end
|
|
|
|
it "redirects and continues to the index page with the correct message" do
|
|
post "/feedback_messages", params: valid_abuse_report_params, headers: headers
|
|
|
|
follow_redirect!
|
|
|
|
expect(response.body).to include("Thank you for your report.")
|
|
end
|
|
end
|
|
end
|
|
end
|