account_controller_concern_spec.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe AccountControllerConcern do
  4. controller(ApplicationController) do
  5. include AccountControllerConcern
  6. def success
  7. head 200
  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 'assigns @account, returns success, and sets link headers' do
  45. get 'success', params: { account_username: account.username }
  46. expect(assigns(:account)).to eq account
  47. expect(response).to have_http_status(200)
  48. expect(response.headers['Link'].to_s).to eq(expected_link_headers)
  49. end
  50. def expected_link_headers
  51. [
  52. '<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json"',
  53. '<https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"',
  54. ].join(', ')
  55. end
  56. end
  57. end