2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AutocompleteController do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { project.owner }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'GET users' do
|
2016-09-13 17:45:13 +05:30
|
|
|
let!(:user2) { create(:user) }
|
|
|
|
let!(:non_member) { create(:user) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'project members' do
|
2015-09-11 14:41:01 +05:30
|
|
|
before do
|
2016-09-13 17:45:13 +05:30
|
|
|
sign_in(user)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with project ID' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: project.id)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns the project members' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.map { |u| u["username"] }).to include(user.username)
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: 'unknown')
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(response).to have_gitlab_http_status(404) }
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'group members' do
|
|
|
|
let(:group) { create(:group) }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
|
|
|
before do
|
2016-09-13 17:45:13 +05:30
|
|
|
group.add_owner(user)
|
2018-03-17 18:26:18 +05:30
|
|
|
sign_in(user)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with group ID' do
|
|
|
|
before do
|
|
|
|
get(:users, group_id: group.id)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns the group members' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first["username"]).to eq user.username
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #users with unknown group ID' do
|
|
|
|
before do
|
|
|
|
get(:users, group_id: 'unknown')
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(response).to have_gitlab_http_status(404) }
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'non-member login for public project' do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:project) { create(:project, :public) }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
before do
|
2016-09-13 17:45:13 +05:30
|
|
|
sign_in(non_member)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with project ID' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: project.id, current_user: true)
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns the project members and non-members' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(2)
|
|
|
|
expect(json_response.map { |u| u['username'] }).to include(user.username, non_member.username)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'all users' do
|
2015-09-11 14:41:01 +05:30
|
|
|
before do
|
2016-09-13 17:45:13 +05:30
|
|
|
sign_in(user)
|
|
|
|
get(:users)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
|
|
|
it { expect(json_response.size).to eq User.count }
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
context 'user order' do
|
|
|
|
it 'shows exact matches first' do
|
|
|
|
reported_user = create(:user, username: 'reported_user', name: 'Doug')
|
|
|
|
user = create(:user, username: 'user', name: 'User')
|
|
|
|
user1 = create(:user, username: 'user1', name: 'Ian')
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
get(:users, search: 'user')
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
response_usernames = json_response.map { |user| user['username'] }
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
expect(response_usernames.take(3)).to match_array([user.username, reported_user.username, user1.username])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'limited users per page' do
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
25.times do
|
|
|
|
create(:user)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
sign_in(user)
|
2018-03-17 18:26:18 +05:30
|
|
|
get(:users)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
|
|
|
it { expect(json_response.size).to eq(20) }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'unauthenticated user' do
|
|
|
|
let(:public_project) { create(:project, :public) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with public project' do
|
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
public_project.add_guest(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
get(:users, project_id: public_project.id)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
|
|
|
it { expect(json_response.size).to eq 2 }
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: project.id)
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(response).to have_gitlab_http_status(404) }
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with unknown project' do
|
|
|
|
before do
|
|
|
|
get(:users, project_id: 'unknown')
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(response).to have_gitlab_http_status(404) }
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with inaccessible group' do
|
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
project.add_guest(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
get(:users, group_id: user.namespace.id)
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(response).to have_gitlab_http_status(404) }
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
describe 'GET #users with no project' do
|
|
|
|
before do
|
|
|
|
get(:users)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it { expect(json_response).to be_kind_of(Array) }
|
|
|
|
it { expect(json_response).to be_empty }
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'GET #users with todo filter' do
|
|
|
|
it 'gives an array of users' do
|
|
|
|
get :users, todo_filter: true
|
|
|
|
|
|
|
|
expect(response.status).to eq 200
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(json_response).to be_kind_of(Array)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'author of issuable included' do
|
|
|
|
context 'authenticated' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'includes the author' do
|
|
|
|
get(:users, author_id: non_member.id)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(json_response.first["username"]).to eq non_member.username
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'rejects non existent user ids' do
|
|
|
|
get(:users, author_id: 99999)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(json_response.collect { |u| u['id'] }).not_to include(99999)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'without authenticating' do
|
|
|
|
it 'returns empty result' do
|
|
|
|
get(:users, author_id: non_member.id)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(json_response).to be_empty
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'skip_users parameter included' do
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
it 'skips the user IDs passed' do
|
|
|
|
get(:users, skip_users: [user, user2].map(&:id))
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
response_user_ids = json_response.map { |user| user['id'] }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response_user_ids).to contain_exactly(non_member.id)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
context 'GET projects' do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:authorized_project) { create(:project) }
|
|
|
|
let(:authorized_search_project) { create(:project, name: 'rugged') }
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
before do
|
|
|
|
sign_in(user)
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'authorized projects' do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
authorized_project.add_maintainer(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(1)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(json_response.first['id']).to eq authorized_project.id
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(json_response.first['name_with_namespace']).to eq authorized_project.full_name
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'authorized projects and search' do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
authorized_project.add_maintainer(user)
|
|
|
|
authorized_search_project.add_maintainer(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID and search' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id, search: 'rugged')
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(1)
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(json_response.first['id']).to eq authorized_search_project.id
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(json_response.first['name_with_namespace']).to eq authorized_search_project.full_name
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
context 'authorized projects apply limit' do
|
|
|
|
before do
|
|
|
|
authorized_project2 = create(:project)
|
|
|
|
authorized_project3 = create(:project)
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
authorized_project.add_maintainer(user)
|
|
|
|
authorized_project2.add_maintainer(user)
|
|
|
|
authorized_project3.add_maintainer(user)
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
stub_const 'MoveToProjectFinder::PAGE_SIZE', 2
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq 2 # Of a total of 3
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized projects with offset' do
|
|
|
|
before do
|
|
|
|
authorized_project2 = create(:project)
|
|
|
|
authorized_project3 = create(:project)
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
authorized_project.add_maintainer(user)
|
|
|
|
authorized_project2.add_maintainer(user)
|
|
|
|
authorized_project3.add_maintainer(user)
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID and offset_id' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id, offset_id: authorized_project.id)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq 2 # Of a total of 3
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'authorized projects without admin_issue ability' do
|
2018-03-17 18:26:18 +05:30
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
authorized_project.add_guest(user)
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(user.can?(:admin_issue, authorized_project)).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #projects with project ID' do
|
|
|
|
before do
|
|
|
|
get(:projects, project_id: project.id)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'returns no projects' do
|
|
|
|
expect(json_response).to be_kind_of(Array)
|
|
|
|
expect(json_response.size).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'GET award_emojis' do
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let!(:award_emoji1) { create_list(:award_emoji, 2, user: user, name: 'thumbsup') }
|
|
|
|
let!(:award_emoji2) { create_list(:award_emoji, 1, user: user, name: 'thumbsdown') }
|
|
|
|
let!(:award_emoji3) { create_list(:award_emoji, 3, user: user, name: 'star') }
|
|
|
|
let!(:award_emoji4) { create_list(:award_emoji, 1, user: user, name: 'tea') }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
context 'unauthorized user' do
|
|
|
|
it 'returns empty json' do
|
|
|
|
get :award_emojis
|
|
|
|
|
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'sign in as user without award emoji' do
|
|
|
|
it 'returns empty json' do
|
|
|
|
sign_in(user2)
|
|
|
|
get :award_emojis
|
|
|
|
|
|
|
|
expect(json_response).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'sign in as user with award emoji' do
|
|
|
|
it 'returns json sorted by name count' do
|
|
|
|
sign_in(user)
|
|
|
|
get :award_emojis
|
|
|
|
|
|
|
|
expect(json_response.count).to eq 4
|
|
|
|
expect(json_response[0]).to match('name' => 'star')
|
|
|
|
expect(json_response[1]).to match('name' => 'thumbsup')
|
|
|
|
expect(json_response[2]).to match('name' => 'tea')
|
|
|
|
expect(json_response[3]).to match('name' => 'thumbsdown')
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|