diff options
Diffstat (limited to 'spec/controllers/invites_controller_spec.rb')
-rw-r--r-- | spec/controllers/invites_controller_spec.rb | 89 |
1 files changed, 80 insertions, 9 deletions
diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index a083cfac981..75a972d2f95 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -17,8 +17,53 @@ RSpec.describe InvitesController, :snowplow do } end - before do - controller.instance_variable_set(:@member, member) + 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 end describe 'GET #show' do @@ -39,7 +84,7 @@ RSpec.describe InvitesController, :snowplow do end it 'forces re-confirmation if email does not match signed in user' do - member.invite_email = 'bogus@email.com' + member.update!(invite_email: 'bogus@email.com') expect do request @@ -64,8 +109,8 @@ RSpec.describe InvitesController, :snowplow do it 'tracks the user as experiment group' do request - expect_snowplow_event(snowplow_event.merge(action: 'opened')) - expect_snowplow_event(snowplow_event.merge(action: 'accepted')) + expect_snowplow_event(**snowplow_event.merge(action: 'opened')) + expect_snowplow_event(**snowplow_event.merge(action: 'accepted')) end end @@ -76,10 +121,13 @@ RSpec.describe InvitesController, :snowplow do it 'tracks the user as control group' do request - expect_snowplow_event(snowplow_event.merge(action: 'opened')) - expect_snowplow_event(snowplow_event.merge(action: 'accepted')) + expect_snowplow_event(**snowplow_event.merge(action: 'opened')) + expect_snowplow_event(**snowplow_event.merge(action: 'accepted')) end end + + it_behaves_like "tracks the 'accepted' event for the invitation reminders experiment" + it_behaves_like 'invalid token' end context 'when not logged in' do @@ -125,7 +173,7 @@ RSpec.describe InvitesController, :snowplow do it 'tracks the user as experiment group' do request - expect_snowplow_event(snowplow_event.merge(action: 'accepted')) + expect_snowplow_event(**snowplow_event.merge(action: 'accepted')) end end @@ -136,8 +184,31 @@ RSpec.describe InvitesController, :snowplow do it 'tracks the user as control group' do request - expect_snowplow_event(snowplow_event.merge(action: 'accepted')) + expect_snowplow_event(**snowplow_event.merge(action: 'accepted')) end end + + 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' end end |