You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Oauth::AuthorizedApplicationsController do
  4. render_views
  5. describe 'GET #index' do
  6. subject do
  7. get :index
  8. end
  9. shared_examples 'stores location for user' do
  10. it 'stores location for user' do
  11. subject
  12. expect(controller.stored_location_for(:user)).to eq "/oauth/authorized_applications"
  13. end
  14. end
  15. context 'when signed in' do
  16. before do
  17. sign_in Fabricate(:user), scope: :user
  18. end
  19. it 'returns http success' do
  20. subject
  21. expect(response).to have_http_status(200)
  22. end
  23. include_examples 'stores location for user'
  24. end
  25. context 'when not signed in' do
  26. it 'redirects' do
  27. subject
  28. expect(response).to redirect_to '/auth/sign_in'
  29. end
  30. include_examples 'stores location for user'
  31. end
  32. end
  33. describe 'DELETE #destroy' do
  34. let!(:user) { Fabricate(:user) }
  35. let!(:application) { Fabricate(:application) }
  36. let!(:access_token) { Fabricate(:accessible_access_token, application: application, resource_owner_id: user.id) }
  37. let!(:web_push_subscription) { Fabricate(:web_push_subscription, user: user, access_token: access_token) }
  38. before do
  39. sign_in user, scope: :user
  40. post :destroy, params: { id: application.id }
  41. end
  42. it 'revokes access tokens for the application' do
  43. expect(Doorkeeper::AccessToken.where(application: application).first.revoked_at).to_not be_nil
  44. end
  45. it 'removes subscriptions for the application\'s access tokens' do
  46. expect(Web::PushSubscription.where(user: user).count).to eq 0
  47. end
  48. end
  49. end