You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.7 KiB

  1. require 'rails_helper'
  2. describe Api::V1::Accounts::CredentialsController do
  3. render_views
  4. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
  6. context 'with an oauth token' do
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #show' do
  11. it 'returns http success' do
  12. get :show
  13. expect(response).to have_http_status(200)
  14. end
  15. end
  16. describe 'PATCH #update' do
  17. describe 'with valid data' do
  18. before do
  19. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  20. patch :update, params: {
  21. display_name: "Alice Isn't Dead",
  22. note: "Hi!\n\nToot toot!",
  23. avatar: fixture_file_upload('files/avatar.gif', 'image/gif'),
  24. header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'),
  25. source: {
  26. privacy: 'unlisted',
  27. sensitive: true,
  28. }
  29. }
  30. end
  31. it 'returns http success' do
  32. expect(response).to have_http_status(200)
  33. end
  34. it 'updates account info' do
  35. user.account.reload
  36. expect(user.account.display_name).to eq("Alice Isn't Dead")
  37. expect(user.account.note).to eq("Hi!\n\nToot toot!")
  38. expect(user.account.avatar).to exist
  39. expect(user.account.header).to exist
  40. expect(user.setting_default_privacy).to eq('unlisted')
  41. expect(user.setting_default_sensitive).to eq(true)
  42. end
  43. it 'queues up an account update distribution' do
  44. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(user.account_id)
  45. end
  46. end
  47. describe 'with invalid data' do
  48. before do
  49. note = 'This is too long. '
  50. note = note + 'a' * (Account::MAX_NOTE_LENGTH - note.length + 1)
  51. patch :update, params: { note: note }
  52. end
  53. it 'returns http unprocessable entity' do
  54. expect(response).to have_http_status(:unprocessable_entity)
  55. end
  56. end
  57. end
  58. end
  59. context 'without an oauth token' do
  60. before do
  61. allow(controller).to receive(:doorkeeper_token) { nil }
  62. end
  63. describe 'GET #show' do
  64. it 'returns http unauthorized' do
  65. get :show
  66. expect(response).to have_http_status(:unauthorized)
  67. end
  68. end
  69. describe 'PATCH #update' do
  70. it 'returns http unauthorized' do
  71. patch :update, params: { note: 'Foo' }
  72. expect(response).to have_http_status(:unauthorized)
  73. end
  74. end
  75. end
  76. end