Merge commit '4a7395d989e40c3bd4ef18173aa5ea850c8ddcdd' into glitch-soc/merge-upstream

Conflicts:
- `README.md`:
  Upstream modified its README, we have a completely different one.
  Kept our README file.
This commit is contained in:
Claire
2023-12-21 18:17:17 +01:00
71 changed files with 1411 additions and 1149 deletions

View File

@@ -0,0 +1,31 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Accounts Familiar Followers API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:follows' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account) }
describe 'GET /api/v1/accounts/familiar_followers' do
it 'returns http success' do
get '/api/v1/accounts/familiar_followers', params: { account_id: account.id, limit: 2 }, headers: headers
expect(response).to have_http_status(200)
end
context 'when there are duplicate account IDs in the params' do
let(:account_a) { Fabricate(:account) }
let(:account_b) { Fabricate(:account) }
it 'removes duplicate account IDs from params' do
account_ids = [account_a, account_b, account_b, account_a, account_a].map { |a| a.id.to_s }
get '/api/v1/accounts/familiar_followers', params: { id: account_ids }, headers: headers
expect(body_as_json.pluck(:id)).to contain_exactly(account_a.id.to_s, account_b.id.to_s)
end
end
end
end

View File

@@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Accounts Identity Proofs API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:accounts' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account) }
describe 'GET /api/v1/accounts/identity_proofs' do
it 'returns http success' do
get "/api/v1/accounts/#{account.id}/identity_proofs", params: { limit: 2 }, headers: headers
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Accounts Lists API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:lists' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account) }
let(:list) { Fabricate(:list, account: user.account) }
before do
user.account.follow!(account)
list.accounts << account
end
describe 'GET /api/v1/accounts/lists' do
it 'returns http success' do
get "/api/v1/accounts/#{account.id}/lists", headers: headers
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Accounts Lookup API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:accounts' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account) }
describe 'GET /api/v1/accounts/lookup' do
it 'returns http success' do
get '/api/v1/accounts/lookup', params: { account_id: account.id, acct: account.acct }, headers: headers
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,40 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Accounts Notes API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'write:accounts' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account) }
let(:comment) { 'foo' }
describe 'POST /api/v1/accounts/:account_id/note' do
subject do
post "/api/v1/accounts/#{account.id}/note", params: { comment: comment }, headers: headers
end
context 'when account note has reasonable length', :aggregate_failures do
let(:comment) { 'foo' }
it 'updates account note' do
subject
expect(response).to have_http_status(200)
expect(AccountNote.find_by(account_id: user.account.id, target_account_id: account.id).comment).to eq comment
end
end
context 'when account note exceeds allowed length', :aggregate_failures do
let(:comment) { 'a' * 2_001 }
it 'does not create account note' do
subject
expect(response).to have_http_status(422)
expect(AccountNote.where(account_id: user.account.id, target_account_id: account.id)).to_not exist
end
end
end
end

View File

@@ -0,0 +1,41 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Accounts Pins API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'write:accounts' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:kevin) { Fabricate(:user) }
before do
kevin.account.followers << user.account
end
describe 'POST /api/v1/accounts/:account_id/pin' do
subject { post "/api/v1/accounts/#{kevin.account.id}/pin", headers: headers }
it 'creates account_pin', :aggregate_failures do
expect do
subject
end.to change { AccountPin.where(account: user.account, target_account: kevin.account).count }.by(1)
expect(response).to have_http_status(200)
end
end
describe 'POST /api/v1/accounts/:account_id/unpin' do
subject { post "/api/v1/accounts/#{kevin.account.id}/unpin", headers: headers }
before do
Fabricate(:account_pin, account: user.account, target_account: kevin.account)
end
it 'destroys account_pin', :aggregate_failures do
expect do
subject
end.to change { AccountPin.where(account: user.account, target_account: kevin.account).count }.by(-1)
expect(response).to have_http_status(200)
end
end
end

View File

