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.

86 lines
2.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::AppsController, type: :controller do
  3. render_views
  4. describe 'POST #create' do
  5. let(:client_name) { 'Test app' }
  6. let(:scopes) { nil }
  7. let(:redirect_uris) { 'urn:ietf:wg:oauth:2.0:oob' }
  8. let(:website) { nil }
  9. let(:app_params) do
  10. {
  11. client_name: client_name,
  12. redirect_uris: redirect_uris,
  13. scopes: scopes,
  14. website: website,
  15. }
  16. end
  17. before do
  18. post :create, params: app_params
  19. end
  20. context 'with valid params' do
  21. it 'returns http success' do
  22. expect(response).to have_http_status(200)
  23. end
  24. it 'creates an OAuth app' do
  25. expect(Doorkeeper::Application.find_by(name: client_name)).to_not be_nil
  26. end
  27. it 'returns client ID and client secret' do
  28. json = body_as_json
  29. expect(json[:client_id]).to_not be_blank
  30. expect(json[:client_secret]).to_not be_blank
  31. end
  32. end
  33. context 'with an unsupported scope' do
  34. let(:scopes) { 'hoge' }
  35. it 'returns http unprocessable entity' do
  36. expect(response).to have_http_status(422)
  37. end
  38. end
  39. context 'with many duplicate scopes' do
  40. let(:scopes) { (%w(read) * 40).join(' ') }
  41. it 'returns http success' do
  42. expect(response).to have_http_status(200)
  43. end
  44. it 'only saves the scope once' do
  45. expect(Doorkeeper::Application.find_by(name: client_name).scopes.to_s).to eq 'read'
  46. end
  47. end
  48. context 'with a too-long name' do
  49. let(:client_name) { 'hoge' * 20 }
  50. it 'returns http unprocessable entity' do
  51. expect(response).to have_http_status(422)
  52. end
  53. end
  54. context 'with a too-long website' do
  55. let(:website) { 'https://foo.bar/' + ('hoge' * 2_000) }
  56. it 'returns http unprocessable entity' do
  57. expect(response).to have_http_status(422)
  58. end
  59. end
  60. context 'with a too-long redirect_uris' do
  61. let(:redirect_uris) { 'https://foo.bar/' + ('hoge' * 2_000) }
  62. it 'returns http unprocessable entity' do
  63. expect(response).to have_http_status(422)
  64. end
  65. end
  66. end
  67. end