2023-02-22 09:55:31 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-07 20:42:33 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe '/api/v1/accounts' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:scopes) { '' }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
2016-09-08 07:33:07 +09:00
|
|
|
|
2024-05-29 18:19:17 +09:00
|
|
|
describe 'GET /api/v1/accounts?id[]=:id' do
|
2024-05-07 00:19:15 +09:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:other_account) { Fabricate(:account) }
|
|
|
|
let(:scopes) { 'read:accounts' }
|
|
|
|
|
|
|
|
it 'returns expected response' do
|
2024-05-29 18:19:17 +09:00
|
|
|
get '/api/v1/accounts', headers: headers, params: { id: [account.id, other_account.id, 123_123] }
|
2024-05-07 00:19:15 +09:00
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(body_as_json).to contain_exactly(
|
|
|
|
hash_including(id: account.id.to_s),
|
|
|
|
hash_including(id: other_account.id.to_s)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'GET /api/v1/accounts/:id' do
|
|
|
|
context 'when logged out' do
|
|
|
|
let(:account) { Fabricate(:account) }
|
2016-03-20 21:03:06 +09:00
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
it 'returns account entity as 200 OK', :aggregate_failures do
|
|
|
|
get "/api/v1/accounts/#{account.id}"
|
2016-03-20 21:03:06 +09:00
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(body_as_json[:id]).to eq(account.id.to_s)
|
|
|
|
end
|
|
|
|
end
|
2018-12-25 03:12:38 +09:00
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
context 'when the account does not exist' do
|
|
|
|
it 'returns http not found' do
|
|
|
|
get '/api/v1/accounts/1'
|
|
|
|
|
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
expect(body_as_json[:error]).to eq('Record not found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when logged in' do
|
|
|
|
subject do
|
|
|
|
get "/api/v1/accounts/#{account.id}", headers: headers
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:scopes) { 'read:accounts' }
|
|
|
|
|
|
|
|
it 'returns account entity as 200 OK', :aggregate_failures do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(body_as_json[:id]).to eq(account.id.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
|
2018-12-25 03:12:38 +09:00
|
|
|
end
|
2023-11-17 20:34:49 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST /api/v1/accounts' do
|
|
|
|
subject do
|
|
|
|
post '/api/v1/accounts', headers: headers, params: { username: 'test', password: '12345678', email: 'hello@world.tld', agreement: agreement }
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:client_app) { Fabricate(:application) }
|
|
|
|
let(:token) { Doorkeeper::AccessToken.find_or_create_for(application: client_app, resource_owner: nil, scopes: 'read write', use_refresh_token: false) }
|
|
|
|
let(:agreement) { nil }
|
2018-12-25 03:12:38 +09:00
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
context 'when given truthy agreement' do
|
2018-12-25 03:12:38 +09:00
|
|
|
let(:agreement) { 'true' }
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'creates a user', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-12-25 03:12:38 +09:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(body_as_json[:access_token]).to_not be_blank
|
|
|
|
|
|
|
|
user = User.find_by(email: 'hello@world.tld')
|
|
|
|
expect(user).to_not be_nil
|
2023-11-17 20:34:49 +09:00
|
|
|
expect(user.created_by_application_id).to eq client_app.id
|
2018-12-25 03:12:38 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
context 'when given no agreement' do
|
2018-12-25 03:12:38 +09:00
|
|
|
it 'returns http unprocessable entity' do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-12-25 03:12:38 +09:00
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/follow' do
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'write:follows' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob', locked: locked) }
|
2016-03-20 21:03:06 +09:00
|
|
|
|
2023-06-06 22:51:42 +09:00
|
|
|
context 'when posting to an other account' do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/follow", headers: headers
|
2020-09-19 00:26:45 +09:00
|
|
|
end
|
2016-03-20 21:03:06 +09:00
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
context 'with unlocked account' do
|
|
|
|
let(:locked) { false }
|
2017-09-12 06:50:37 +09:00
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'creates a following relation between user and target user', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-20 21:03:06 +09:00
|
|
|
|
2024-09-03 17:03:08 +09:00
|
|
|
expect(body_as_json)
|
|
|
|
.to include(
|
|
|
|
following: true,
|
|
|
|
requested: false
|
|
|
|
)
|
2020-09-19 00:26:45 +09:00
|
|
|
|
|
|
|
expect(user.account.following?(other_account)).to be true
|
|
|
|
end
|
2017-09-12 06:50:37 +09:00
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
2017-09-12 06:50:37 +09:00
|
|
|
end
|
2018-07-06 01:31:35 +09:00
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
context 'with locked account' do
|
|
|
|
let(:locked) { true }
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'creates a follow request relation between user and target user', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
|
2024-09-03 17:03:08 +09:00
|
|
|
expect(body_as_json)
|
|
|
|
.to include(
|
|
|
|
following: false,
|
|
|
|
requested: true
|
|
|
|
)
|
2020-09-19 00:26:45 +09:00
|
|
|
|
|
|
|
expect(user.account.requested?(other_account)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
|
|
|
end
|
2017-09-06 00:48:13 +09:00
|
|
|
end
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
context 'when modifying follow options' do
|
2020-09-19 00:26:45 +09:00
|
|
|
let(:locked) { false }
|
2017-09-12 06:50:37 +09:00
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
before do
|
|
|
|
user.account.follow!(other_account, reblogs: false, notify: false)
|
2017-09-12 06:50:37 +09:00
|
|
|
end
|
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
it 'changes reblogs option' do
|
2023-11-17 20:34:49 +09:00
|
|
|
post "/api/v1/accounts/#{other_account.id}/follow", headers: headers, params: { reblogs: true }
|
2017-09-12 06:50:37 +09:00
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
expect(body_as_json).to include({
|
|
|
|
following: true,
|
|
|
|
showing_reblogs: true,
|
|
|
|
notifying: false,
|
|
|
|
})
|
2017-09-12 06:50:37 +09:00
|
|
|
end
|
|
|
|
|
2020-09-19 00:26:45 +09:00
|
|
|
it 'changes notify option' do
|
2023-11-17 20:34:49 +09:00
|
|
|
post "/api/v1/accounts/#{other_account.id}/follow", headers: headers, params: { notify: true }
|
2020-09-19 00:26:45 +09:00
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
expect(body_as_json).to include({
|
|
|
|
following: true,
|
|
|
|
showing_reblogs: false,
|
|
|
|
notifying: true,
|
|
|
|
})
|
2020-09-19 00:26:45 +09:00
|
|
|
end
|
2022-09-21 06:51:21 +09:00
|
|
|
|
|
|
|
it 'changes languages option' do
|
2023-11-17 20:34:49 +09:00
|
|
|
post "/api/v1/accounts/#{other_account.id}/follow", headers: headers, params: { languages: %w(en es) }
|
|
|
|
|
|
|
|
expect(body_as_json).to include({
|
|
|
|
following: true,
|
|
|
|
showing_reblogs: false,
|
|
|
|
notifying: false,
|
|
|
|
languages: match_array(%w(en es)),
|
|
|
|
})
|
2022-09-21 06:51:21 +09:00
|
|
|
end
|
2016-03-20 21:03:06 +09:00
|
|
|
end
|
2016-03-19 20:13:47 +09:00
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/unfollow' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/unfollow", headers: headers
|
|
|
|
end
|
|
|
|
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'write:follows' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2016-03-20 21:03:06 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.account.follow!(other_account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'removes the following relation between user and target user', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2016-03-20 21:03:06 +09:00
|
|
|
expect(user.account.following?(other_account)).to be false
|
|
|
|
end
|
2018-07-06 01:31:35 +09:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
2016-03-19 20:13:47 +09:00
|
|
|
end
|
2016-09-22 05:07:18 +09:00
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/remove_from_followers' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/remove_from_followers", headers: headers
|
|
|
|
end
|
|
|
|
|
2021-10-18 19:02:35 +09:00
|
|
|
let(:scopes) { 'write:follows' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2021-10-18 19:02:35 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
other_account.follow!(user.account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'removes the followed relation between user and target user', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2021-10-18 19:02:35 +09:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(user.account.followed_by?(other_account)).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/block' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/block", headers: headers
|
|
|
|
end
|
|
|
|
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'write:blocks' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2016-10-04 01:17:06 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.account.follow!(other_account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'creates a blocking relation', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2016-10-04 01:17:06 +09:00
|
|
|
expect(user.account.following?(other_account)).to be false
|
|
|
|
expect(user.account.blocking?(other_account)).to be true
|
|
|
|
end
|
2018-07-06 01:31:35 +09:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
2016-10-04 01:17:06 +09:00
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/unblock' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/unblock", headers: headers
|
|
|
|
end
|
|
|
|
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'write:blocks' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2016-10-04 01:17:06 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.account.block!(other_account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'removes the blocking relation between user and target user', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2016-10-04 01:17:06 +09:00
|
|
|
expect(user.account.blocking?(other_account)).to be false
|
|
|
|
end
|
2018-07-06 01:31:35 +09:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
2016-10-04 01:17:06 +09:00
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/mute' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/mute", headers: headers
|
|
|
|
end
|
|
|
|
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'write:mutes' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2017-02-06 10:51:56 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.account.follow!(other_account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'mutes notifications', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2017-02-06 10:51:56 +09:00
|
|
|
expect(user.account.following?(other_account)).to be true
|
|
|
|
expect(user.account.muting?(other_account)).to be true
|
2017-11-15 11:56:41 +09:00
|
|
|
expect(user.account.muting_notifications?(other_account)).to be true
|
|
|
|
end
|
2018-07-06 01:31:35 +09:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
2017-11-15 11:56:41 +09:00
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/mute with notifications set to false' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/mute", headers: headers, params: { notifications: false }
|
|
|
|
end
|
|
|
|
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'write:mutes' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2017-11-15 11:56:41 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.account.follow!(other_account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'does not mute notifications', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2017-11-15 11:56:41 +09:00
|
|
|
expect(user.account.following?(other_account)).to be true
|
|
|
|
expect(user.account.muting?(other_account)).to be true
|
|
|
|
expect(user.account.muting_notifications?(other_account)).to be false
|
|
|
|
end
|
2018-07-06 01:31:35 +09:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
2017-02-06 10:51:56 +09:00
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/mute with nonzero duration set' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/mute", headers: headers, params: { duration: 300 }
|
|
|
|
end
|
|
|
|
|
2021-01-10 20:47:21 +09:00
|
|
|
let(:scopes) { 'write:mutes' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2021-01-10 20:47:21 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.account.follow!(other_account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'mutes notifications', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2021-01-10 20:47:21 +09:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
expect(user.account.following?(other_account)).to be true
|
|
|
|
expect(user.account.muting?(other_account)).to be true
|
|
|
|
expect(user.account.muting_notifications?(other_account)).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
|
|
|
end
|
|
|
|
|
2023-11-17 20:34:49 +09:00
|
|
|
describe 'POST /api/v1/accounts/:id/unmute' do
|
|
|
|
subject do
|
|
|
|
post "/api/v1/accounts/#{other_account.id}/unmute", headers: headers
|
|
|
|
end
|
|
|
|
|
2018-07-06 01:31:35 +09:00
|
|
|
let(:scopes) { 'write:mutes' }
|
2022-01-28 08:46:42 +09:00
|
|
|
let(:other_account) { Fabricate(:account, username: 'bob') }
|
2017-02-06 10:51:56 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
user.account.mute!(other_account)
|
|
|
|
end
|
|
|
|
|
2023-10-13 21:42:09 +09:00
|
|
|
it 'removes the muting relation between user and target user', :aggregate_failures do
|
2023-11-17 20:34:49 +09:00
|
|
|
subject
|
|
|
|
|
2018-04-22 04:35:07 +09:00
|
|
|
expect(response).to have_http_status(200)
|
2017-02-06 10:51:56 +09:00
|
|
|
expect(user.account.muting?(other_account)).to be false
|
|
|
|
end
|
2018-07-06 01:31:35 +09:00
|
|
|
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read:accounts'
|
2017-02-06 10:51:56 +09:00
|
|
|
end
|
2016-03-07 20:42:33 +09:00
|
|
|
end
|