credentials_controller_spec.rb 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Api::V1::Apps::CredentialsController do
  4. render_views
  5. let(:token) { Fabricate(:accessible_access_token, scopes: 'read', application: Fabricate(:application)) }
  6. context 'with an oauth token' do
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #show' do
  11. before do
  12. get :show
  13. end
  14. it 'returns http success' do
  15. expect(response).to have_http_status(200)
  16. end
  17. it 'does not contain client credentials' do
  18. json = body_as_json
  19. expect(json).to_not have_key(:client_secret)
  20. expect(json).to_not have_key(:client_id)
  21. end
  22. end
  23. end
  24. context 'without an oauth token' do
  25. before do
  26. allow(controller).to receive(:doorkeeper_token).and_return(nil)
  27. end
  28. describe 'GET #show' do
  29. it 'returns http unauthorized' do
  30. get :show
  31. expect(response).to have_http_status(401)
  32. end
  33. end
  34. end
  35. end