2023-09-21 02:25:16 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'credentials API' do
|
|
|
|
let(:user) { Fabricate(:user, account_attributes: { discoverable: false, locked: true, indexable: false }) }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:scopes) { 'read:accounts write:accounts' }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
|
|
|
|
|
|
|
describe 'GET /api/v1/accounts/verify_credentials' do
|
|
|
|
subject do
|
|
|
|
get '/api/v1/accounts/verify_credentials', headers: headers
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'write write:accounts'
|
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
it 'returns http success with expected content' do
|
2023-09-21 02:25:16 +10:00
|
|
|
subject
|
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
2023-09-21 02:25:16 +10:00
|
|
|
expect(body_as_json).to include({
|
|
|
|
source: hash_including({
|
|
|
|
discoverable: false,
|
|
|
|
indexable: false,
|
|
|
|
}),
|
|
|
|
locked: true,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
describe 'PATCH /api/v1/accounts/update_credentials' do
|
2023-09-21 02:25:16 +10:00
|
|
|
subject do
|
|
|
|
patch '/api/v1/accounts/update_credentials', headers: headers, params: params
|
|
|
|
end
|
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
before { allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async) }
|
|
|
|
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
avatar: fixture_file_upload('avatar.gif', 'image/gif'),
|
|
|
|
discoverable: true,
|
|
|
|
display_name: "Alice Isn't Dead",
|
|
|
|
header: fixture_file_upload('attachment.jpg', 'image/jpeg'),
|
|
|
|
indexable: true,
|
|
|
|
locked: false,
|
|
|
|
note: 'Hello!',
|
|
|
|
source: {
|
|
|
|
privacy: 'unlisted',
|
|
|
|
sensitive: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2023-09-21 02:25:16 +10:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:accounts'
|
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
describe 'with empty source list' do
|
|
|
|
let(:params) { { display_name: "I'm a cat", source: {} } }
|
2023-09-21 02:25:16 +10:00
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
it 'returns http success' do
|
|
|
|
subject
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
end
|
2023-09-21 02:25:16 +10:00
|
|
|
end
|
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
describe 'with invalid data' do
|
|
|
|
let(:params) { { note: 'This is too long. ' * 30 } }
|
|
|
|
|
|
|
|
it 'returns http unprocessable entity' do
|
|
|
|
subject
|
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success with updated JSON attributes' do
|
2023-09-21 02:25:16 +10:00
|
|
|
subject
|
|
|
|
|
2024-03-13 20:22:43 +11:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
|
2023-09-21 02:25:16 +10:00
|
|
|
expect(body_as_json).to include({
|
|
|
|
source: hash_including({
|
|
|
|
discoverable: true,
|
|
|
|
indexable: true,
|
|
|
|
}),
|
|
|
|
locked: false,
|
|
|
|
})
|
2024-03-13 20:22:43 +11:00
|
|
|
|
|
|
|
expect(ActivityPub::UpdateDistributionWorker)
|
|
|
|
.to have_received(:perform_async).with(user.account_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_account_updates
|
|
|
|
expect(user.account.reload)
|
|
|
|
.to have_attributes(
|
|
|
|
display_name: eq("Alice Isn't Dead"),
|
|
|
|
note: 'Hello!',
|
|
|
|
avatar: exist,
|
|
|
|
header: exist
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_user_updates
|
|
|
|
expect(user.reload)
|
|
|
|
.to have_attributes(
|
|
|
|
setting_default_privacy: eq('unlisted'),
|
|
|
|
setting_default_sensitive: be(true)
|
|
|
|
)
|
2023-09-21 02:25:16 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|