Convert oauth/authorized_applications spec controller->request (#37614)

This commit is contained in:
Matt Jankowski 2026-01-27 05:44:24 -05:00 committed by GitHub
parent 142714cd1e
commit aa347708f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,21 +2,16 @@
require 'rails_helper' require 'rails_helper'
RSpec.describe OAuth::AuthorizedApplicationsController do RSpec.describe 'OAuth Authorized Applications' do
render_views describe 'GET /oauth/authorized_applications' do
subject { get oauth_authorized_applications_path }
describe 'GET #index' do
subject do
get :index
end
context 'when signed in' do context 'when signed in' do
before do before { sign_in Fabricate(:user) }
sign_in Fabricate(:user), scope: :user
end
it 'returns http success with private cache control headers' do it 'returns http success with private cache control headers' do
subject subject
expect(response) expect(response)
.to have_http_status(200) .to have_http_status(200)
expect(response.headers['Cache-Control']) expect(response.headers['Cache-Control'])
@ -40,29 +35,29 @@ RSpec.describe OAuth::AuthorizedApplicationsController do
end end
end end
describe 'DELETE #destroy' do describe 'DELETE /oauth/authorized_applications/:id' do
subject { delete oauth_authorized_application_path(application) }
let!(:user) { Fabricate(:user) } let!(:user) { Fabricate(:user) }
let!(:application) { Fabricate(:application) } let!(:application) { Fabricate(:application) }
let!(:access_token) { Fabricate(:accessible_access_token, application: application, resource_owner_id: user.id) } let!(:access_token) { Fabricate(:accessible_access_token, application: application, resource_owner_id: user.id) }
let!(:web_push_subscription) { Fabricate(:web_push_subscription, user: user, access_token: access_token) } let!(:web_push_subscription) { Fabricate(:web_push_subscription, user: user, access_token: access_token) }
let(:redis_pipeline_stub) { instance_double(Redis::PipelinedConnection, publish: nil) } let(:redis_pipeline_stub) { instance_double(Redis::PipelinedConnection, publish: nil) }
before do before { allow(redis).to receive(:pipelined).and_yield(redis_pipeline_stub) }
sign_in user, scope: :user
allow(redis).to receive(:pipelined).and_yield(redis_pipeline_stub) context 'when signed in' do
end before { sign_in user }
it 'revokes access tokens for the application and removes subscriptions and sends kill payload to streaming' do it 'revokes access tokens for the application and removes subscriptions and sends kill payload to streaming' do
post :destroy, params: { id: application.id } expect { subject }
.to change { Doorkeeper::AccessToken.where(application:).first.reload.revoked_at }.from(nil).to(be_present)
expect(Doorkeeper::AccessToken.where(application: application).first.revoked_at) .and change { Web::PushSubscription.where(user:).reload.count }.to(0)
.to_not be_nil
expect(Web::PushSubscription.where(user: user).count)
.to eq(0)
expect { web_push_subscription.reload } expect { web_push_subscription.reload }
.to raise_error(ActiveRecord::RecordNotFound) .to raise_error(ActiveRecord::RecordNotFound)
expect(redis_pipeline_stub) expect(redis_pipeline_stub)
.to have_received(:publish).with("timeline:access_token:#{access_token.id}", '{"event":"kill"}') .to have_received(:publish).with("timeline:access_token:#{access_token.id}", '{"event":"kill"}')
end end
end end
end
end end