gitlab-org--gitlab-foss/spec/requests/ci/api/lint_spec.rb

51 lines
1.4 KiB
Ruby
Raw Normal View History

2016-08-18 06:50:01 +00:00
require 'spec_helper'
describe Ci::API::API do
include ApiHelpers
2016-08-23 10:12:21 +00:00
let(:user) { create(:user) }
let(:yaml_content) do
2016-08-18 06:50:01 +00:00
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
2016-08-23 10:12:21 +00:00
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'), { private_token: user.private_token, content: yaml_content }
2016-08-18 06:50:01 +00:00
2016-08-23 10:12:21 +00:00
expect(response).to have_http_status(201)
expect(json_response).to be_an Hash
expect(json_response['status']).to eq('syntax is correct')
end
end
context "unauthorized user" do
it "does not validate content" do
post ci_api('/lint'), { content: yaml_content }
2016-08-18 06:50:01 +00:00
2016-08-23 10:12:21 +00:00
expect(response).to have_http_status(401)
2016-08-18 06:50:01 +00:00
end
end
end
2016-08-23 10:12:21 +00:00
context "with invalid .gitlab_ci.yml content" do
it "validate content" do
2016-08-23 10:56:24 +00:00
post ci_api('/lint'), { private_token: user.private_token, content: 'invalid content' }
2016-08-23 10:12:21 +00:00
expect(response).to have_http_status(500)
expect(json_response['status']).to eq('syntax is incorrect')
end
end
context "no content" do
it "shows error message" do
post ci_api('/lint'), { private_token: user.private_token }
expect(response).to have_http_status(400)
expect(json_response['message']).to eq('Please provide content of .gitlab-ci.yml')
end
end
2016-08-18 06:50:01 +00:00
end
end