1
0
Fork 0
forked from fedi/mastodon

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

This commit is contained in:
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

View file

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