logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

credentials_controller_spec.rb (2650B)


  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(:success)
  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(:success)
  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. patch :update, params: { note: 'This is too long. ' * 10 }
  50. end
  51. it 'returns http unprocessable entity' do
  52. expect(response).to have_http_status(:unprocessable_entity)
  53. end
  54. end
  55. end
  56. end
  57. context 'without an oauth token' do
  58. before do
  59. allow(controller).to receive(:doorkeeper_token) { nil }
  60. end
  61. describe 'GET #show' do
  62. it 'returns http unauthorized' do
  63. get :show
  64. expect(response).to have_http_status(:unauthorized)
  65. end
  66. end
  67. describe 'PATCH #update' do
  68. it 'returns http unauthorized' do
  69. patch :update, params: { note: 'Foo' }
  70. expect(response).to have_http_status(:unauthorized)
  71. end
  72. end
  73. end
  74. end