Module: Zaikio::OAuthClient::TestHelper

Extended by:
ActiveSupport::Concern
Included in:
SystemTestHelper
Defined in:
lib/zaikio/oauth_client/test_helper.rb

Defined Under Namespace

Classes: TestSessionController, VirtualAccessToken

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_active_access_token(id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/zaikio/oauth_client/test_helper.rb', line 9

def find_active_access_token(id)
  return unless id.to_s.starts_with?("AT:")

  _, audience, person_id = id.split(":")

  VirtualAccessToken.new(
    id: id,
    bearer_id: person_id,
    audience: audience,
    bearer_type: "Person",
    expired?: false
  )
end

Instance Method Details

#get_session(key) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/zaikio/oauth_client/test_helper.rb', line 50

def get_session(key)
  get "/zaikio/oauth_client/test_helper/get_session", params: { key: key }

  if response.status == 204
    nil
  else
    response.body
  end
end

#logged_in_as(person, access_token: nil, client_name: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/zaikio/oauth_client/test_helper.rb', line 64

def logged_in_as(person, access_token: nil, client_name: nil)
  client_name ||= Zaikio::OAuthClient.client_name ||
                  Zaikio::OAuthClient.configuration.all_client_names.first
  set_session(
    :zaikio_access_token_id,
    access_token&.id || "AT:#{client_name}:#{person.id}"
  )

  # Deprecated please use zaikio_access_token_id
  set_session(:zaikio_person_id, person.id)
end

#set_session(key, value) ⇒ Object



60
61
62
# File 'lib/zaikio/oauth_client/test_helper.rb', line 60

def set_session(key, value)
  get "/zaikio/oauth_client/test_helper/session", params: { id: value, key: key }
end