2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-09 20:12:40 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 05:49:53 +02:00
|
|
|
RSpec.describe Api::V1::Statuses::FavouritedByAccountsController do
|
2017-06-09 20:12:40 +02:00
|
|
|
render_views
|
|
|
|
|
2022-01-28 00:46:42 +01:00
|
|
|
let(:user) { Fabricate(:user) }
|
2017-06-09 20:12:40 +02:00
|
|
|
let(:app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
2018-07-05 18:31:35 +02:00
|
|
|
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, application: app, scopes: 'read:accounts') }
|
2019-12-31 00:55:32 +01:00
|
|
|
let(:alice) { Fabricate(:account) }
|
|
|
|
let(:bob) { Fabricate(:account) }
|
2017-06-09 20:12:40 +02:00
|
|
|
|
|
|
|
context 'with an oauth token' do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:doorkeeper_token) { token }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
let(:status) { Fabricate(:status, account: user.account) }
|
|
|
|
|
|
|
|
before do
|
2019-12-31 00:55:32 +01:00
|
|
|
Favourite.create!(account: alice, status: status)
|
|
|
|
Favourite.create!(account: bob, status: status)
|
2017-06-09 20:12:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http success' do
|
2019-12-31 00:55:32 +01:00
|
|
|
get :index, params: { status_id: status.id, limit: 2 }
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-09 20:12:40 +02:00
|
|
|
expect(response.headers['Link'].links.size).to eq(2)
|
|
|
|
end
|
2019-12-31 00:55:32 +01:00
|
|
|
|
|
|
|
it 'returns accounts who favorited the status' do
|
|
|
|
get :index, params: { status_id: status.id, limit: 2 }
|
|
|
|
expect(body_as_json.size).to eq 2
|
2023-04-26 20:21:54 +02:00
|
|
|
expect([body_as_json[0][:id], body_as_json[1][:id]]).to contain_exactly(alice.id.to_s, bob.id.to_s)
|
2019-12-31 00:55:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return blocked users' do
|
|
|
|
user.account.block!(bob)
|
|
|
|
get :index, params: { status_id: status.id, limit: 2 }
|
|
|
|
expect(body_as_json.size).to eq 1
|
|
|
|
expect(body_as_json[0][:id]).to eq alice.id.to_s
|
|
|
|
end
|
2017-06-09 20:12:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without an oauth token' do
|
|
|
|
before do
|
2023-02-20 02:32:10 +01:00
|
|
|
allow(controller).to receive(:doorkeeper_token).and_return(nil)
|
2017-06-09 20:12:40 +02: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-06 22:51:40 +01:00
|
|
|
it 'returns http unauthorized' do
|
2017-06-09 20:12:40 +02:00
|
|
|
get :index, params: { status_id: status.id }
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(404)
|
2017-06-09 20:12:40 +02: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
|
|
|
|
get :index, params: { status_id: status.id }
|
2018-04-21 21:35:07 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2017-06-09 20:12:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|