Migrate to request specs in `/api/v1/apps` (#25401)

pull/62/head
Daniel M Brasil 2023-06-14 04:48:48 -03:00 committed by GitHub
parent 4c5f62de99
commit a6407aa662
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 15 deletions

View File

@ -2,16 +2,18 @@
require 'rails_helper'
RSpec.describe Api::V1::AppsController do
render_views
RSpec.describe 'Apps' do
describe 'POST /api/v1/apps' do
subject do
post '/api/v1/apps', params: params
end
describe 'POST #create' do
let(:client_name) { 'Test app' }
let(:scopes) { nil }
let(:redirect_uris) { 'urn:ietf:wg:oauth:2.0:oob' }
let(:website) { nil }
let(:app_params) do
let(:params) do
{
client_name: client_name,
redirect_uris: redirect_uris,
@ -20,24 +22,26 @@ RSpec.describe Api::V1::AppsController do
}
end
before do
post :create, params: app_params
end
context 'with valid params' do
it 'returns http success' do
subject
expect(response).to have_http_status(200)
end
it 'creates an OAuth app' do
expect(Doorkeeper::Application.find_by(name: client_name)).to_not be_nil
subject
expect(Doorkeeper::Application.find_by(name: client_name)).to be_present
end
it 'returns client ID and client secret' do
json = body_as_json
subject
expect(json[:client_id]).to_not be_blank
expect(json[:client_secret]).to_not be_blank
body = body_as_json
expect(body[:client_id]).to be_present
expect(body[:client_secret]).to be_present
end
end
@ -45,6 +49,8 @@ RSpec.describe Api::V1::AppsController do
let(:scopes) { 'hoge' }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
end
@ -53,10 +59,14 @@ RSpec.describe Api::V1::AppsController do
let(:scopes) { (%w(read) * 40).join(' ') }
it 'returns http success' do
subject
expect(response).to have_http_status(200)
end
it 'only saves the scope once' do
subject
expect(Doorkeeper::Application.find_by(name: client_name).scopes.to_s).to eq 'read'
end
end
@ -65,6 +75,8 @@ RSpec.describe Api::V1::AppsController do
let(:client_name) { 'hoge' * 20 }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
end
@ -73,6 +85,8 @@ RSpec.describe Api::V1::AppsController do
let(:website) { "https://foo.bar/#{'hoge' * 2_000}" }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
end
@ -81,6 +95,19 @@ RSpec.describe Api::V1::AppsController do
let(:redirect_uris) { "https://foo.bar/#{'hoge' * 2_000}" }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
end
context 'without required params' do
let(:client_name) { '' }
let(:redirect_uris) { '' }
it 'returns http unprocessable entity' do
subject
expect(response).to have_http_status(422)
end
end