summaryrefslogtreecommitdiff
path: root/spec/requests/api
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api')
-rw-r--r--spec/requests/api/files_spec.rb2
-rw-r--r--spec/requests/api/merge_requests_spec.rb26
-rw-r--r--spec/requests/api/users_spec.rb171
3 files changed, 184 insertions, 15 deletions
diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb
index 6c7860511e8..8cb8790c339 100644
--- a/spec/requests/api/files_spec.rb
+++ b/spec/requests/api/files_spec.rb
@@ -110,7 +110,7 @@ describe API::API, api: true do
expect(response.status).to eq(400)
end
- it "should return a 400 if satellite fails to create file" do
+ it "should return a 400 if fails to create file" do
allow_any_instance_of(Repository).to receive(:remove_file).and_return(false)
delete api("/projects/#{project.id}/repository/files", user), valid_params
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index 29db035b2de..942768fa254 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -148,7 +148,7 @@ describe API::API, api: true do
it "should return merge_request" do
post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request',
- source_branch: 'stable',
+ source_branch: 'feature_conflict',
target_branch: 'master',
author: user,
labels: 'label, label2'
@@ -171,20 +171,20 @@ describe API::API, api: true do
it "should return 400 when target_branch is missing" do
post api("/projects/#{project.id}/merge_requests", user),
- title: "Test merge_request", source_branch: "stable", author: user
+ title: "Test merge_request", source_branch: "markdown", author: user
expect(response.status).to eq(400)
end
it "should return 400 when title is missing" do
post api("/projects/#{project.id}/merge_requests", user),
- target_branch: 'master', source_branch: 'stable'
+ target_branch: 'master', source_branch: 'markdown'
expect(response.status).to eq(400)
end
it 'should return 400 on invalid label names' do
post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request',
- source_branch: 'stable',
+ source_branch: 'markdown',
target_branch: 'master',
author: user,
labels: 'label, ?'
@@ -198,7 +198,7 @@ describe API::API, api: true do
before do
post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request',
- source_branch: 'stable',
+ source_branch: 'feature_conflict',
target_branch: 'master',
author: user
@mr = MergeRequest.all.last
@@ -208,7 +208,7 @@ describe API::API, api: true do
expect do
post api("/projects/#{project.id}/merge_requests", user),
title: 'New test merge_request',
- source_branch: 'stable',
+ source_branch: 'feature_conflict',
target_branch: 'master',
author: user
end.to change { MergeRequest.count }.by(0)
@@ -228,7 +228,8 @@ describe API::API, api: true do
it "should return merge_request" do
post api("/projects/#{fork_project.id}/merge_requests", user2),
- title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
+ title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master",
+ author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
expect(response.status).to eq(201)
expect(json_response['title']).to eq('Test merge_request')
expect(json_response['description']).to eq('Test description for Test merge_request')
@@ -258,7 +259,7 @@ describe API::API, api: true do
it "should return 400 when title is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2),
- target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: project.id
+ target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id
expect(response.status).to eq(400)
end
@@ -267,7 +268,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request',
target_branch: 'master',
- source_branch: 'stable',
+ source_branch: 'markdown',
author: user,
target_project_id: fork_project.id
expect(response.status).to eq(422)
@@ -277,7 +278,7 @@ describe API::API, api: true do
post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request',
target_branch: 'master',
- source_branch: 'stable',
+ source_branch: 'markdown',
author: user2,
target_project_id: unrelated_project.id
expect(response.status).to eq(422)
@@ -286,7 +287,7 @@ describe API::API, api: true do
it "should return 201 when target_branch is specified and for the same project" do
post api("/projects/#{fork_project.id}/merge_requests", user2),
- title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: fork_project.id
+ title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id
expect(response.status).to eq(201)
end
end
@@ -302,9 +303,6 @@ describe API::API, api: true do
describe "PUT /projects/:id/merge_request/:merge_request_id/merge" do
it "should return merge_request in case of success" do
- allow_any_instance_of(MergeRequest).
- to receive_messages(can_be_merged?: true, automerge!: true)
-
put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user)
expect(response.status).to eq(200)
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index c4dd1f76cf2..f2aa369985e 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -6,6 +6,7 @@ describe API::API, api: true do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
let(:key) { create(:key, user: user) }
+ let(:email) { create(:email, user: user) }
describe "GET /users" do
context "when unauthenticated" do
@@ -384,6 +385,87 @@ describe API::API, api: true do
end
end
+ describe "POST /users/:id/emails" do
+ before { admin }
+
+ it "should not create invalid email" do
+ post api("/users/#{user.id}/emails", admin), {}
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('400 (Bad request) "email" not given')
+ end
+
+ it "should create email" do
+ email_attrs = attributes_for :email
+ expect do
+ post api("/users/#{user.id}/emails", admin), email_attrs
+ end.to change{ user.emails.count }.by(1)
+ end
+ end
+
+ describe 'GET /user/:uid/emails' do
+ before { admin }
+
+ context 'when unauthenticated' do
+ it 'should return authentication error' do
+ get api("/users/#{user.id}/emails")
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context 'when authenticated' do
+ it 'should return 404 for non-existing user' do
+ get api('/users/999999/emails', admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 User Not Found')
+ end
+
+ it 'should return array of emails' do
+ user.emails << email
+ user.save
+ get api("/users/#{user.id}/emails", admin)
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.first['email']).to eq(email.email)
+ end
+ end
+ end
+
+ describe 'DELETE /user/:uid/emails/:id' do
+ before { admin }
+
+ context 'when unauthenticated' do
+ it 'should return authentication error' do
+ delete api("/users/#{user.id}/emails/42")
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context 'when authenticated' do
+ it 'should delete existing email' do
+ user.emails << email
+ user.save
+ expect do
+ delete api("/users/#{user.id}/emails/#{email.id}", admin)
+ end.to change { user.emails.count }.by(-1)
+ expect(response.status).to eq(200)
+ end
+
+ it 'should return 404 error if user not found' do
+ user.emails << email
+ user.save
+ delete api("/users/999999/emails/#{email.id}", admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 User Not Found')
+ end
+
+ it 'should return 404 error if email not foud' do
+ delete api("/users/#{user.id}/emails/42", admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 Email Not Found')
+ end
+ end
+ end
+
describe "DELETE /users/:id" do
before { admin }
@@ -528,6 +610,95 @@ describe API::API, api: true do
end
end
+ describe "GET /user/emails" do
+ context "when unauthenticated" do
+ it "should return authentication error" do
+ get api("/user/emails")
+ expect(response.status).to eq(401)
+ end
+ end
+
+ context "when authenticated" do
+ it "should return array of emails" do
+ user.emails << email
+ user.save
+ get api("/user/emails", user)
+ expect(response.status).to eq(200)
+ expect(json_response).to be_an Array
+ expect(json_response.first["email"]).to eq(email.email)
+ end
+ end
+ end
+
+ describe "GET /user/emails/:id" do
+ it "should return single email" do
+ user.emails << email
+ user.save
+ get api("/user/emails/#{email.id}", user)
+ expect(response.status).to eq(200)
+ expect(json_response["email"]).to eq(email.email)
+ end
+
+ it "should return 404 Not Found within invalid ID" do
+ get api("/user/emails/42", user)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 Not found')
+ end
+
+ it "should return 404 error if admin accesses user's email" do
+ user.emails << email
+ user.save
+ admin
+ get api("/user/emails/#{email.id}", admin)
+ expect(response.status).to eq(404)
+ expect(json_response['message']).to eq('404 Not found')
+ end
+ end
+
+ describe "POST /user/emails" do
+ it "should create email" do
+ email_attrs = attributes_for :email
+ expect do
+ post api("/user/emails", user), email_attrs
+ end.to change{ user.emails.count }.by(1)
+ expect(response.status).to eq(201)
+ end
+
+ it "should return a 401 error if unauthorized" do
+ post api("/user/emails"), email: 'some email'
+ expect(response.status).to eq(401)
+ end
+
+ it "should not create email with invalid email" do
+ post api("/user/emails", user), {}
+ expect(response.status).to eq(400)
+ expect(json_response['message']).to eq('400 (Bad request) "email" not given')
+ end
+ end
+
+ describe "DELETE /user/emails/:id" do
+ it "should delete existed email" do
+ user.emails << email
+ user.save
+ expect do
+ delete api("/user/emails/#{email.id}", user)
+ end.to change{user.emails.count}.by(-1)
+ expect(response.status).to eq(200)
+ end
+
+ it "should return success if email ID not found" do
+ delete api("/user/emails/42", user)
+ expect(response.status).to eq(200)
+ end
+
+ it "should return 401 error if unauthorized" do
+ user.emails << email
+ user.save
+ delete api("/user/emails/#{email.id}")
+ expect(response.status).to eq(401)
+ end
+ end
+
describe 'PUT /user/:id/block' do
before { admin }
it 'should block existing user' do