2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-14 21:27:53 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 05:49:53 +02:00
|
|
|
RSpec.describe Disputes::AppealsController do
|
2022-02-14 21:27:53 +01:00
|
|
|
render_views
|
|
|
|
|
|
|
|
before { sign_in current_user, scope: :user }
|
|
|
|
|
2022-07-05 02:41:40 +02:00
|
|
|
let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
2022-02-14 21:27:53 +01:00
|
|
|
|
|
|
|
describe '#create' do
|
2024-02-16 14:01:15 +01:00
|
|
|
subject { post :create, params: params }
|
|
|
|
|
2024-01-12 10:21:00 +01:00
|
|
|
context 'with valid params' do
|
|
|
|
let(:current_user) { Fabricate(:user) }
|
|
|
|
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
|
2024-02-16 14:01:15 +01:00
|
|
|
let(:params) { { strike_id: strike.id, appeal: { text: 'Foo' } } }
|
2022-02-14 21:27:53 +01:00
|
|
|
|
2024-02-16 14:01:15 +01:00
|
|
|
it 'notifies staff about new appeal and redirects back to strike page', :sidekiq_inline do
|
2024-02-19 16:57:47 +01:00
|
|
|
emails = capture_emails { subject }
|
|
|
|
|
|
|
|
expect(emails.size)
|
|
|
|
.to eq(1)
|
|
|
|
expect(emails.first)
|
|
|
|
.to have_attributes(
|
|
|
|
to: contain_exactly(admin.email),
|
|
|
|
subject: eq(I18n.t('admin_mailer.new_appeal.subject', username: current_user.account.acct, instance: Rails.configuration.x.local_domain))
|
|
|
|
)
|
2024-01-12 10:21:00 +01:00
|
|
|
expect(response).to redirect_to(disputes_strike_path(strike.id))
|
|
|
|
end
|
2022-02-14 21:27:53 +01:00
|
|
|
end
|
|
|
|
|
2024-01-12 10:21:00 +01:00
|
|
|
context 'with invalid params' do
|
|
|
|
let(:current_user) { Fabricate(:user) }
|
|
|
|
let(:strike) { Fabricate(:account_warning, target_account: current_user.account) }
|
2024-02-16 14:01:15 +01:00
|
|
|
let(:params) { { strike_id: strike.id, appeal: { text: '' } } }
|
2024-01-12 10:21:00 +01:00
|
|
|
|
2024-02-16 14:01:15 +01:00
|
|
|
it 'does not send email and renders strike show page', :sidekiq_inline do
|
2024-02-19 16:57:47 +01:00
|
|
|
emails = capture_emails { subject }
|
2024-01-12 10:21:00 +01:00
|
|
|
|
2024-02-19 16:57:47 +01:00
|
|
|
expect(emails).to be_empty
|
2024-01-12 10:21:00 +01:00
|
|
|
expect(response).to render_template('disputes/strikes/show')
|
|
|
|
end
|
2022-02-14 21:27:53 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|