Merge remote-tracking branch 'parent/main' into upstream-20241026

This commit is contained in:
KMY 2024-10-26 10:41:00 +09:00
commit 0c99b8fbb0
79 changed files with 2403 additions and 2056 deletions

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'ActivityPub Likes' do
let(:account) { Fabricate(:account) }
let(:status) { Fabricate :status, account: account }
before { Fabricate :favourite, status: status }
describe 'GET /accounts/:account_username/statuses/:status_id/likes' do
it 'returns http success and activity json types and correct items count' do
get account_status_likes_path(account, status)
expect(response)
.to have_http_status(200)
expect(response.media_type)
.to eq 'application/activity+json'
expect(response.parsed_body)
.to include(type: 'Collection')
.and include(totalItems: 1)
end
end
end

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'ActivityPub Shares' do
let(:account) { Fabricate(:account) }
let(:status) { Fabricate :status, account: account }
before { Fabricate :status, reblog: status }
describe 'GET /accounts/:account_username/statuses/:status_id/shares' do
it 'returns http success and activity json types and correct items count' do
get account_status_shares_path(account, status)
expect(response)
.to have_http_status(200)
expect(response.media_type)
.to eq 'application/activity+json'
expect(response.parsed_body)
.to include(type: 'Collection')
.and include(totalItems: 1)
end
end
end

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'Domain Blocks Previews API' do
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'write:blocks' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account, user: user) }
describe 'GET /api/v1/domain_blocks/preview' do
subject { get '/api/v1/domain_blocks/preview', params: { domain: domain }, headers: headers }
let(:domain) { 'host.example' }
before do
Fabricate :follow, account: account, target_account: Fabricate(:account, domain: domain)
Fabricate :follow, target_account: account, account: Fabricate(:account, domain: domain)
end
it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it 'returns http success and follower counts' do
subject
expect(response)
.to have_http_status(200)
expect(response.content_type)
.to start_with('application/json')
expect(response.parsed_body)
.to include(followers_count: 1)
.and include(following_count: 1)
end
end
end

View file

@ -0,0 +1,55 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'API Web Push Subscriptions' do
describe 'DELETE /api/web/push_subscriptions/:id' do
subject { delete api_web_push_subscription_path(token) }
context 'when the subscription exists' do
let!(:web_push_subscription) do
Fabricate(:web_push_subscription)
end
let(:token) do
web_push_subscription.generate_token_for(:unsubscribe)
end
it 'deletes the subscription' do
expect { subject }
.to change(Web::PushSubscription, :count).by(-1)
expect(response).to have_http_status(200)
end
end
context 'when the subscription does not exist' do
let(:web_push_subscription) do
Fabricate(:web_push_subscription)
end
let(:token) do
web_push_subscription.generate_token_for(:unsubscribe)
end
before do
token # memoize before destroying the record
web_push_subscription.destroy!
end
it 'does nothing' do
subject
expect(response).to have_http_status(200)
end
end
context 'when the token is invalid' do
let(:token) { 'invalid--invalid' }
it 'does nothing' do
subject
expect(response).to have_http_status(200)
end
end
end
end