Module: Brevio::Session::Testing
Overview
Module used to enable testing for controllers using the Brevio session. Mocks a login to a shared redis, with keys generated by the Brevio::Session::CookieJar.
Defined Under Namespace
Classes: Config
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#sessions ⇒ Object
Returns the value of attribute sessions.
Instance Method Summary collapse
-
#brevio_login(user, updated_at: Time.current.yesterday) ⇒ Object
Simulates a user with a shared Brevio session.
- #brevio_login_new_user(user_brevio_id, patch: nil, audit_company:) ⇒ Object
- #brevio_logout ⇒ Object
-
#set_cookie(value) ⇒ Object
rubocop:disable Naming/AccessorMethodName (set makes sense here).
- #setup!(logger:) ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
61 62 63 |
# File 'lib/brevio/session/testing.rb', line 61 def config @config end |
#sessions ⇒ Object
Returns the value of attribute sessions.
61 62 63 |
# File 'lib/brevio/session/testing.rb', line 61 def sessions @sessions end |
Instance Method Details
#brevio_login(user, updated_at: Time.current.yesterday) ⇒ Object
Simulates a user with a shared Brevio session. We can specify which brevio_id the mocked ID service should return (as well as a custom last updated_at timestamp).
The user needs to have the following methods defined: #brevio_id, #audit_company
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/brevio/session/testing.rb', line 13 def brevio_login(user, updated_at: Time.current.yesterday) redis_key = SecureRandom.hex(6) session_hash = { user_id: user.brevio_id, audit_company_id: user.audit_company.brevio_id, user_patch: user.patch, user_stamp: updated_at } Testing.config.logger.info "setting Brevio session to #{session_hash}" Testing.config.gem_config.redis.set( redis_key, session_hash ) Testing.config.gem_config.redis.set("brevio-id:audit-company:#{user.audit_company.brevio_id}:patch", user.audit_company.patch) (redis_key) end |
#brevio_login_new_user(user_brevio_id, patch: nil, audit_company:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/brevio/session/testing.rb', line 32 def brevio_login_new_user(user_brevio_id, patch: nil, audit_company:) redis_key = SecureRandom.hex(6) session_hash = { user_id: user_brevio_id, audit_company_id: audit_company.brevio_id, user_patch: patch || SecureRandom.hex(12), user_stamp: Time.current.yesterday } Testing.config.logger.info "setting Brevio session to #{session_hash}" Testing.config.gem_config.redis.set( redis_key, session_hash ) (redis_key) end |
#brevio_logout ⇒ Object
49 50 51 |
# File 'lib/brevio/session/testing.rb', line 49 def brevio_logout [Testing.config.gem_config.] = nil end |
#set_cookie(value) ⇒ Object
rubocop:disable Naming/AccessorMethodName (set makes sense here)
54 55 56 |
# File 'lib/brevio/session/testing.rb', line 54 def (value) [Testing.config.gem_config.] = value end |
#setup!(logger:) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/brevio/session/testing.rb', line 63 def setup!(logger:) self.config = Config.new config.logger = logger config.gem_config = Brevio::Session::Config.config config.logger.info '--- 👨🔬 Setting up Brevio Session gem for testing 👨🔬 ---' # Ensures we return a mocked value of the session, rather than something which depends on # the cryptographically signed value. # Brevio::Session::Cookies::Parse.send(:define_method, :perform!) do || raise NilSession if .nil? end end |