2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'spec_helper'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
RSpec.describe 'Profile > Account', :js, feature_category: :user_profile do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:user) { create(:user, username: 'foo') }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
describe 'Service sign-in' do
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'when an identity does not exist' do
|
|
|
|
before do
|
|
|
|
allow(Devise).to receive_messages(omniauth_configs: { google_oauth2: {} })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows the user to connect' do
|
|
|
|
visit profile_account_path
|
|
|
|
|
|
|
|
expect(page).to have_link('Connect Google', href: '/users/auth/google_oauth2')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when an identity already exists' do
|
|
|
|
before do
|
|
|
|
allow(Devise).to receive_messages(omniauth_configs: { twitter: {}, saml: {} })
|
|
|
|
|
|
|
|
create(:identity, user: user, provider: :twitter)
|
|
|
|
create(:identity, user: user, provider: :saml)
|
|
|
|
|
|
|
|
visit profile_account_path
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows the user to disconnect when there is an existing identity' do
|
2021-01-29 00:20:46 +05:30
|
|
|
expect(page).to have_link('Disconnect Twitter', href: '/-/profile/account/unlink?provider=twitter')
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows active for a provider that is not allowed to unlink' do
|
|
|
|
expect(page).to have_content('Saml Active')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe 'Change username' do
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:new_username) { 'bar' }
|
|
|
|
let(:new_user_path) { "/#{new_username}" }
|
|
|
|
let(:old_user_path) { "/#{user.username}" }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'the user is accessible via the new path' do
|
2017-08-17 22:00:37 +05:30
|
|
|
update_username(new_username)
|
|
|
|
visit new_user_path
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_current_path(new_user_path, ignore_query: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(find('.user-info')).to have_content(new_username)
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'the old user path redirects to the new path' do
|
2017-08-17 22:00:37 +05:30
|
|
|
update_username(new_username)
|
|
|
|
visit old_user_path
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_current_path(new_user_path, ignore_query: true)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(find('.user-info')).to have_content(new_username)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project' do
|
2018-11-08 19:23:39 +05:30
|
|
|
let!(:project) { create(:project, namespace: user.namespace) }
|
|
|
|
let(:new_project_path) { "/#{new_username}/#{project.path}" }
|
|
|
|
let(:old_project_path) { "/#{user.username}/#{project.path}" }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before(:context) do
|
|
|
|
TestEnv.clean_test_path
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
after do
|
2017-09-10 17:25:29 +05:30
|
|
|
TestEnv.clean_test_path
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'the project is accessible via the new path' do
|
2017-08-17 22:00:37 +05:30
|
|
|
update_username(new_username)
|
|
|
|
visit new_project_path
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_current_path(new_project_path, ignore_query: true)
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(find('.breadcrumbs')).to have_content(user.name)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'the old project path redirects to the new path' do
|
2017-08-17 22:00:37 +05:30
|
|
|
update_username(new_username)
|
|
|
|
visit old_project_path
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_current_path(new_project_path, ignore_query: true)
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(find('.breadcrumbs')).to have_content(user.name)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
describe 'Delete account' do
|
|
|
|
before do
|
|
|
|
create_list(:project, number_of_projects, namespace: user.namespace)
|
|
|
|
visit profile_account_path
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no personal projects' do
|
|
|
|
let(:number_of_projects) { 0 }
|
|
|
|
|
|
|
|
it 'does not show personal projects removal message' do
|
|
|
|
expect(page).not_to have_content(/\d personal projects? will be removed and cannot be restored/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when one personal project exists' do
|
|
|
|
let(:number_of_projects) { 1 }
|
|
|
|
|
|
|
|
it 'does show personal project removal message' do
|
|
|
|
expect(page).to have_content('1 personal project will be removed and cannot be restored')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when more than one personal projects exists' do
|
|
|
|
let(:number_of_projects) { 3 }
|
|
|
|
|
|
|
|
it 'shows pluralized personal project removal message' do
|
|
|
|
expect(page).to have_content('3 personal projects will be removed and cannot be restored')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def update_username(new_username)
|
|
|
|
allow(user.namespace).to receive(:move_dir)
|
|
|
|
visit profile_account_path
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
fill_in 'username-change-input', with: new_username
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.find('[data-testid="username-change-confirmation-modal"]').click
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
page.within('.modal') do
|
2021-01-29 00:20:46 +05:30
|
|
|
find('.js-modal-action-primary').click
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
|
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|