diff options
Diffstat (limited to 'spec/controllers/projects/web_ide_schemas_controller_spec.rb')
-rw-r--r-- | spec/controllers/projects/web_ide_schemas_controller_spec.rb | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/spec/controllers/projects/web_ide_schemas_controller_spec.rb b/spec/controllers/projects/web_ide_schemas_controller_spec.rb new file mode 100644 index 00000000000..fbec941aecc --- /dev/null +++ b/spec/controllers/projects/web_ide_schemas_controller_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::WebIdeSchemasController do + let_it_be(:developer) { create(:user) } + let_it_be(:project) { create(:project, :private, :repository, namespace: developer.namespace) } + + before do + project.add_developer(developer) + + sign_in(user) + end + + describe 'GET show' do + let(:user) { developer } + let(:branch) { 'master' } + + subject do + get :show, params: { + namespace_id: project.namespace.to_param, + project_id: project, + branch: branch, + filename: 'package.json' + } + end + + before do + allow_next_instance_of(::Ide::SchemasConfigService) do |instance| + allow(instance).to receive(:execute).and_return(result) + end + end + + context 'when branch is invalid' do + let(:branch) { 'non-existent' } + + it 'returns 422' do + subject + + expect(response).to have_gitlab_http_status(:unprocessable_entity) + end + end + + context 'when a valid schema exists' do + let(:result) { { status: :success, schema: { schema: 'Sample Schema' } } } + + it 'returns the schema' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(response.body).to eq('{"schema":"Sample Schema"}') + end + end + + context 'when an error occurs parsing the schema' do + let(:result) { { status: :error, message: 'Some error occured' } } + + it 'returns 422 with the error' do + subject + + expect(response).to have_gitlab_http_status(:unprocessable_entity) + expect(response.body).to eq('{"status":"error","message":"Some error occured"}') + end + end + end +end |