Class: Booth::Testing::Userland::OnboardingFirstTime

Inherits:
IncorporationTestCase show all
Defined in:
lib/booth/testing/userland/onboarding_first_time.rb

Instance Method Summary collapse

Methods included from Shortcuts

#assert_logged_in, #assert_logged_out, #assert_userland_view, #create_and_onboard, #login_with_passkey, #register_new_passkey, #soft_reset_session, #virtual_authenticators, #visit_namespaced

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/booth/testing/userland/onboarding_first_time.rb', line 7

def call
  before_test&.call

  alice = ::Booth::Models::Credential.create!(
    domain: ::Capybara.app_host.remove('http://'),
    username: 'alice',
    scope:,
  )

  after_credential&.call(credential_id: alice.id)

  bobby = ::Booth::Models::Credential.create!(
    domain: ::Capybara.app_host.remove('http://'),
    username: 'bobby',
    scope:,
  )

  after_credential&.call(credential_id: bobby.id)

  alices_onboarding = ::Booth::Models::Onboarding.create!(
    credential_id: alice.id,
  )

  bobbys_onboarding = ::Booth::Models::Onboarding.create!(
    credential_id: bobby.id,
  )

  # Onboard via URL

  visit_namespaced controller: :onboardings, action: :show,
                   params: { id: alices_onboarding.secret_key }

  assert_userland_view controller: :onboardings, step: :redeem

  click_on :submit

  # ------------------------ SIGNIFICANT TEST --------------------------------
  # Re-visiting the Onboarding later, shows the success of having redeemed it.
  # --------------------------------------------------------------------------
  assert_userland_view controller: :onboardings, step: :success

  visit_namespaced controller: :webauths, action: :index

  # ----- SIGNIFICANT TEST -----
  # Onboarding logs the user in.
  # ----------------------------
  assert_userland_view controller: :webauths, step: :index

  visit_namespaced controller: :onboardings, action: :show,
                   params: { id: alices_onboarding.secret_key }

  assert_userland_view controller: :onboardings, step: :success

  visit_namespaced controller: :onboardings, action: :show,
                   params: { id: bobbys_onboarding.secret_key }

  # -------------------- SIGNIFICANT TEST -------------------
  # Cannot onboard while the wrong user is already logged in.
  # ---------------------------------------------------------
  assert_userland_view controller: :onboardings, step: :wrong_user

  soft_reset_session

  visit_namespaced controller: :onboardings, action: :show,
                   params: { id: alices_onboarding.secret_key }

  # ------------ SIGNIFICANT TEST ---------------
  # Cannot redeem an already consumed Onboarding.
  # ---------------------------------------------
  assert_userland_view controller: :onboardings, step: :already_used
end