| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  | require 'rails_helper' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe Api::V1::Accounts::CredentialsController do | 
					
						
							|  |  |  |   render_views | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } | 
					
						
							| 
									
										
										
										
											2018-07-05 11:31:35 -05:00
										 |  |  |   let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |   context 'with an oauth token' do | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       allow(controller).to receive(:doorkeeper_token) { token } | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |     describe 'GET #show' do | 
					
						
							| 
									
										
										
										
											2018-07-05 11:31:35 -05:00
										 |  |  |       let(:scopes) { 'read:accounts' } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  |       it 'returns http success' do | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |         get :show | 
					
						
							| 
									
										
										
										
											2018-04-21 14:35:07 -05:00
										 |  |  |         expect(response).to have_http_status(200) | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe 'PATCH #update' do | 
					
						
							| 
									
										
										
										
											2018-07-05 11:31:35 -05:00
										 |  |  |       let(:scopes) { 'write:accounts' } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |       describe 'with valid data' do | 
					
						
							|  |  |  |         before do | 
					
						
							|  |  |  |           allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           patch :update, params: { | 
					
						
							|  |  |  |             display_name: "Alice Isn't Dead", | 
					
						
							|  |  |  |             note: "Hi!\n\nToot toot!", | 
					
						
							|  |  |  |             avatar: fixture_file_upload('files/avatar.gif', 'image/gif'), | 
					
						
							|  |  |  |             header: fixture_file_upload('files/attachment.jpg', 'image/jpeg'), | 
					
						
							| 
									
										
										
										
											2018-04-08 06:43:10 -05:00
										 |  |  |             source: { | 
					
						
							|  |  |  |               privacy: 'unlisted', | 
					
						
							|  |  |  |               sensitive: true, | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |         it 'returns http success' do | 
					
						
							| 
									
										
										
										
											2018-04-21 14:35:07 -05:00
										 |  |  |           expect(response).to have_http_status(200) | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |         it 'updates account info' do | 
					
						
							|  |  |  |           user.account.reload | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(user.account.display_name).to eq("Alice Isn't Dead") | 
					
						
							|  |  |  |           expect(user.account.note).to eq("Hi!\n\nToot toot!") | 
					
						
							|  |  |  |           expect(user.account.avatar).to exist | 
					
						
							|  |  |  |           expect(user.account.header).to exist | 
					
						
							| 
									
										
										
										
											2018-04-08 06:43:10 -05:00
										 |  |  |           expect(user.setting_default_privacy).to eq('unlisted') | 
					
						
							|  |  |  |           expect(user.setting_default_sensitive).to eq(true) | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it 'queues up an account update distribution' do | 
					
						
							|  |  |  |           expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(user.account_id) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-08-12 17:44:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |       describe 'with invalid data' do | 
					
						
							|  |  |  |         before do | 
					
						
							| 
									
										
										
										
											2019-05-19 15:51:44 -05:00
										 |  |  |           patch :update, params: { note: 'This is too long. ' * 30 } | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it 'returns http unprocessable entity' do | 
					
						
							|  |  |  |           expect(response).to have_http_status(:unprocessable_entity) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-08-12 17:44:41 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |   context 'without an oauth token' do | 
					
						
							|  |  |  |     before do | 
					
						
							|  |  |  |       allow(controller).to receive(:doorkeeper_token) { nil } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     describe 'GET #show' do | 
					
						
							|  |  |  |       it 'returns http unauthorized' do | 
					
						
							|  |  |  |         get :show | 
					
						
							|  |  |  |         expect(response).to have_http_status(:unauthorized) | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-20 17:41:08 -05:00
										 |  |  |     describe 'PATCH #update' do | 
					
						
							|  |  |  |       it 'returns http unauthorized' do | 
					
						
							|  |  |  |         patch :update, params: { note: 'Foo' } | 
					
						
							|  |  |  |         expect(response).to have_http_status(:unauthorized) | 
					
						
							| 
									
										
										
										
											2017-05-31 14:36:24 -05:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |