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.

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