summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-02-22 15:49:51 +0000
committerRémy Coutable <remy@rymai.me>2017-02-22 15:49:51 +0000
commit91335c59fd3a0a1dc5cd83835d086ac1699316b9 (patch)
tree6a7e1af66666c3e98b81b7945a382dabc8d7ba6c /spec
parent765d509a5bd0548961ea7ab1d86bf9302b5298b1 (diff)
parentd3425933dddf4e849199c06dd3ce00c212d0c6da (diff)
downloadgitlab-ce-91335c59fd3a0a1dc5cd83835d086ac1699316b9.tar.gz
Merge branch '27032-add-a-house-keeping-api-call' into 'master'
Add housekeeping endpoint for Projects API Closes #27032 See merge request !9421
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/projects_spec.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 4e90aae9279..2f1181b2e8c 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -1422,4 +1422,53 @@ describe API::Projects, api: true do
end
end
end
+
+ describe 'POST /projects/:id/housekeeping' do
+ let(:housekeeping) { Projects::HousekeepingService.new(project) }
+
+ before do
+ allow(Projects::HousekeepingService).to receive(:new).with(project).and_return(housekeeping)
+ end
+
+ context 'when authenticated as owner' do
+ it 'starts the housekeeping process' do
+ expect(housekeeping).to receive(:execute).once
+
+ post api("/projects/#{project.id}/housekeeping", user)
+
+ expect(response).to have_http_status(201)
+ end
+
+ context 'when housekeeping lease is taken' do
+ it 'returns conflict' do
+ expect(housekeeping).to receive(:execute).once.and_raise(Projects::HousekeepingService::LeaseTaken)
+
+ post api("/projects/#{project.id}/housekeeping", user)
+
+ expect(response).to have_http_status(409)
+ expect(json_response['message']).to match(/Somebody already triggered housekeeping for this project/)
+ end
+ end
+ end
+
+ context 'when authenticated as developer' do
+ before do
+ project_member2
+ end
+
+ it 'returns forbidden error' do
+ post api("/projects/#{project.id}/housekeeping", user3)
+
+ expect(response).to have_http_status(403)
+ end
+ end
+
+ context 'when unauthenticated' do
+ it 'returns authentication error' do
+ post api("/projects/#{project.id}/housekeeping")
+
+ expect(response).to have_http_status(401)
+ end
+ end
+ end
end