2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-31 21:36:24 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Api::V1::Accounts::CredentialsController do
|
|
|
|
render_views
|
|
|
|
|
2022-01-28 00:46:42 +01:00
|
|
|
let(:user) { Fabricate(:user) }
|
2018-07-05 18:31:35 +02:00
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
2017-05-31 21:36:24 +02:00
|
|
|
|
2017-08-21 00:41:08 +02:00
|
|
|
context 'with an oauth token' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:doorkeeper_token) { token }
|
2017-05-31 21:36:24 +02:00
|
|
|
end
|
|
|
|
|
2017-08-21 00:41:08 +02:00
|
|
|
describe 'GET #show' do
|
2018-07-05 18:31:35 +02:00
|
|
|
let(:scopes) { 'read:accounts' }
|
|
|
|
|
2017-05-31 21:36:24 +02:00
|
|
|
it 'returns http success' do
|
2017-08-21 00:41:08 +02:00
|
|
|
get :show
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2017-05-31 21:36:24 +02:00
|
|
|
end
|
2017-08-21 00:41:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH #update' do
|
2018-07-05 18:31:35 +02:00
|
|
|
let(:scopes) { 'write:accounts' }
|
|
|
|
|
2017-08-21 00:41:08 +02: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!",
|
2021-03-24 10:44:31 +01:00
|
|
|
avatar: fixture_file_upload('avatar.gif', 'image/gif'),
|
|
|
|
header: fixture_file_upload('attachment.jpg', 'image/jpeg'),
|
2018-04-08 13:43:10 +02:00
|
|
|
source: {
|
|
|
|
privacy: 'unlisted',
|
|
|
|
sensitive: true,
|
2023-02-18 15:33:41 +01:00
|
|
|
},
|
2017-08-21 00:41:08 +02:00
|
|
|
}
|
|
|
|
end
|
2017-05-31 21:36:24 +02:00
|
|
|
|
2023-10-13 14:42:09 +02:00
|
|
|
it 'updates account info', :aggregate_failures do
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2017-05-31 21:36:24 +02:00
|
|
|
|
2023-03-30 14:44:00 +02:00
|
|
|
user.reload
|
2017-08-21 00:41:08 +02:00
|
|
|
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 13:43:10 +02:00
|
|
|
expect(user.setting_default_privacy).to eq('unlisted')
|
2023-02-20 06:14:50 +01:00
|
|
|
expect(user.setting_default_sensitive).to be(true)
|
2017-08-21 00:41:08 +02:00
|
|
|
|
|
|
|
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(user.account_id)
|
|
|
|
end
|
2017-05-31 21:36:24 +02:00
|
|
|
end
|
2017-08-13 00:44:41 +02:00
|
|
|
|
2019-11-16 19:02:09 +01:00
|
|
|
describe 'with empty source list' do
|
|
|
|
before do
|
|
|
|
patch :update, params: {
|
|
|
|
display_name: "I'm a cat",
|
|
|
|
source: {},
|
|
|
|
}, as: :json
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2023-02-17 22:56:20 +01:00
|
|
|
end
|
2019-11-16 19:02:09 +01:00
|
|
|
|
2017-08-21 00:41:08 +02:00
|
|
|
describe 'with invalid data' do
|
|
|
|
before do
|
2019-05-19 22:51:44 +02:00
|
|
|
patch :update, params: { note: 'This is too long. ' * 30 }
|
2017-08-21 00:41:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http unprocessable entity' do
|
2023-02-20 03:16:40 +01:00
|
|
|
expect(response).to have_http_status(422)
|
2017-08-21 00:41:08 +02:00
|
|
|
end
|
2017-08-13 00:44:41 +02:00
|
|
|
end
|
2017-05-31 21:36:24 +02:00
|
|
|
end
|
2017-08-21 00:41:08 +02:00
|
|
|
end
|
2017-05-31 21:36:24 +02:00
|
|
|
|
2017-08-21 00:41:08 +02:00
|
|
|
context 'without an oauth token' do
|
|
|
|
before do
|
2023-02-20 02:32:10 +01:00
|
|
|
allow(controller).to receive(:doorkeeper_token).and_return(nil)
|
2017-08-21 00:41:08 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
it 'returns http unauthorized' do
|
|
|
|
get :show
|
2023-02-20 03:16:40 +01:00
|
|
|
expect(response).to have_http_status(401)
|
2017-05-31 21:36:24 +02:00
|
|
|
end
|
2017-08-21 00:41:08 +02:00
|
|
|
end
|
2017-05-31 21:36:24 +02:00
|
|
|
|
2017-08-21 00:41:08 +02:00
|
|
|
describe 'PATCH #update' do
|
|
|
|
it 'returns http unauthorized' do
|
|
|
|
patch :update, params: { note: 'Foo' }
|
2023-02-20 03:16:40 +01:00
|
|
|
expect(response).to have_http_status(401)
|
2017-05-31 21:36:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|