@@ -31,8 +31,8 @@ describe 'GET /api/v1/accounts/relationships' do
.to have_http_status(200)
expect(body_as_json)
.to be_an(Enumerable)
.and have_attributes(
first: include(
.and contain_exactly(
include(
following: true,
followed_by: false
)
@@ -53,9 +53,11 @@ describe 'GET /api/v1/accounts/relationships' do
expect(body_as_json)
.to be_an(Enumerable)
.and have_attributes(
size: 2,
first: include(simon_item),
second: include(lewis_item)
size: 2
)
.and contain_exactly(
include(simon_item),
include(lewis_item)
)
end
end
@@ -71,10 +73,12 @@ describe 'GET /api/v1/accounts/relationships' do
expect(body_as_json)
.to be_an(Enumerable)
.and have_attributes(
size: 3,
first: include(simon_item),
second: include(lewis_item),
third: include(bob_item)
size: 3
)
.and contain_exactly(
include(simon_item),
include(lewis_item),
include(bob_item)
)
end
end
@@ -88,9 +92,11 @@ describe 'GET /api/v1/accounts/relationships' do
expect(body_as_json)
.to be_an(Enumerable)
.and have_attributes(
size: 2,
first: include(simon_item),
second: include(lewis_item)
size: 2
)
.and contain_exactly(
include(simon_item),
include(lewis_item)
)
end
end
@@ -116,7 +122,6 @@ describe 'GET /api/v1/accounts/relationships' do
muting: false,
requested: false,
domain_blocking: false,
}
end
@@ -129,7 +134,6 @@ describe 'GET /api/v1/accounts/relationships' do
muting: false,
requested: false,
domain_blocking: false,
}
end
end
@@ -149,8 +153,10 @@ describe 'GET /api/v1/accounts/relationships' do
expect(body_as_json)
.to be_an(Enumerable)
.and have_attributes(
size: 1,
first: include(
size: 1
)
.and contain_exactly(
include(
following: true,
showing_reblogs: true
)
@@ -168,8 +174,8 @@ describe 'GET /api/v1/accounts/relationships' do
expect(body_as_json)
.to be_an(Enumerable)
.and have_attributes(
first: include(
.and contain_exactly(
include(
following: false,
showing_reblogs: false
)

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Accounts Search API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:accounts' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
describe 'GET /api/v1/accounts/search' do
it 'returns http success' do
get '/api/v1/accounts/search', params: { q: 'query' }, headers: headers
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Featured Tags Suggestions API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:accounts' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account) }
describe 'GET /api/v1/featured_tags/suggestions' do
it 'returns http success' do
get '/api/v1/featured_tags/suggestions', params: { account_id: account.id, limit: 2 }, headers: headers
expect(response).to have_http_status(200)
end
end
end

View File

@@ -0,0 +1,139 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Search API' do
context 'with token' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:search' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
describe 'GET /api/v2/search' do
let!(:bob) { Fabricate(:account, username: 'bob_test') }
let!(:ana) { Fabricate(:account, username: 'ana_test') }
let!(:tom) { Fabricate(:account, username: 'tom_test') }
let(:params) { { q: 'test' } }
it 'returns http success' do
get '/api/v2/search', headers: headers, params: params
expect(response).to have_http_status(200)
end
context 'when searching accounts' do
let(:params) { { q: 'test', type: 'accounts' } }
it 'returns all matching accounts' do
get '/api/v2/search', headers: headers, params: params
expect(body_as_json[:accounts].pluck(:id)).to contain_exactly(bob.id.to_s, ana.id.to_s, tom.id.to_s)
end
context 'with truthy `resolve`' do
let(:params) { { q: 'test1', resolve: '1' } }
it 'returns http unauthorized' do
get '/api/v2/search', headers: headers, params: params
expect(response).to have_http_status(200)
end
end
context 'with `offset`' do
let(:params) { { q: 'test1', offset: 1 } }
it 'returns http unauthorized' do
get '/api/v2/search', headers: headers, params: params
expect(response).to have_http_status(200)
end
end
context 'with following=true' do
let(:params) { { q: 'test', type: 'accounts', following: 'true' } }
before do
user.account.follow!(ana)
end
it 'returns only the followed accounts' do
get '/api/v2/search', headers: headers, params: params
expect(body_as_json[:accounts].pluck(:id)).to contain_exactly(ana.id.to_s)
end
end
end
context 'when search raises syntax error' do
before { allow(Search).to receive(:new).and_raise(Mastodon::SyntaxError) }
it 'returns http unprocessable_entity' do
get '/api/v2/search', headers: headers, params: params
expect(response).to have_http_status(422)
end
end
context 'when search raises not found error' do
before { allow(Search).to receive(:new).and_raise(ActiveRecord::RecordNotFound) }
it 'returns http not_found' do
get '/api/v2/search', headers: headers, params: params
expect(response).to have_http_status(404)
end
end
end
end
context 'without token' do
describe 'GET /api/v2/search' do
let(:search_params) { nil }
before do
get '/api/v2/search', params: search_params
end
context 'without a `q` param' do
it 'returns http bad_request' do
expect(response).to have_http_status(400)
end
end
context 'with a `q` shorter than 5 characters' do
let(:search_params) { { q: 'test' } }
it 'returns http success' do
expect(response).to have_http_status(200)
end
end
context 'with a `q` equal to or longer than 5 characters' do
let(:search_params) { { q: 'test1' } }
it 'returns http success' do
expect(response).to have_http_status(200)
end
context 'with truthy `resolve`' do
let(:search_params) { { q: 'test1', resolve: '1' } }
it 'returns http unauthorized' do
expect(response).to have_http_status(401)
expect(response.body).to match('resolve remote resources')
end
end
context 'with `offset`' do
let(:search_params) { { q: 'test1', offset: 1 } }
it 'returns http unauthorized' do
expect(response).to have_http_status(401)
expect(response.body).to match('pagination is not supported')
end
end
end
end
end
end

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
require 'rails_helper'
describe 'Suggestions API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
describe 'GET /api/v2/suggestions' do
it 'returns http success' do
get '/api/v2/suggestions', headers: headers
expect(response).to have_http_status(200)
end
end
end