mirror of
https://github.com/mastodon/mastodon.git
synced 2025-02-08 07:55:06 +00:00
da5b45a573
Some checks failed
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Bundler Audit / security (push) Has been cancelled
Haml Linting / lint (push) Has been cancelled
124 lines
3.9 KiB
Ruby
124 lines
3.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'Requests' 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/v1/notifications/requests', :inline_jobs do
|
|
subject do
|
|
get '/api/v1/notifications/requests', headers: headers, params: params
|
|
end
|
|
|
|
let(:params) { {} }
|
|
|
|
before do
|
|
Fabricate(:notification_request, account: user.account)
|
|
end
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'write write:notifications'
|
|
|
|
context 'with no options' do
|
|
it 'returns http success', :aggregate_failures do
|
|
subject
|
|
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'POST /api/v1/notifications/requests/:id/accept' do
|
|
subject do
|
|
post "/api/v1/notifications/requests/#{notification_request.id}/accept", headers: headers
|
|
end
|
|
|
|
let(:notification_request) { Fabricate(:notification_request, account: user.account) }
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:notifications'
|
|
|
|
it 'returns http success' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
|
|
it 'creates notification permission' do
|
|
subject
|
|
|
|
expect(NotificationPermission.find_by(account: notification_request.account, from_account: notification_request.from_account)).to_not be_nil
|
|
end
|
|
|
|
context 'when notification request belongs to someone else' do
|
|
let(:notification_request) { Fabricate(:notification_request) }
|
|
|
|
it 'returns http not found' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(404)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'POST /api/v1/notifications/requests/:id/dismiss' do
|
|
subject do
|
|
post "/api/v1/notifications/requests/#{notification_request.id}/dismiss", headers: headers
|
|
end
|
|
|
|
let!(:notification_request) { Fabricate(:notification_request, account: user.account) }
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:notifications'
|
|
|
|
it 'returns http success and destroys the notification request', :aggregate_failures do
|
|
expect { subject }.to change(NotificationRequest, :count).by(-1)
|
|
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
|
|
context 'when notification request belongs to someone else' do
|
|
let(:notification_request) { Fabricate(:notification_request) }
|
|
|
|
it 'returns http not found' do
|
|
subject
|
|
|
|
expect(response).to have_http_status(404)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'POST /api/v1/notifications/requests/accept' do
|
|
subject do
|
|
post '/api/v1/notifications/requests/accept', params: { id: [notification_request.id] }, headers: headers
|
|
end
|
|
|
|
let!(:notification_request) { Fabricate(:notification_request, account: user.account) }
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:notifications'
|
|
|
|
it 'returns http success and creates notification permission', :aggregate_failures do
|
|
subject
|
|
|
|
expect(NotificationPermission.find_by(account: notification_request.account, from_account: notification_request.from_account)).to_not be_nil
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
end
|
|
|
|
describe 'POST /api/v1/notifications/requests/dismiss' do
|
|
subject do
|
|
post '/api/v1/notifications/requests/dismiss', params: { id: [notification_request.id] }, headers: headers
|
|
end
|
|
|
|
let!(:notification_request) { Fabricate(:notification_request, account: user.account) }
|
|
|
|
it_behaves_like 'forbidden for wrong scope', 'read read:notifications'
|
|
|
|
it 'returns http success and destroys the notification request', :aggregate_failures do
|
|
expect { subject }.to change(NotificationRequest, :count).by(-1)
|
|
|
|
expect(response).to have_http_status(200)
|
|
end
|
|
end
|
|
end
|