Merge remote-tracking branch 'parent/main' into upstream-20240906
This commit is contained in:
commit
f18eabfe75
689 changed files with 4369 additions and 2434 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Accounts Familiar Followers API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Accounts FollowerAccounts' do
|
||||
RSpec.describe 'API V1 Accounts FollowerAccounts' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:accounts' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Accounts FollowingAccounts' do
|
||||
RSpec.describe 'API V1 Accounts FollowingAccounts' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:accounts' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Accounts Identity Proofs API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Accounts Lists API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Accounts Lookup API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Accounts Notes API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Accounts Pins API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'GET /api/v1/accounts/relationships' do
|
||||
RSpec.describe 'GET /api/v1/accounts/relationships' do
|
||||
subject do
|
||||
get '/api/v1/accounts/relationships', headers: headers, params: params
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Accounts Search API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Accounts Statuses' do
|
||||
RSpec.describe 'API V1 Accounts Statuses' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe '/api/v1/accounts' do
|
||||
RSpec.describe '/api/v1/accounts' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { '' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
@ -122,10 +122,11 @@ describe '/api/v1/accounts' do
|
|||
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:following]).to be true
|
||||
expect(json[:requested]).to be false
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
following: true,
|
||||
requested: false
|
||||
)
|
||||
|
||||
expect(user.account.following?(other_account)).to be true
|
||||
end
|
||||
|
@ -141,10 +142,11 @@ describe '/api/v1/accounts' do
|
|||
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:following]).to be false
|
||||
expect(json[:requested]).to be true
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
following: false,
|
||||
requested: true
|
||||
)
|
||||
|
||||
expect(user.account.requested?(other_account)).to be true
|
||||
end
|
||||
|
|
|
@ -96,10 +96,11 @@ RSpec.describe 'Canonical Email Blocks' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:id]).to eq(canonical_email_block.id.to_s)
|
||||
expect(json[:canonical_email_hash]).to eq(canonical_email_block.canonical_email_hash)
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
id: eq(canonical_email_block.id.to_s),
|
||||
canonical_email_hash: eq(canonical_email_block.canonical_email_hash)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Admin Dimensions' do
|
||||
RSpec.describe 'Admin Dimensions' do
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -126,7 +126,7 @@ RSpec.describe 'Domain Blocks' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq(
|
||||
expect(body_as_json).to match(
|
||||
{
|
||||
id: domain_block.id.to_s,
|
||||
domain: domain_block.domain,
|
||||
|
@ -174,10 +174,8 @@ RSpec.describe 'Domain Blocks' do
|
|||
it 'creates a domain block with the expected domain name and severity', :aggregate_failures do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body).to match a_hash_including(
|
||||
expect(body_as_json).to match a_hash_including(
|
||||
{
|
||||
domain: 'foo.bar.com',
|
||||
severity: 'silence',
|
||||
|
@ -197,10 +195,8 @@ RSpec.describe 'Domain Blocks' do
|
|||
it 'creates a domain block with the expected domain name and severity', :aggregate_failures do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body).to match a_hash_including(
|
||||
expect(body_as_json).to match a_hash_including(
|
||||
{
|
||||
domain: 'foo.bar.com',
|
||||
severity: 'suspend',
|
||||
|
|
|
@ -88,10 +88,12 @@ RSpec.describe 'IP Blocks' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:ip]).to eq("#{ip_block.ip}/#{ip_block.ip.prefix}")
|
||||
expect(json[:severity]).to eq(ip_block.severity.to_s)
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
ip: eq("#{ip_block.ip}/#{ip_block.ip.prefix}"),
|
||||
severity: eq(ip_block.severity.to_s)
|
||||
)
|
||||
end
|
||||
|
||||
context 'when ip block does not exist' do
|
||||
|
@ -118,11 +120,12 @@ RSpec.describe 'IP Blocks' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:ip]).to eq("#{params[:ip]}/32")
|
||||
expect(json[:severity]).to eq(params[:severity])
|
||||
expect(json[:comment]).to eq(params[:comment])
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
ip: eq("#{params[:ip]}/32"),
|
||||
severity: eq(params[:severity]),
|
||||
comment: eq(params[:comment])
|
||||
)
|
||||
end
|
||||
|
||||
context 'when the required ip param is not provided' do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Admin Measures' do
|
||||
RSpec.describe 'Admin Measures' do
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Admin Retention' do
|
||||
RSpec.describe 'Admin Retention' do
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Links' do
|
||||
RSpec.describe 'Links' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Admin Trends Links Preview Card Providers' do
|
||||
RSpec.describe 'API V1 Admin Trends Links Preview Card Providers' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Admin Trends Statuses' do
|
||||
RSpec.describe 'API V1 Admin Trends Statuses' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Admin Trends Tags' do
|
||||
RSpec.describe 'API V1 Admin Trends Tags' do
|
||||
let(:role) { UserRole.find_by(name: 'Admin') }
|
||||
let(:user) { Fabricate(:user, role: role) }
|
||||
let(:scopes) { 'admin:read admin:write' }
|
||||
|
|
57
spec/requests/api/v1/annual_reports_spec.rb
Normal file
57
spec/requests/api/v1/annual_reports_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'API V1 Annual Reports' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
describe 'GET /api/v1/annual_reports' do
|
||||
context 'when not authorized' do
|
||||
it 'returns http unauthorized' do
|
||||
get api_v1_annual_reports_path
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(401)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with wrong scope' do
|
||||
before do
|
||||
get api_v1_annual_reports_path, headers: headers
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write write:accounts'
|
||||
end
|
||||
|
||||
context 'with correct scope' do
|
||||
let(:scopes) { 'read:accounts' }
|
||||
|
||||
it 'returns http success' do
|
||||
get api_v1_annual_reports_path, headers: headers
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
|
||||
expect(body_as_json)
|
||||
.to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/annual_reports/:id/read' do
|
||||
context 'with correct scope' do
|
||||
let(:scopes) { 'write:accounts' }
|
||||
|
||||
it 'returns success and marks the report as read' do
|
||||
annual_report = Fabricate :generated_annual_report, account: user.account
|
||||
|
||||
expect { post read_api_v1_annual_report_path(id: annual_report.year), headers: headers }
|
||||
.to change { annual_report.reload.viewed? }.to(true)
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Credentials' do
|
||||
RSpec.describe 'Credentials' do
|
||||
describe 'GET /api/v1/apps/verify_credentials' do
|
||||
subject do
|
||||
get '/api/v1/apps/verify_credentials', headers: headers
|
||||
|
|
|
@ -61,9 +61,10 @@ RSpec.describe 'Apps' do
|
|||
expect(response).to have_http_status(200)
|
||||
expect(Doorkeeper::Application.find_by(name: client_name)).to be_present
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body[:scopes]).to eq Doorkeeper.config.default_scopes.to_a
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
scopes: Doorkeeper.config.default_scopes.to_a
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -81,9 +82,10 @@ RSpec.describe 'Apps' do
|
|||
expect(app).to be_present
|
||||
expect(app.scopes.to_s).to eq 'read'
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body[:scopes]).to eq ['read']
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
scopes: %w(read)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -163,10 +165,11 @@ RSpec.describe 'Apps' do
|
|||
expect(app.redirect_uri).to eq redirect_uris
|
||||
expect(app.redirect_uris).to eq redirect_uris.split
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body[:redirect_uri]).to eq redirect_uris
|
||||
expect(body[:redirect_uris]).to eq redirect_uris.split
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
redirect_uri: redirect_uris,
|
||||
redirect_uris: redirect_uris.split
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -184,10 +187,11 @@ RSpec.describe 'Apps' do
|
|||
expect(app.redirect_uri).to eq redirect_uris.join "\n"
|
||||
expect(app.redirect_uris).to eq redirect_uris
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body[:redirect_uri]).to eq redirect_uris.join "\n"
|
||||
expect(body[:redirect_uris]).to eq redirect_uris
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
redirect_uri: redirect_uris.join("\n"),
|
||||
redirect_uris: redirect_uris
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -55,10 +55,8 @@ RSpec.describe 'Blocks' do
|
|||
it 'queries the blocks in range according to max_id', :aggregate_failures do
|
||||
subject
|
||||
|
||||
response_body = body_as_json
|
||||
|
||||
expect(response_body.size).to be 1
|
||||
expect(response_body[0][:id]).to eq(blocks[0].target_account.id.to_s)
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(include(id: blocks.first.target_account.id.to_s))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,10 +66,8 @@ RSpec.describe 'Blocks' do
|
|||
it 'queries the blocks in range according to since_id', :aggregate_failures do
|
||||
subject
|
||||
|
||||
response_body = body_as_json
|
||||
|
||||
expect(response_body.size).to be 1
|
||||
expect(response_body[0][:id]).to eq(blocks[2].target_account.id.to_s)
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(include(id: blocks[2].target_account.id.to_s))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API namespace minimal Content-Security-Policy' do
|
||||
RSpec.describe 'API namespace minimal Content-Security-Policy' do
|
||||
before { stub_tests_controller }
|
||||
|
||||
after { Rails.application.reload_routes! }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Custom Emojis' do
|
||||
RSpec.describe 'Custom Emojis' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Directories API' do
|
||||
RSpec.describe 'Directories API' do
|
||||
let(:user) { Fabricate(:user, confirmed_at: nil) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:follows' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Endorsements' do
|
||||
RSpec.describe 'Endorsements' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Featured Tags Suggestions API' do
|
||||
RSpec.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' }
|
||||
|
|
|
@ -37,9 +37,7 @@ RSpec.describe 'FeaturedTags' do
|
|||
it 'returns an empty body' do
|
||||
get '/api/v1/featured_tags', headers: headers
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body).to be_empty
|
||||
expect(body_as_json).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,10 +47,10 @@ RSpec.describe 'FeaturedTags' do
|
|||
it 'returns only the featured tags belonging to the requesting user' do
|
||||
get '/api/v1/featured_tags', headers: headers
|
||||
|
||||
body = body_as_json
|
||||
expected_ids = user_featured_tags.pluck(:id).map(&:to_s)
|
||||
|
||||
expect(body.pluck(:id)).to match_array(expected_ids)
|
||||
expect(body_as_json.pluck(:id))
|
||||
.to match_array(
|
||||
user_featured_tags.pluck(:id).map(&:to_s)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -69,9 +67,10 @@ RSpec.describe 'FeaturedTags' do
|
|||
it 'returns the correct tag name' do
|
||||
post '/api/v1/featured_tags', headers: headers, params: params
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body[:name]).to eq(params[:name])
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
name: params[:name]
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates a new featured tag for the requesting user' do
|
||||
|
@ -142,9 +141,7 @@ RSpec.describe 'FeaturedTags' do
|
|||
it 'returns an empty body' do
|
||||
delete "/api/v1/featured_tags/#{id}", headers: headers
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body).to be_empty
|
||||
expect(body_as_json).to be_empty
|
||||
end
|
||||
|
||||
it 'deletes the featured tag', :inline_jobs do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Instances' do
|
||||
RSpec.describe 'Instances' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Translation Languages' do
|
||||
RSpec.describe 'Translation Languages' do
|
||||
describe 'GET /api/v1/instances/translation_languages' do
|
||||
context 'when no translation service is configured' do
|
||||
it 'returns empty language matrix', :aggregate_failures do
|
||||
|
@ -26,7 +26,7 @@ describe 'Translation Languages' do
|
|||
.to have_http_status(200)
|
||||
|
||||
expect(body_as_json)
|
||||
.to eq({ und: %w(en de), en: ['de'] })
|
||||
.to match({ und: %w(en de), en: ['de'] })
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -63,7 +63,7 @@ RSpec.describe 'Lists' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: list.id.to_s,
|
||||
title: list.title,
|
||||
replies_policy: list.replies_policy,
|
||||
|
@ -149,7 +149,7 @@ RSpec.describe 'Lists' do
|
|||
expect(response).to have_http_status(200)
|
||||
list.reload
|
||||
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: list.id.to_s,
|
||||
title: list.title,
|
||||
replies_policy: list.replies_policy,
|
||||
|
|
|
@ -17,13 +17,12 @@ RSpec.describe 'API Markers' do
|
|||
end
|
||||
|
||||
it 'returns markers', :aggregate_failures do
|
||||
json = body_as_json
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(json.key?(:home)).to be true
|
||||
expect(json[:home][:last_read_id]).to eq '123'
|
||||
expect(json.key?(:notifications)).to be true
|
||||
expect(json[:notifications][:last_read_id]).to eq '456'
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
home: include(last_read_id: '123'),
|
||||
notifications: include(last_read_id: '456')
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -58,10 +58,8 @@ RSpec.describe 'Mutes' do
|
|||
it 'queries mutes in range according to max_id', :aggregate_failures do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body.size).to eq 1
|
||||
expect(body[0][:id]).to eq mutes[0].target_account_id.to_s
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(include(id: mutes.first.target_account_id.to_s))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,10 +69,8 @@ RSpec.describe 'Mutes' do
|
|||
it 'queries mutes in range according to since_id', :aggregate_failures do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body.size).to eq 1
|
||||
expect(body[0][:id]).to eq mutes[1].target_account_id.to_s
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(include(id: mutes[1].target_account_id.to_s))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ RSpec.describe 'Requests' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({ merged: true })
|
||||
expect(body_as_json).to match({ merged: true })
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,7 +146,7 @@ RSpec.describe 'Requests' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({ merged: false })
|
||||
expect(body_as_json).to match({ merged: false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API Peers Search' do
|
||||
RSpec.describe 'API Peers Search' do
|
||||
describe 'GET /api/v1/peers/search' do
|
||||
context 'when peers api is disabled' do
|
||||
before do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Preferences' do
|
||||
RSpec.describe 'Preferences' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Push Subscriptions' do
|
||||
RSpec.describe 'API V1 Push Subscriptions' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:endpoint) { 'https://fcm.googleapis.com/fcm/send/fiuH06a27qE:APA91bHnSiGcLwdaxdyqVXNDR9w1NlztsHb6lyt5WDKOC_Z_Q8BlFxQoR8tWFSXUIDdkyw0EdvxTu63iqamSaqVSevW5LfoFwojws8XYDXv_NRRLH6vo2CdgiN4jgHv5VLt2A8ah6lUX' }
|
||||
let(:keys) do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Scheduled Statuses' do
|
||||
RSpec.describe 'Scheduled Statuses' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Statuses Histories' do
|
||||
RSpec.describe 'API V1 Statuses Histories' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Statuses Mutes' do
|
||||
RSpec.describe 'API V1 Statuses Mutes' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'write:mutes' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Pins' do
|
||||
RSpec.describe 'Pins' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'write:accounts' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Statuses Reblogs' do
|
||||
RSpec.describe 'API V1 Statuses Reblogs' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'write:statuses' }
|
||||
|
@ -24,11 +24,14 @@ describe 'API V1 Statuses Reblogs' do
|
|||
|
||||
expect(user.account.reblogged?(status)).to be true
|
||||
|
||||
hash_body = body_as_json
|
||||
|
||||
expect(hash_body[:reblog][:id]).to eq status.id.to_s
|
||||
expect(hash_body[:reblog][:reblogs_count]).to eq 1
|
||||
expect(hash_body[:reblog][:reblogged]).to be true
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
reblog: include(
|
||||
id: status.id.to_s,
|
||||
reblogs_count: 1,
|
||||
reblogged: true
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -57,11 +60,12 @@ describe 'API V1 Statuses Reblogs' do
|
|||
|
||||
expect(user.account.reblogged?(status)).to be false
|
||||
|
||||
hash_body = body_as_json
|
||||
|
||||
expect(hash_body[:id]).to eq status.id.to_s
|
||||
expect(hash_body[:reblogs_count]).to eq 0
|
||||
expect(hash_body[:reblogged]).to be false
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
id: status.id.to_s,
|
||||
reblogs_count: 0,
|
||||
reblogged: false
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -81,11 +85,12 @@ describe 'API V1 Statuses Reblogs' do
|
|||
|
||||
expect(user.account.reblogged?(status)).to be false
|
||||
|
||||
hash_body = body_as_json
|
||||
|
||||
expect(hash_body[:id]).to eq status.id.to_s
|
||||
expect(hash_body[:reblogs_count]).to eq 0
|
||||
expect(hash_body[:reblogged]).to be false
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
id: status.id.to_s,
|
||||
reblogs_count: 0,
|
||||
reblogged: false
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ RSpec.describe 'Sources' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: status.id.to_s,
|
||||
text: status.text,
|
||||
spoiler_text: status.spoiler_text,
|
||||
|
@ -51,7 +51,7 @@ RSpec.describe 'Sources' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json).to eq({
|
||||
expect(body_as_json).to match({
|
||||
id: status.id.to_s,
|
||||
text: status.text,
|
||||
spoiler_text: status.spoiler_text,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Statuses Translations' do
|
||||
RSpec.describe 'API V1 Statuses Translations' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe '/api/v1/statuses' do
|
||||
RSpec.describe '/api/v1/statuses' do
|
||||
context 'with an oauth token' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:client_app) { Fabricate(:application, name: 'Test app', website: 'http://testapp.com') }
|
||||
|
@ -243,7 +243,7 @@ describe '/api/v1/statuses' do
|
|||
subject
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to eq [{ id: bob.id.to_s, acct: bob.acct }]
|
||||
expect(body_as_json[:unexpected_accounts].map { |a| a.slice(:id, :acct) }).to match [{ id: bob.id.to_s, acct: bob.acct }]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Streaming' do
|
||||
RSpec.describe 'API V1 Streaming' do
|
||||
around do |example|
|
||||
before = Rails.configuration.x.streaming_api_base_url
|
||||
Rails.configuration.x.streaming_api_base_url = "wss://#{Rails.configuration.x.web_domain}"
|
||||
|
@ -10,12 +10,11 @@ describe 'API V1 Streaming' do
|
|||
Rails.configuration.x.streaming_api_base_url = before
|
||||
end
|
||||
|
||||
let(:headers) { { 'Host' => Rails.configuration.x.web_domain } }
|
||||
|
||||
context 'with streaming api on same host' do
|
||||
describe 'GET /api/v1/streaming' do
|
||||
it 'raises ActiveRecord::RecordNotFound' do
|
||||
get '/api/v1/streaming', headers: headers
|
||||
integration_session.https!(false)
|
||||
get '/api/v1/streaming'
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
|
|
|
@ -32,10 +32,8 @@ RSpec.describe 'Suggestions' do
|
|||
it 'returns accounts' do
|
||||
subject
|
||||
|
||||
body = body_as_json
|
||||
|
||||
expect(body.size).to eq 2
|
||||
expect(body.pluck(:id)).to match_array([bob, jeff].map { |i| i.id.to_s })
|
||||
expect(body_as_json)
|
||||
.to contain_exactly(include(id: bob.id.to_s), include(id: jeff.id.to_s))
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Home', :inline_jobs do
|
||||
RSpec.describe 'Home', :inline_jobs do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
@ -94,8 +94,9 @@ describe 'Home', :inline_jobs do
|
|||
it 'returns http unprocessable entity', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
||||
expect(response)
|
||||
.to have_http_status(422)
|
||||
.and not_have_http_link_header
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Link' do
|
||||
RSpec.describe 'Link' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'API V1 Timelines List' do
|
||||
RSpec.describe 'API V1 Timelines List' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
@ -47,8 +47,9 @@ describe 'API V1 Timelines List' do
|
|||
it 'returns http unprocessable entity' do
|
||||
get "/api/v1/timelines/list/#{list.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
||||
expect(response)
|
||||
.to have_http_status(422)
|
||||
.and not_have_http_link_header
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Public' do
|
||||
RSpec.describe 'Public' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:scopes) { 'read:statuses' }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
|
|
|
@ -8,22 +8,25 @@ RSpec.describe 'Tag' do
|
|||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
shared_examples 'a successful request to the tag timeline' do
|
||||
it 'returns the expected statuses', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json.pluck(:id)).to match_array(expected_statuses.map { |status| status.id.to_s })
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET /api/v1/timelines/tag/:hashtag' do
|
||||
subject do
|
||||
get "/api/v1/timelines/tag/#{hashtag}", headers: headers, params: params
|
||||
end
|
||||
|
||||
shared_examples 'a successful request to the tag timeline' do
|
||||
it 'returns the expected statuses', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
expect(body_as_json.pluck(:id))
|
||||
.to match_array(expected_statuses.map { |status| status.id.to_s })
|
||||
.and not_include(private_status.id)
|
||||
end
|
||||
end
|
||||
|
||||
let(:account) { Fabricate(:account) }
|
||||
let!(:private_status) { PostStatusService.new.call(account, visibility: :private, text: '#life could be a dream') } # rubocop:disable RSpec/LetSetup
|
||||
let!(:private_status) { PostStatusService.new.call(account, visibility: :private, text: '#life could be a dream') }
|
||||
let!(:life_status) { PostStatusService.new.call(account, text: 'tell me what is my #life without your #love') }
|
||||
let!(:war_status) { PostStatusService.new.call(user.account, text: '#war, war never changes') }
|
||||
let!(:love_status) { PostStatusService.new.call(account, text: 'what is #love?') }
|
||||
|
|
|
@ -42,9 +42,11 @@ RSpec.describe 'API V2 Filters Keywords' do
|
|||
it 'creates a filter', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
json = body_as_json
|
||||
expect(json[:keyword]).to eq 'magic'
|
||||
expect(json[:whole_word]).to be false
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
keyword: 'magic',
|
||||
whole_word: false
|
||||
)
|
||||
|
||||
filter = user.account.custom_filters.first
|
||||
expect(filter).to_not be_nil
|
||||
|
@ -71,9 +73,11 @@ RSpec.describe 'API V2 Filters Keywords' do
|
|||
it 'responds with the keyword', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
json = body_as_json
|
||||
expect(json[:keyword]).to eq 'foo'
|
||||
expect(json[:whole_word]).to be false
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
keyword: 'foo',
|
||||
whole_word: false
|
||||
)
|
||||
end
|
||||
|
||||
context "when trying to access another user's filter keyword" do
|
||||
|
|
|
@ -43,8 +43,10 @@ RSpec.describe 'API V2 Filters Statuses' do
|
|||
it 'creates a filter', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
json = body_as_json
|
||||
expect(json[:status_id]).to eq status.id.to_s
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
status_id: status.id.to_s
|
||||
)
|
||||
|
||||
filter = user.account.custom_filters.first
|
||||
expect(filter).to_not be_nil
|
||||
|
@ -71,8 +73,10 @@ RSpec.describe 'API V2 Filters Statuses' do
|
|||
it 'responds with the filter', :aggregate_failures do
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
json = body_as_json
|
||||
expect(json[:status_id]).to eq status_filter.status_id.to_s
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
status_id: status_filter.status.id.to_s
|
||||
)
|
||||
end
|
||||
|
||||
context "when trying to access another user's filter keyword" do
|
||||
|
|
|
@ -68,15 +68,18 @@ RSpec.describe 'Filters' do
|
|||
it 'returns a filter with keywords', :aggregate_failures do
|
||||
subject
|
||||
|
||||
json = body_as_json
|
||||
|
||||
expect(json[:title]).to eq 'magic'
|
||||
expect(json[:filter_action]).to eq 'hide'
|
||||
expect(json[:context]).to eq ['home']
|
||||
expect(json[:keywords].map { |keyword| keyword.slice(:keyword, :whole_word) }).to eq [{ keyword: 'magic', whole_word: true }]
|
||||
expect(json[:exclude_follows]).to be true
|
||||
expect(json[:exclude_localusers]).to be true
|
||||
expect(json[:with_profile]).to be true
|
||||
expect(body_as_json)
|
||||
.to include(
|
||||
title: 'magic',
|
||||
filter_action: 'hide',
|
||||
context: %w(home),
|
||||
keywords: contain_exactly(
|
||||
include(keyword: 'magic', whole_word: true)
|
||||
),
|
||||
exclude_follows: true,
|
||||
exclude_localusers: true,
|
||||
with_profile: true
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates a filter', :aggregate_failures do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Instances' do
|
||||
RSpec.describe 'Instances' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id) }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Search API' do
|
||||
RSpec.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) }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe 'Suggestions API' do
|
||||
RSpec.describe 'Suggestions API' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read' }
|
||||
|
|
80
spec/requests/api/v2_alpha/notifications/accounts_spec.rb
Normal file
80
spec/requests/api/v2_alpha/notifications/accounts_spec.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Accounts in grouped notifications' do
|
||||
let(:user) { Fabricate(:user, account_attributes: { username: 'alice' }) }
|
||||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
|
||||
let(:scopes) { 'read:notifications write:notifications' }
|
||||
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
|
||||
|
||||
describe 'GET /api/v2_alpha/notifications/:group_key/accounts', :inline_jobs do
|
||||
subject do
|
||||
get "/api/v2_alpha/notifications/#{user.account.notifications.first.group_key}/accounts", headers: headers, params: params
|
||||
end
|
||||
|
||||
let(:params) { {} }
|
||||
|
||||
before do
|
||||
first_status = PostStatusService.new.call(user.account, text: 'Test')
|
||||
FavouriteService.new.call(Fabricate(:account), first_status)
|
||||
FavouriteService.new.call(Fabricate(:account), first_status)
|
||||
ReblogService.new.call(Fabricate(:account), first_status)
|
||||
FollowService.new.call(Fabricate(:account), user.account)
|
||||
FavouriteService.new.call(Fabricate(:account), first_status)
|
||||
end
|
||||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write write:notifications'
|
||||
|
||||
it 'returns a list of accounts' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
# The group we are interested in is only favorites
|
||||
notifications = user.account.notifications.where(type: 'favourite').reorder(id: :desc)
|
||||
expect(body_as_json).to match(
|
||||
[
|
||||
a_hash_including(
|
||||
id: notifications.first.from_account_id.to_s
|
||||
),
|
||||
a_hash_including(
|
||||
id: notifications.second.from_account_id.to_s
|
||||
),
|
||||
a_hash_including(
|
||||
id: notifications.third.from_account_id.to_s
|
||||
),
|
||||
]
|
||||
)
|
||||
end
|
||||
|
||||
context 'with limit param' do
|
||||
let(:params) { { limit: 2 } }
|
||||
|
||||
it 'returns the requested number of accounts, with pagination headers' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
|
||||
# The group we are interested in is only favorites
|
||||
notifications = user.account.notifications.where(type: 'favourite').reorder(id: :desc)
|
||||
expect(body_as_json).to match(
|
||||
[
|
||||
a_hash_including(
|
||||
id: notifications.first.from_account_id.to_s
|
||||
),
|
||||
a_hash_including(
|
||||
id: notifications.second.from_account_id.to_s
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
expect(response)
|
||||
.to include_pagination_headers(
|
||||
prev: api_v2_alpha_notification_accounts_url(limit: params[:limit], min_id: notifications.first.id),
|
||||
next: api_v2_alpha_notification_accounts_url(limit: params[:limit], max_id: notifications.second.id)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -116,6 +116,19 @@ RSpec.describe 'Notifications' do
|
|||
|
||||
it_behaves_like 'forbidden for wrong scope', 'write write:notifications'
|
||||
|
||||
context 'when there are no notifications' do
|
||||
before do
|
||||
user.account.notifications.destroy_all
|
||||
end
|
||||
|
||||
it 'returns 0 notifications' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json[:notification_groups]).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
context 'with no options' do
|
||||
it 'returns expected notification types', :aggregate_failures do
|
||||
subject
|
||||
|
@ -235,7 +248,7 @@ RSpec.describe 'Notifications' do
|
|||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(body_as_json[:partial_accounts].size).to be > 0
|
||||
expect(body_as_json[:partial_accounts][0].keys).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url)
|
||||
expect(body_as_json[:partial_accounts][0].keys.map(&:to_sym)).to contain_exactly(:acct, :avatar, :avatar_static, :bot, :id, :locked, :url)
|
||||
expect(body_as_json[:partial_accounts].pluck(:id)).to_not include(recent_account.id.to_s)
|
||||
expect(body_as_json[:accounts].pluck(:id)).to include(recent_account.id.to_s)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue