summaryrefslogtreecommitdiff
path: root/spec/requests/ci/api/lint_spec.rb
blob: cc3d77f3b38ccbb40afe09803a779ea48e8481e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'

describe Ci::API::API do
  include ApiHelpers

  let(:user) { create(:user) }
  let(:yaml_content) do
    File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
  end

  describe 'POST /ci/lint' do
    context 'with valid .gitlab-ci.yaml content' do
      context 'authorized user' do
        it 'validate content' do
          post ci_api('/lint'), { content: yaml_content }

          expect(response).to have_http_status(200)
          expect(json_response).to be_an Hash
          expect(json_response['status']).to eq('valid')
        end
      end
    end

    context 'with invalid .gitlab_ci.yml content' do
      it 'validate content' do
        post ci_api('/lint'), { content: 'invalid content' }

        expect(response).to have_http_status(200)
        expect(json_response['status']).to eq('invalid')
      end
    end

    context 'no content parameters' do
      it 'shows error message' do
        post ci_api('/lint')

        expect(response).to have_http_status(400)
      end
    end
  end
end