profiles_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Deleting profile images' do
  4. let(:account) do
  5. Fabricate(
  6. :account,
  7. avatar: fixture_file_upload('avatar.gif', 'image/gif'),
  8. header: fixture_file_upload('attachment.jpg', 'image/jpeg')
  9. )
  10. end
  11. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: account.user.id, scopes: scopes) }
  12. let(:scopes) { 'write:accounts' }
  13. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  14. describe 'DELETE /api/v1/profile' do
  15. before do
  16. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  17. end
  18. context 'when deleting an avatar' do
  19. context 'with wrong scope' do
  20. before do
  21. delete '/api/v1/profile/avatar', headers: headers
  22. end
  23. it_behaves_like 'forbidden for wrong scope', 'read'
  24. end
  25. it 'returns http success and deletes the avatar, preserves the header, queues up distribution' do
  26. delete '/api/v1/profile/avatar', headers: headers
  27. expect(response).to have_http_status(200)
  28. expect(response.content_type)
  29. .to start_with('application/json')
  30. account.reload
  31. expect(account.avatar).to_not exist
  32. expect(account.header).to exist
  33. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
  34. end
  35. end
  36. context 'when deleting a header' do
  37. context 'with wrong scope' do
  38. before do
  39. delete '/api/v1/profile/header', headers: headers
  40. end
  41. it_behaves_like 'forbidden for wrong scope', 'read'
  42. end
  43. it 'returns http success, preserves the avatar, deletes the header, queues up distribution' do
  44. delete '/api/v1/profile/header', headers: headers
  45. expect(response).to have_http_status(200)
  46. expect(response.content_type)
  47. .to start_with('application/json')
  48. account.reload
  49. expect(account.avatar).to exist
  50. expect(account.header).to_not exist
  51. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
  52. end
  53. end
  54. end
  55. end