PageRenderTime 52ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/ee/spec/features/registrations/saas_user_registration_spec.rb

https://gitlab.com/zillemarco/gitlab
Ruby | 288 lines | 258 code | 17 blank | 13 comment | 0 complexity | df70ea79de87a6af284a47d3f8d317a2 MD5 | raw file
  1. # frozen_string_literal: true
  2. require 'spec_helper'
  3. RSpec.describe "User registration", :js, :saas do
  4. include AfterNextHelpers
  5. let(:service_with_success) do
  6. instance_double(GitlabSubscriptions::CreateTrialOrLeadService, execute: ServiceResponse.success)
  7. end
  8. before do
  9. stub_feature_flags(
  10. # This is an "experiment" that's not been cleaned up and is over a year old:
  11. # https://gitlab.com/gitlab-org/gitlab/-/issues/255170
  12. user_other_role_details: true,
  13. # This is an experiment that we want to clean up, but can't yet because of
  14. # query limit concerns:
  15. # https://gitlab.com/gitlab-org/gitlab/-/issues/350754
  16. combined_registration: true,
  17. # This is the feature flag for the new registration flows where the user is
  18. # required to provide company details when registering for their company in
  19. # both the standard registration and trial flows.
  20. about_your_company_registration_flow: true
  21. )
  22. stub_application_setting(
  23. # Saas doesn't require admin approval.
  24. require_admin_approval_after_user_signup: false
  25. )
  26. # The groups_and_projects_controller (on `click_on 'Create project'`) is over
  27. # the query limit threshold, so we have to adjust it.
  28. # https://gitlab.com/gitlab-org/gitlab/-/issues/338737
  29. stub_const('Gitlab::QueryLimiting::Transaction::THRESHOLD', 272)
  30. end
  31. def fill_in_sign_up_form(user)
  32. fill_in 'First name', with: user.first_name
  33. fill_in 'Last name', with: user.last_name
  34. fill_in 'Username', with: user.username
  35. fill_in 'Email', with: user.email
  36. fill_in 'Password', with: user.password
  37. end
  38. def fill_in_welcome_form
  39. select 'Other', from: 'user_role'
  40. fill_in 'What is your job title? (optional)', with: 'My role' # behind the user_other_role_details feature flag.
  41. select 'A different reason', from: 'user_registration_objective'
  42. fill_in 'Why are you signing up? (optional)', with: 'My reason'
  43. end
  44. def fill_in_company_form
  45. fill_in 'company_name', with: 'Test Company'
  46. select '1 - 99', from: 'company_size'
  47. select 'United States of America', from: 'country'
  48. select 'Florida', from: 'state'
  49. fill_in 'phone_number', with: '+1234567890'
  50. fill_in 'website_url', with: 'https://gitlab.com'
  51. end
  52. describe "when accepting an invite" do
  53. let_it_be(:user) { build(:user, name: 'Invited User') }
  54. let_it_be(:owner) { create(:user, name: 'John Doe') }
  55. let_it_be(:group) { create(:group, name: 'Test Group') }
  56. before do
  57. group.add_owner(owner)
  58. invitation = create(:group_member, :invited, :developer,
  59. invite_email: user.email,
  60. group: group,
  61. created_by: owner
  62. )
  63. visit invite_path(invitation.raw_invite_token, invite_type: Emails::Members::INITIAL_INVITE)
  64. fill_in_sign_up_form(user)
  65. click_on 'Register'
  66. end
  67. it "doesn't ask me what I would like to do" do
  68. expect(page).to have_content('Welcome to GitLab, Invited!')
  69. expect(page).not_to have_content('What would you like to do?')
  70. end
  71. it "sends me to the group activity page" do
  72. fill_in_welcome_form
  73. click_on 'Get started!'
  74. expect(page).to have_current_path(activity_group_path(group), ignore_query: true)
  75. expect(page).to have_content('You have been granted Developer access to group Test Group')
  76. end
  77. end
  78. describe "using the standard flow" do
  79. let_it_be(:user) { create(:user, name: 'Onboarding User') }
  80. before do
  81. sign_in user
  82. visit users_sign_up_welcome_path
  83. end
  84. it "presents the initial welcome step" do
  85. expect(page).to have_content('Welcome to GitLab, Onboarding!')
  86. fill_in_welcome_form
  87. end
  88. context "just for me" do
  89. before do
  90. fill_in_welcome_form
  91. choose 'Just me'
  92. check 'I\'d like to receive updates about GitLab via email'
  93. end
  94. context "wanting to join a project" do
  95. before do
  96. choose 'Join a project'
  97. click_on 'Continue'
  98. end
  99. it "takes me to my dashboard" do
  100. expect(page).to have_content 'This user doesn\'t have any personal projects'
  101. end
  102. it "signs me up for email updates" do
  103. expect(user.reload).to be_email_opted_in
  104. end
  105. end
  106. context "wanting to create a project" do
  107. # This flow is behind the combined_registration feature flag.
  108. before do
  109. choose 'Create a new project'
  110. click_on 'Continue'
  111. end
  112. it "creates my new group and project without a trial" do
  113. fill_in 'group_name', with: 'Test Group'
  114. fill_in 'blank_project_name', with: 'Test Project'
  115. click_on 'Create project'
  116. # We end up in the continuous onboarding flow here...
  117. expect(page).to have_content 'Get started with GitLab'
  118. # So have to verify the newly created project by navigating to our projects...
  119. visit projects_path
  120. # Where we have two projects, one being part of continuous onboarding.
  121. expect(page).to have_content 'Test Group / Test Project'
  122. expect(page).to have_content 'Test Group / Learn GitLab'
  123. end
  124. it "imports my existing project without a trial" do
  125. click_on 'Import'
  126. fill_in 'import_group_name', with: 'Test Group'
  127. click_on 'GitHub'
  128. expect(page).to have_content <<~MESSAGE.tr("\n", ' ')
  129. To connect GitHub repositories, you first need to authorize
  130. GitLab to access the list of your GitHub repositories.
  131. MESSAGE
  132. end
  133. end
  134. end
  135. context "for my company" do
  136. before do
  137. fill_in_welcome_form
  138. choose 'My company or team'
  139. end
  140. context "wanting to join a project" do
  141. before do
  142. choose 'Join a project'
  143. click_on 'Continue'
  144. end
  145. it "takes me to my dashboard" do
  146. expect(page).to have_content 'This user doesn\'t have any personal projects'
  147. end
  148. end
  149. context "wanting to create a project" do
  150. # This flow is behind the combined_registration and the
  151. # about_your_company_registration_flow feature flags.
  152. before do
  153. choose 'Create a new project'
  154. click_on 'Continue'
  155. end
  156. it "prompts for details about my company" do
  157. expect(page).to have_content 'About your company'
  158. fill_in_company_form
  159. end
  160. context "and opting into a trial" do
  161. before do
  162. fill_in_company_form
  163. click_button class: 'gl-toggle'
  164. expect(GitlabSubscriptions::CreateTrialOrLeadService).to receive(:new).with(
  165. user: user,
  166. params: ActionController::Parameters.new(
  167. company_name: 'Test Company',
  168. company_size: '1-99',
  169. phone_number: '+1234567890',
  170. country: 'US',
  171. state: 'FL',
  172. website_url: 'https://gitlab.com',
  173. trial: 'true',
  174. # these are the passed through params
  175. role: 'other',
  176. other_role: 'My role',
  177. registration_objective: 'other',
  178. jobs_to_be_done_other: 'My reason'
  179. ).permit!
  180. ).and_return(service_with_success)
  181. click_on 'Continue'
  182. end
  183. it "creates my new group and project with a trial" do
  184. fill_in 'group_name', with: 'Test Group'
  185. fill_in 'blank_project_name', with: 'Test Project'
  186. expect_next(GitlabSubscriptions::ApplyTrialService).to receive(:execute).with({
  187. uid: user.id,
  188. trial_user: hash_including(
  189. namespace_id: anything,
  190. gitlab_com_trial: true,
  191. sync_to_gl: true
  192. )
  193. }).and_return(success: true)
  194. click_on 'Create project'
  195. expect(page).to have_content 'Get started with GitLab'
  196. end
  197. end
  198. context "without a trial" do
  199. before do
  200. fill_in_company_form
  201. expect(GitlabSubscriptions::CreateTrialOrLeadService).to receive(:new).with(
  202. user: user,
  203. params: hash_including(
  204. trial: 'false',
  205. # these are the passed through params
  206. role: 'other',
  207. other_role: 'My role',
  208. registration_objective: 'other',
  209. jobs_to_be_done_other: 'My reason'
  210. )
  211. ).and_return(service_with_success)
  212. click_on 'Continue'
  213. end
  214. it "creates my new group and project without a trial" do
  215. fill_in 'group_name', with: 'Test Group'
  216. fill_in 'blank_project_name', with: 'Test Project'
  217. click_on 'Create project'
  218. # We end up in the continuous onboarding flow here...
  219. expect(page).to have_content 'Get started with GitLab'
  220. # So have to verify the newly created project by navigating to our projects...
  221. visit projects_path
  222. # Where we have two projects, one being part of continuous onboarding.
  223. expect(page).to have_content 'Test Group / Test Project'
  224. expect(page).to have_content 'Test Group / Learn GitLab'
  225. end
  226. end
  227. end
  228. end
  229. end
  230. end