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.

61 lines
1.8 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: 'write') }
  6. before do
  7. allow(controller).to receive(:doorkeeper_token) { token }
  8. end
  9. describe 'GET #show' do
  10. it 'returns http success' do
  11. get :show
  12. expect(response).to have_http_status(:success)
  13. end
  14. end
  15. describe 'PATCH #update' do
  16. describe 'with valid data' do
  17. before do
  18. allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
  19. patch :update, params: {
  20. display_name: "Alice Isn't Dead",
  21. note: "Hi!\n\nToot toot!",
  22. avatar: fixture_file_upload('files/avatar.gif', 'image/gif'),
  23. header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'),
  24. }
  25. end
  26. it 'returns http success' do
  27. expect(response).to have_http_status(:success)
  28. end
  29. it 'updates account info' do
  30. user.account.reload
  31. expect(user.account.display_name).to eq("Alice Isn't Dead")
  32. expect(user.account.note).to eq("Hi!\n\nToot toot!")
  33. expect(user.account.avatar).to exist
  34. expect(user.account.header).to exist
  35. end
  36. it 'queues up an account update distribution' do
  37. expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(user.account_id)
  38. end
  39. end
  40. describe 'with invalid data' do
  41. before do
  42. patch :update, params: { note: 'This is too long. ' * 10 }
  43. end
  44. it 'returns http unprocessable entity' do
  45. expect(response).to have_http_status(:unprocessable_entity)
  46. end
  47. end
  48. end
  49. end