account_controller_concern_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountControllerConcern do
  4. controller(ApplicationController) do
  5. include AccountControllerConcern
  6. def success
  7. render plain: @account.username # rubocop:disable RSpec/InstanceVariable
  8. end
  9. end
  10. before do
  11. routes.draw { get 'success' => 'anonymous#success' }
  12. end
  13. context 'when account is unconfirmed' do
  14. it 'returns http not found' do
  15. account = Fabricate(:user, confirmed_at: nil).account
  16. get 'success', params: { account_username: account.username }
  17. expect(response).to have_http_status(404)
  18. end
  19. end
  20. context 'when account is not approved' do
  21. it 'returns http not found' do
  22. Setting.registrations_mode = 'approved'
  23. account = Fabricate(:user, approved: false).account
  24. get 'success', params: { account_username: account.username }
  25. expect(response).to have_http_status(404)
  26. end
  27. end
  28. context 'when account is suspended' do
  29. it 'returns http gone' do
  30. account = Fabricate(:account, suspended: true)
  31. get 'success', params: { account_username: account.username }
  32. expect(response).to have_http_status(410)
  33. end
  34. end
  35. context 'when account is deleted by owner' do
  36. it 'returns http gone' do
  37. account = Fabricate(:account, suspended: true, user: nil)
  38. get 'success', params: { account_username: account.username }
  39. expect(response).to have_http_status(410)
  40. end
  41. end
  42. context 'when account is not suspended' do
  43. let(:account) { Fabricate(:account, username: 'username') }
  44. it 'Prepares the account, returns success, and sets link headers' do
  45. get 'success', params: { account_username: account.username }
  46. expect(response)
  47. .to have_http_status(200)
  48. .and have_http_link_header('http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io').for(rel: 'lrdd', type: 'application/jrd+json')
  49. .and have_http_link_header('https://cb6e6126.ngrok.io/users/username').for(rel: 'alternate', type: 'application/activity+json')
  50. expect(response.body)
  51. .to include(account.username)
  52. end
  53. end
  54. end