Commit 4fbfaff7 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch...

Merge branch '328728-determine-if-we-should-ever-manually-need-to-accept-invite-for-an-existing-user' into 'master'

Clarify when manual acceptance of an invite may occur in tests

See merge request gitlab-org/gitlab!61795
parents 3f535e69 11b68bfe
......@@ -7,15 +7,12 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
let_it_be(:group) { create(:group, name: 'Owned') }
let_it_be(:project) { create(:project, :repository, namespace: group) }
let(:user) { create(:user, email: 'user@example.com') }
let(:group_invite) { group.group_members.invite.last }
before do
stub_application_setting(require_admin_approval_after_user_signup: false)
project.add_maintainer(owner)
group.add_owner(owner)
group.add_developer('user@example.com', owner)
group_invite.generate_invite_token!
end
def confirm_email(new_user)
......@@ -45,7 +42,16 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
click_button 'Get started!'
end
context 'when inviting a registered user' do
let(:invite_email) { 'user@example.com' }
before do
group.add_developer(invite_email, owner)
group_invite.generate_invite_token!
end
context 'when signed out' do
context 'when analyzing the redirects and forms from invite link click' do
before do
visit invite_path(group_invite.raw_invite_token)
end
......@@ -64,6 +70,15 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
it 'pre-fills the Email field on the sign up box with the invite_email from the invite' do
expect(find_field('Email').value).to eq(group_invite.invite_email)
end
end
context 'when invite is sent before account is created - ldap or social sign in for manual acceptance edge case' do
let(:user) { create(:user, email: 'user@example.com') }
context 'when invite clicked and not signed in' do
before do
visit invite_path(group_invite.raw_invite_token)
end
it 'sign in, grants access and redirects to group activity page' do
click_link 'Sign in'
......@@ -74,18 +89,83 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
end
end
context 'when signed in as an existing member' do
context 'when signed in and an invite link is clicked' do
context 'when an invite email is a secondary email for the user' do
let(:invite_email) { 'user_secondary@example.com' }
before do
sign_in(owner)
sign_in(user)
visit invite_path(group_invite.raw_invite_token)
end
it 'shows message user already a member' do
it 'sends user to the invite url and allows them to decline' do
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(page).to have_content("Note that this invitation was sent to #{invite_email}")
expect(page).to have_content("but you are signed in as #{user.to_reference} with email #{user.email}")
click_link('Decline')
expect(page).to have_content('You have declined the invitation')
expect(current_path).to eq(dashboard_projects_path)
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
it 'sends uer to the invite url and allows them to accept' do
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(page).to have_content("Note that this invitation was sent to #{invite_email}")
expect(page).to have_content("but you are signed in as #{user.to_reference} with email #{user.email}")
click_link('Accept invitation')
expect(page).to have_content('You have been granted')
expect(current_path).to eq(activity_group_path(group))
end
end
context 'when user is an existing member' do
before do
sign_in(owner)
visit invite_path(group_invite.raw_invite_token)
end
it 'shows message user already a member' do
expect(current_path).to eq(invite_path(group_invite.raw_invite_token))
expect(page).to have_link(owner.name, href: user_url(owner))
expect(page).to have_content('However, you are already a member of this group.')
end
end
end
context 'when declining the invitation from invitation reminder email' do
context 'when signed in' do
before do
sign_in(user)
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to dashboard' do
expect(current_path).to eq(dashboard_projects_path)
expect(page).to have_content('You have declined the invitation to join group Owned.')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
context 'when signed out with signup onboarding' do
before do
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to sign in page' do
expect(current_path).to eq(decline_invite_path(group_invite.raw_invite_token))
expect(page).not_to have_content('You have declined the invitation to join')
expect(page).to have_content('You successfully declined the invitation')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end
end
end
end
context 'when inviting an unregistered user' do
let(:new_user) { build_stubbed(:user) }
......@@ -243,64 +323,14 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
end
end
context 'when declining the invitation' do
context 'as an existing user' do
let(:group_invite) { create(:group_member, user: user, group: group, created_by: owner) }
context 'when signed in' do
before do
sign_in(user)
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to dashboard' do
expect(current_path).to eq(dashboard_projects_path)
expect(page).to have_content('You have declined the invitation to join group Owned.')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
context 'when signed out' do
before do
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and redirects to sign in page' do
expect(current_path).to eq(new_user_session_path)
expect(page).to have_content('You have declined the invitation to join group Owned.')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end
context 'as a non-existing user' do
before do
context 'when declining the invitation from invitation reminder email' do
it 'declines application and shows a decline page' do
visit decline_invite_path(group_invite.raw_invite_token)
end
it 'declines application and shows a decline page' do
expect(current_path).to eq(decline_invite_path(group_invite.raw_invite_token))
expect(page).to have_content('You successfully declined the invitation')
expect { group_invite.reload }.to raise_error ActiveRecord::RecordNotFound
end
end
end
context 'when accepting the invitation as an existing user' do
before do
sign_in(user)
visit invite_path(group_invite.raw_invite_token)
end
it 'grants access and redirects to the group activity page' do
expect(group.users.include?(user)).to be false
page.click_link 'Accept invitation'
expect(current_path).to eq(activity_group_path(group))
expect(page).to have_content('You have been granted Owner access to group Owned.')
expect(group.users.include?(user)).to be true
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment