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.

55 lines
1.5 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) { double acceptable?: true, resource_owner_id: user.id }
  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. patch :update, params: {
  19. display_name: "Alice Isn't Dead",
  20. note: "Hi!\n\nToot toot!",
  21. avatar: fixture_file_upload('files/avatar.gif', 'image/gif'),
  22. header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'),
  23. }
  24. end
  25. it 'returns http success' do
  26. expect(response).to have_http_status(:success)
  27. end
  28. it 'updates account info' do
  29. user.account.reload
  30. expect(user.account.display_name).to eq("Alice Isn't Dead")
  31. expect(user.account.note).to eq("Hi!\n\nToot toot!")
  32. expect(user.account.avatar).to exist
  33. expect(user.account.header).to exist
  34. end
  35. end
  36. describe 'with invalid data' do
  37. before do
  38. patch :update, params: { note: 'This is too long. ' * 10 }
  39. end
  40. it 'returns http unprocessable entity' do
  41. expect(response).to have_http_status(:unprocessable_entity)
  42. end
  43. end
  44. end
  45. end