feat: Ability to update avatars from super admin (#7264)
- Ability to update user avatars from super admin - Ability to update bot avatars from super admin fixes: #7060
This commit is contained in:
@@ -22,4 +22,25 @@ RSpec.describe 'Super Admin agent-bots API', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /super_admin/agent_bots/:id/destroy_avatar' do
|
||||
let!(:agent_bot) { create(:agent_bot, :with_avatar) }
|
||||
|
||||
context 'when it is an unauthenticated super admin' do
|
||||
it 'returns unauthorized' do
|
||||
delete "/super_admin/agent_bots/#{agent_bot.id}/avatar", params: { attachment_id: agent_bot.avatar.id }
|
||||
expect(response).to have_http_status(:redirect)
|
||||
expect(agent_bot.reload.avatar).to be_attached
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated super admin' do
|
||||
it 'destroys the avatar' do
|
||||
sign_in(super_admin, scope: :super_admin)
|
||||
delete "/super_admin/agent_bots/#{agent_bot.id}/avatar", params: { attachment_id: agent_bot.avatar.id }
|
||||
expect(response).to have_http_status(:redirect)
|
||||
expect(agent_bot.reload.avatar).not_to be_attached
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,4 +45,25 @@ RSpec.describe 'Super Admin Users API', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /super_admin/users/:id/avatar' do
|
||||
let!(:user) { create(:user, :with_avatar) }
|
||||
|
||||
context 'when it is an unauthenticated super admin' do
|
||||
it 'returns unauthorized' do
|
||||
delete "/super_admin/users/#{user.id}/avatar", params: { attachment_id: user.avatar.id }
|
||||
expect(response).to have_http_status(:redirect)
|
||||
expect(user.reload.avatar).to be_attached
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated super admin' do
|
||||
it 'destroys the avatar' do
|
||||
sign_in(super_admin, scope: :super_admin)
|
||||
delete "/super_admin/users/#{user.id}/avatar", params: { attachment_id: user.avatar.id }
|
||||
expect(response).to have_http_status(:redirect)
|
||||
expect(user.reload.avatar).not_to be_attached
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,5 +9,9 @@ FactoryBot.define do
|
||||
trait :skip_validate do
|
||||
to_create { |instance| instance.save(validate: false) }
|
||||
end
|
||||
|
||||
trait :with_avatar do
|
||||
avatar { fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ FactoryBot.define do
|
||||
end
|
||||
|
||||
trait :with_avatar do
|
||||
avatar { Rack::Test::UploadedFile.new('spec/assets/avatar.png', 'image/png') }
|
||||
avatar { fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png') }
|
||||
end
|
||||
|
||||
trait :administrator do
|
||||
|
||||
Reference in New Issue
Block a user