2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-10 04:12:40 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-01-22 22:58:54 +11:00
|
|
|
RSpec.describe 'API V1 Statuses Favourited by Accounts' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:scopes) { 'read:accounts' }
|
|
|
|
# let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
|
|
|
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
2019-12-31 10:55:32 +11:00
|
|
|
let(:alice) { Fabricate(:account) }
|
|
|
|
let(:bob) { Fabricate(:account) }
|
2017-06-10 04:12:40 +10:00
|
|
|
|
|
|
|
context 'with an oauth token' do
|
2024-01-22 22:58:54 +11:00
|
|
|
subject do
|
|
|
|
get "/api/v1/statuses/#{status.id}/favourited_by", headers: headers, params: { limit: 2 }
|
2017-06-10 04:12:40 +10:00
|
|
|
end
|
|
|
|
|
2024-01-22 22:58:54 +11:00
|
|
|
describe 'GET /api/v1/statuses/:status_id/favourited_by' do
|
2017-06-10 04:12:40 +10:00
|
|
|
let(:status) { Fabricate(:status, account: user.account) }
|
|
|
|
|
|
|
|
before do
|
2019-12-31 10:55:32 +11:00
|
|
|
Favourite.create!(account: alice, status: status)
|
|
|
|
Favourite.create!(account: bob, status: status)
|
2017-06-10 04:12:40 +10:00
|
|
|
end
|
|
|
|
|
2024-01-22 22:58:54 +11:00
|
|
|
it 'returns http success and accounts who favourited the status' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
2024-07-12 18:30:52 +10:00
|
|
|
.and include_pagination_headers(
|
|
|
|
prev: api_v1_status_favourited_by_index_url(limit: 2, since_id: Favourite.last.id),
|
|
|
|
next: api_v1_status_favourited_by_index_url(limit: 2, max_id: Favourite.first.id)
|
|
|
|
)
|
2024-01-22 22:58:54 +11:00
|
|
|
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body.size)
|
2024-01-22 22:58:54 +11:00
|
|
|
.to eq(2)
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body)
|
2024-01-22 22:58:54 +11:00
|
|
|
.to contain_exactly(
|
|
|
|
include(id: alice.id.to_s),
|
|
|
|
include(id: bob.id.to_s)
|
|
|
|
)
|
2019-12-31 10:55:32 +11:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return blocked users' do
|
|
|
|
user.account.block!(bob)
|
2024-01-22 22:58:54 +11:00
|
|
|
|
|
|
|
subject
|
|
|
|
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body.size)
|
2024-01-22 22:58:54 +11:00
|
|
|
.to eq 1
|
2024-09-06 19:58:46 +10:00
|
|
|
expect(response.parsed_body.first[:id]).to eq(alice.id.to_s)
|
2019-12-31 10:55:32 +11:00
|
|
|
end
|
2017-06-10 04:12:40 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without an oauth token' do
|
2024-01-22 22:58:54 +11:00
|
|
|
subject do
|
|
|
|
get "/api/v1/statuses/#{status.id}/favourited_by", params: { limit: 2 }
|
2017-06-10 04:12:40 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a private status' do
|
|
|
|
let(:status) { Fabricate(:status, account: user.account, visibility: :private) }
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
before do
|
|
|
|
Fabricate(:favourite, status: status)
|
|
|
|
end
|
|
|
|
|
2022-03-07 08:51:40 +11:00
|
|
|
it 'returns http unauthorized' do
|
2024-01-22 22:58:54 +11:00
|
|
|
subject
|
|
|
|
|
2018-04-22 05:35:07 +10:00
|
|
|
expect(response).to have_http_status(404)
|
2017-06-10 04:12:40 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a public status' do
|
|
|
|
let(:status) { Fabricate(:status, account: user.account, visibility: :public) }
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
before do
|
|
|
|
Fabricate(:favourite, status: status)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2024-01-22 22:58:54 +11:00
|
|
|
subject
|
|
|
|
|
2018-04-22 05:35:07 +10:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-10 04:12:40 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|