2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
RSpec.describe InvitesController, :snowplow do
|
2020-07-28 23:09:34 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:member) { create(:project_member, :invited, invite_email: user.email) }
|
|
|
|
let(:raw_invite_token) { member.raw_invite_token }
|
2020-07-28 23:09:34 +05:30
|
|
|
let(:project_members) { member.source.users }
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:md5_member_global_id) { Digest::MD5.hexdigest(member.to_global_id.to_s) }
|
|
|
|
let(:params) { { id: raw_invite_token } }
|
|
|
|
let(:snowplow_event) do
|
|
|
|
{
|
|
|
|
category: 'Growth::Acquisition::Experiment::InviteEmail',
|
|
|
|
label: md5_member_global_id,
|
|
|
|
property: group_type
|
|
|
|
}
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
shared_examples 'invalid token' do
|
|
|
|
context 'when invite token is not valid' do
|
|
|
|
let(:params) { { id: '_bogus_token_' } }
|
|
|
|
|
|
|
|
it 'renders the 404 page' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples "tracks the 'accepted' event for the invitation reminders experiment" do
|
|
|
|
before do
|
|
|
|
stub_experiment(invitation_reminders: true)
|
|
|
|
allow(Gitlab::Experimentation).to receive(:enabled_for_attribute?).with(:invitation_reminders, member.invite_email).and_return(experimental_group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when in the control group' do
|
|
|
|
let(:experimental_group) { false }
|
|
|
|
|
|
|
|
it "tracks the 'accepted' event" do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect_snowplow_event(
|
|
|
|
category: 'Growth::Acquisition::Experiment::InvitationReminders',
|
|
|
|
label: md5_member_global_id,
|
|
|
|
property: 'control_group',
|
|
|
|
action: 'accepted'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when in the experimental group' do
|
|
|
|
let(:experimental_group) { true }
|
|
|
|
|
|
|
|
it "tracks the 'accepted' event" do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect_snowplow_event(
|
|
|
|
category: 'Growth::Acquisition::Experiment::InvitationReminders',
|
|
|
|
label: md5_member_global_id,
|
|
|
|
property: 'experimental_group',
|
|
|
|
action: 'accepted'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
describe 'GET #show' do
|
2020-11-24 15:15:51 +05:30
|
|
|
subject(:request) { get :show, params: params }
|
|
|
|
|
|
|
|
context 'when logged in' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(flash[:notice]).to include 'You have been granted'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'forces re-confirmation if email does not match signed in user' do
|
2021-01-03 14:25:43 +05:30
|
|
|
member.update!(invite_email: 'bogus@email.com')
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
expect do
|
|
|
|
request
|
|
|
|
end.not_to change { project_members.include?(user) }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(flash[:notice]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_user_invite is not set' do
|
|
|
|
it 'does not track the user as experiment group' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect_no_snowplow_event
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_user_invite is experiment' do
|
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'experiment' } }
|
|
|
|
let(:group_type) { 'experiment_group' }
|
|
|
|
|
|
|
|
it 'tracks the user as experiment group' do
|
|
|
|
request
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect_snowplow_event(**snowplow_event.merge(action: 'opened'))
|
|
|
|
expect_snowplow_event(**snowplow_event.merge(action: 'accepted'))
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_user_invite is control' do
|
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'control' } }
|
|
|
|
let(:group_type) { 'control_group' }
|
|
|
|
|
|
|
|
it 'tracks the user as control group' do
|
|
|
|
request
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect_snowplow_event(**snowplow_event.merge(action: 'opened'))
|
|
|
|
expect_snowplow_event(**snowplow_event.merge(action: 'accepted'))
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it_behaves_like "tracks the 'accepted' event for the invitation reminders experiment"
|
|
|
|
it_behaves_like 'invalid token'
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path(invite_email: member.invite_email))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #accept' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:request) { post :accept, params: params }
|
|
|
|
|
|
|
|
context 'when new_user_invite is not set' do
|
|
|
|
it 'does not track an event' do
|
|
|
|
request
|
|
|
|
|
|
|
|
expect_no_snowplow_event
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new_user_invite is experiment' do
|
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'experiment' } }
|
|
|
|
let(:group_type) { 'experiment_group' }
|
|
|
|
|
|
|
|
it 'tracks the user as experiment group' do
|
|
|
|
request
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect_snowplow_event(**snowplow_event.merge(action: 'accepted'))
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'when new_user_invite is control' do
|
|
|
|
let(:params) { { id: raw_invite_token, new_user_invite: 'control' } }
|
|
|
|
let(:group_type) { 'control_group' }
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it 'tracks the user as control group' do
|
|
|
|
request
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
expect_snowplow_event(**snowplow_event.merge(action: 'accepted'))
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
it_behaves_like "tracks the 'accepted' event for the invitation reminders experiment"
|
|
|
|
it_behaves_like 'invalid token'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #decline for link in UI' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:request) { post :decline, params: params }
|
|
|
|
|
|
|
|
it_behaves_like 'invalid token'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #decline for link in email' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:request) { get :decline, params: params }
|
|
|
|
|
|
|
|
it_behaves_like 'invalid token'
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|