Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2015-12-10 20:04:40 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2015-12-11 20:02:09 +0300
commit3d9ce37a48615032c786913acdde1eedba351361 (patch)
tree97999e407b8823327b4558060b370af829fdbd1f /spec/requests
parent64bfd9d71a4017e0b5336a2c1565926f4b8beedd (diff)
Reimplement Trigger API
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/triggers_spec.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/spec/requests/api/triggers_spec.rb b/spec/requests/api/triggers_spec.rb
new file mode 100644
index 00000000000..899458e619e
--- /dev/null
+++ b/spec/requests/api/triggers_spec.rb
@@ -0,0 +1,80 @@
+require 'spec_helper'
+
+describe API::API do
+ include ApiHelpers
+
+ describe 'POST /projects/:project_id/trigger' do
+ let!(:trigger_token) { 'secure token' }
+ let!(:project) { FactoryGirl.create(:project) }
+ let!(:project2) { FactoryGirl.create(:empty_project) }
+ let!(:trigger) { FactoryGirl.create(:ci_trigger, project: project, token: trigger_token) }
+ let(:options) do
+ {
+ token: trigger_token
+ }
+ end
+
+ before do
+ stub_ci_commit_to_return_yaml_file
+ end
+
+ context 'Handles errors' do
+ it 'should return bad request if token is missing' do
+ post api("/projects/#{project.id}/trigger/builds"), ref: 'master'
+ expect(response.status).to eq(400)
+ end
+
+ it 'should return not found if project is not found' do
+ post api('/projects/0/refs/master/trigger/builds'), options.merge(ref: 'master')
+ expect(response.status).to eq(404)
+ end
+
+ it 'should return unauthorized if token is for different project' do
+ post api("/projects/#{project2.id}/trigger/builds"), options.merge(ref: 'master')
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context 'Have a commit' do
+ let(:commit) { project.ci_commits.last }
+
+ it 'should create builds' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'master')
+ expect(response.status).to eq(201)
+ commit.builds.reload
+ expect(commit.builds.size).to eq(2)
+ end
+
+ it 'should return bad request with no builds created if there\'s no commit for that ref' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(ref: 'other-branch')
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('No builds created')
+ end
+
+ context 'Validates variables' do
+ let(:variables) do
+ { 'TRIGGER_KEY' => 'TRIGGER_VALUE' }
+ end
+
+ it 'should validate variables to be a hash' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: 'value', refs: 'master')
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('variables needs to be a hash')
+ end
+
+ it 'should validate variables needs to be a map of key-valued strings' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: { key: %w(1 2) }, refs: 'master')
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('variables needs to be a map of key-valued strings')
+ end
+
+ it 'create trigger request with variables' do
+ post api("/projects/#{project.id}/trigger/builds"), options.merge(variables: variables, refs: 'master')
+ expect(response.status).to eq(201)
+ commit.builds.reload
+ expect(commit.builds.first.trigger_request.variables).to eq(variables)
+ end
+ end
+ end
+ end
+end