2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-20 03:28:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-09-07 11:09:04 -04:00
|
|
|
RSpec.describe InvitesController, :snowplow do
|
2020-07-07 08:09:16 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
2020-09-04 17:08:41 -04:00
|
|
|
let(:member) { create(:project_member, :invited, invite_email: user.email) }
|
|
|
|
let(:raw_invite_token) { member.raw_invite_token }
|
2020-07-07 08:09:16 -04:00
|
|
|
let(:project_members) { member.source.users }
|
2020-08-25 14:10:49 -04:00
|
|
|
let(:md5_member_global_id) { Digest::MD5.hexdigest(member.to_global_id.to_s) }
|
2020-09-04 17:08:41 -04:00
|
|
|
let(:params) { { id: raw_invite_token } }
|
2020-09-07 11:09:04 -04:00
|
|
|
let(:snowplow_event) do
|
|
|
|
{
|
|
|
|
category: 'Growth::Acquisition::Experiment::InviteEmail',
|
|
|
|
label: md5_member_global_id,
|
|
|
|
property: group_type
|
|
|
|
}
|
|
|
|
end
|
2015-10-20 03:28:28 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
controller.instance_variable_set(:@member, member)
|
|
|
|
end
|
|
|
|
|
2020-07-07 08:09:16 -04:00
|
|
|
describe 'GET #show' do
|
2020-08-25 14:10:49 -04:00
|
|
|
subject(:request) { get :show, params: params }
|
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
context 'when logged in' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2020-07-07 08:09:16 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
it 'accepts user if invite email matches signed in user' do
|
|
|
|
expect do
|
|
|
|
request
|
|
|
|
end.to change { project_members.include?(user) }.from(false).to(true)
|
2020-07-07 08:09:16 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(flash[:notice]).to include 'You have been granted'
|
|
|
|
end
|
2020-07-07 08:09:16 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
it 'forces re-confirmation if email does not match signed in user' do
|
|
|
|
member.invite_email = 'bogus@email.com'
|
2020-08-25 14:10:49 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
expect do
|
|
|
|
request
|
|
|
|
end.not_to change { project_members.include?(user) }
|
2020-08-25 14:10:49 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(flash[:notice]).to be_nil
|
2020-08-25 14:10:49 -04:00
|
|
|
end
|
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
context 'when new_user_invite is not set' do
|
|
|
|
it 'does not track the user as experiment group' do
|
|
|
|
request
|
2020-09-07 11:09:04 -04:00
|
|
|
|
|
|
|
expect_no_snowplow_event
|
2020-09-04 17:08:41 -04:00
|
|
|
end
|
|
|
|
end
|
2020-08-25 14:10:49 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
context 'when new_user_invite is experiment' do
|
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'experiment' } }
|
2020-09-07 11:09:04 -04:00
|
|
|
let(:group_type) { 'experiment_group' }
|
2020-09-04 17:08:41 -04:00
|
|
|
|
|
|
|
it 'tracks the user as experiment group' do
|
|
|
|
request
|
2020-09-07 11:09:04 -04:00
|
|
|
|
|
|
|
expect_snowplow_event(snowplow_event.merge(action: 'opened'))
|
|
|
|
expect_snowplow_event(snowplow_event.merge(action: 'accepted'))
|
2020-09-04 17:08:41 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_user_invite is control' do
|
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'control' } }
|
2020-09-07 11:09:04 -04:00
|
|
|
let(:group_type) { 'control_group' }
|
2020-09-04 17:08:41 -04:00
|
|
|
|
|
|
|
it 'tracks the user as control group' do
|
|
|
|
request
|
2020-09-07 11:09:04 -04:00
|
|
|
|
|
|
|
expect_snowplow_event(snowplow_event.merge(action: 'opened'))
|
|
|
|
expect_snowplow_event(snowplow_event.merge(action: 'accepted'))
|
2020-09-04 17:08:41 -04:00
|
|
|
end
|
2020-08-25 14:10:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
context 'when not logged in' do
|
|
|
|
context 'when inviter is a member' do
|
|
|
|
it 'is redirected to a new session with invite email param' do
|
|
|
|
request
|
2020-08-25 14:10:49 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
expect(response).to redirect_to(new_user_session_path(invite_email: member.invite_email))
|
|
|
|
end
|
|
|
|
end
|
2020-08-25 14:10:49 -04:00
|
|
|
|
2020-09-04 17:08:41 -04:00
|
|
|
context 'when inviter is not a member' do
|
|
|
|
let(:params) { { id: '_bogus_token_' } }
|
|
|
|
|
|
|
|
it 'is redirected to a new session' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
2020-08-25 14:10:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #accept' do
|
2020-09-04 17:08:41 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2020-08-25 14:10:49 -04:00
|
|
|
|
|
|
|
subject(:request) { post :accept, params: params }
|
|
|
|
|
|
|
|
context 'when new_user_invite is not set' do
|
|
|
|
it 'does not track an event' do
|
|
|
|
request
|
2020-09-07 11:09:04 -04:00
|
|
|
|
|
|
|
expect_no_snowplow_event
|
2020-08-25 14:10:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_user_invite is experiment' do
|
2020-09-04 17:08:41 -04:00
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'experiment' } }
|
2020-09-07 11:09:04 -04:00
|
|
|
let(:group_type) { 'experiment_group' }
|
2020-08-25 14:10:49 -04:00
|
|
|
|
|
|
|
it 'tracks the user as experiment group' do
|
|
|
|
request
|
2020-09-07 11:09:04 -04:00
|
|
|
|
|
|
|
expect_snowplow_event(snowplow_event.merge(action: 'accepted'))
|
2020-08-25 14:10:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_user_invite is control' do
|
2020-09-04 17:08:41 -04:00
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'control' } }
|
2020-09-07 11:09:04 -04:00
|
|
|
let(:group_type) { 'control_group' }
|
2020-08-25 14:10:49 -04:00
|
|
|
|
|
|
|
it 'tracks the user as control group' do
|
|
|
|
request
|
2020-09-07 11:09:04 -04:00
|
|
|
|
|
|
|
expect_snowplow_event(snowplow_event.merge(action: 'accepted'))
|
2020-08-25 14:10:49 -04:00
|
|
|
end
|
|
|
|
end
|
2020-07-07 08:09:16 -04:00
|
|
|
end
|
2015-10-20 03:28:28 -04:00
|
|
|
end
|