Class: EyServicesFake::MockBackend

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_services_fake/mock_backend.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actors) ⇒ MockBackend

Returns a new instance of MockBackend.



61
62
63
# File 'lib/ey_services_fake/mock_backend.rb', line 61

def initialize(actors)
  @actors = actors
end

Instance Attribute Details

#actorsObject (readonly)

Returns the value of attribute actors.



60
61
62
# File 'lib/ey_services_fake/mock_backend.rb', line 60

def actors
  @actors
end

Class Method Details

.setup!(actors = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ey_services_fake/mock_backend.rb', line 9

def self.setup!(actors = {})
  unless actors[:awsm]
    require 'ey_services_fake/reacharound_awsm'
    actors[:awsm] = ReacharoundAwsm.new
  end
  unless actors[:service_provider]
    require 'ey_services_fake/mocking_bird_service'
    actors[:service_provider] = MockingBirdService.new
  end
  unless actors[:tresfiestas]
    actors[:tresfiestas] = tresfiestas_fake.new
  end
  new(actors)
end

.tresfiestas_fakeObject



4
5
6
7
# File 'lib/ey_services_fake/mock_backend.rb', line 4

def self.tresfiestas_fake
  require 'ey_services_fake/tresfiestas_fake'
  TresfiestasFake
end

Instance Method Details

#actor(role) ⇒ Object



65
66
67
# File 'lib/ey_services_fake/mock_backend.rb', line 65

def actor(role)
  @actors[role] or raise "No actor registered as #{role}, I have #{@actors.keys.inspect}"
end

#appObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/ey_services_fake/mock_backend.rb', line 49

def app
  this = self
  @app ||= Rack::Builder.new do
    this.actors.each do |k, actor|
      map "#{actor.base_url}/" do
        run this.app_for(k)
      end
    end
  end
end

#app_deploymentObject



157
158
159
160
161
162
163
164
# File 'lib/ey_services_fake/mock_backend.rb', line 157

def app_deployment
  app_deployment_hash = actor(:awsm).find_app_deployment([:id])
  unless app_deployment_hash
    actor(:awsm).create_app_deployment([:id], "myapp", "myenv", "production")
    app_deployment_hash = actor(:awsm).find_app_deployment([:id])
  end
  app_deployment_hash
end

#app_for(actor_name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ey_services_fake/mock_backend.rb', line 24

def app_for(actor_name)
  this = self
  @apps ||= {}
  @apps[actor_name] ||= Rack::Builder.new do
    this.actors.each do |k, actor|
      if actor.respond_to?(:extra_middlewares)
        self.instance_eval(&actor.extra_middlewares)
      end
    end
    if ENV["REQUEST_DEBUG"]
      require 'request_visualizer'
      use RequestVisualizer do |str|
        found = str
        this.actors.each do |k, actor|
          if str.match(actor.base_url)
            found = k.to_s
          end
        end
        found
      end
    end
    run this.actors[actor_name].app
  end
end

#awsmObject



77
78
79
80
81
82
83
84
# File 'lib/ey_services_fake/mock_backend.rb', line 77

def awsm
  awsm_hash = actor(:tresfiestas).find_awsm
  unless awsm_hash
    awsm_hash = actor(:tresfiestas).create_awsm(actor(:awsm).base_url, app_for(:awsm))
    actor(:awsm).setup(awsm_hash[:auth_id], awsm_hash[:auth_key], actor(:tresfiestas).base_url, app_for(:tresfiestas))
  end
  awsm_hash
end

#destroy_provisioned_serviceObject



178
179
180
# File 'lib/ey_services_fake/mock_backend.rb', line 178

def destroy_provisioned_service
  actor(:awsm).deprovision_service(provisioned_service[:id])
end

#destroy_service_accountObject



153
154
155
# File 'lib/ey_services_fake/mock_backend.rb', line 153

def 
  actor(:awsm).disable_service(service[:id], [:sso_account][:id], [:id])
end

#latest_invoiceObject



182
183
184
# File 'lib/ey_services_fake/mock_backend.rb', line 182

def latest_invoice
  actor(:tresfiestas).latest_invoice
end

#latest_status_messageObject



186
187
188
# File 'lib/ey_services_fake/mock_backend.rb', line 186

def latest_status_message
  actor(:tresfiestas).latest_status_message
end

#partnerObject



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ey_services_fake/mock_backend.rb', line 86

def partner
  partner_hash = actor(:tresfiestas).find_partner(sso_user)
  unless partner_hash
    partner_hash = actor(:tresfiestas).create_partner(sso_user, actor(:service_provider).base_url, app_for(:service_provider))
    @actors.values.each do |actor|
      if actor.respond_to?(:service_provider_setup)
        actor.service_provider_setup(partner_hash[:auth_id], partner_hash[:auth_key], actor(:service_provider).base_url, app_for(:service_provider))
      end
    end
    actor(:service_provider).setup(partner_hash[:auth_id], partner_hash[:auth_key], actor(:tresfiestas).base_url, app_for(:tresfiestas))
  end
  partner_hash
end

#provisioned_serviceObject



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/ey_services_fake/mock_backend.rb', line 166

def provisioned_service
   = self.
   = [:sso_account]
  app_deployment_hash = self.app_deployment
  provisioned_service_hash = actor(:tresfiestas).find_provisioned_service([:id], app_deployment_hash[:id])
  unless provisioned_service_hash
    actor(:awsm).provision_service([:id], [:id], app_deployment_hash[:id])
    provisioned_service_hash = actor(:tresfiestas).find_provisioned_service([:id], app_deployment_hash[:id])
  end
  provisioned_service_hash.merge(:service_account => , :app_deployment => app_deployment_hash)
end

#provisioned_service_sso_urlObject



202
203
204
# File 'lib/ey_services_fake/mock_backend.rb', line 202

def provisioned_service_sso_url
  actor(:awsm).provisioned_service_sso_url([:id], app_deployment[:id], sso_user, [:id])
end

#reset!Object



69
70
71
72
73
74
75
# File 'lib/ey_services_fake/mock_backend.rb', line 69

def reset!
  @app = nil
  @apps = nil
  @actors.values.each do |v|
    v.reset!
  end
end

#send_invoice(invoices_url, total_amount_cent, line_item_description) ⇒ Object



194
195
196
# File 'lib/ey_services_fake/mock_backend.rb', line 194

def send_invoice(invoices_url, total_amount_cent, line_item_description)
  actor(:service_provider).send_invoice(invoices_url, total_amount_cent, line_item_description)
end

#send_message(message_url, message_type, message_subject, message_body = nil) ⇒ Object



190
191
192
# File 'lib/ey_services_fake/mock_backend.rb', line 190

def send_message(message_url, message_type, message_subject, message_body = nil)
  actor(:service_provider).send_message(message_url, message_type, message_subject, message_body)
end

#serviceObject



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ey_services_fake/mock_backend.rb', line 100

def service
  partner_hash = self.partner
  service_hash = actor(:tresfiestas).find_service(partner_hash[:id])
  unless service_hash
    actor(:service_provider).register_service(partner_hash[:registration_url])
    service_hash = actor(:tresfiestas).find_service(partner_hash[:id])
  end
  if actor(:tresfiestas).respond_to?(:document_service)
    service_hash.merge!(:service_doc => actor(:tresfiestas).document_service(service_hash[:id]))
  end
  service_hash.merge(:partner => partner_hash)
end

#service_accountObject



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ey_services_fake/mock_backend.rb', line 141

def 
  service_enablement_hash = self.service_enablement
   = service_enablement_hash[:sso_account]
  service_hash = service_enablement_hash[:service]
   = actor(:tresfiestas).(service_hash[:id], [:id])
  unless 
    actor(:awsm).enable_service(service_hash[:id], [:id])
     = actor(:tresfiestas).(service_hash[:id], [:id])
  end
  .merge(:name => [:name], :service => service_hash, :sso_account => )
end

#service_account_sso_urlObject



198
199
200
# File 'lib/ey_services_fake/mock_backend.rb', line 198

def 
  actor(:awsm).(service[:id], sso_user, [:id])
end

#service_enablementObject



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ey_services_fake/mock_backend.rb', line 128

def service_enablement
   = self.
  service_hash = self.service

  unless actor(:tresfiestas).service_available_for_account?(service_hash[:id], [:id])
    actor(:tresfiestas).(service_hash[:id], [:id])
  end
  {
    :service => service_hash,
    :sso_account => ,
  }
end

#sso_accountObject



118
119
120
121
122
123
124
125
126
# File 'lib/ey_services_fake/mock_backend.rb', line 118

def 
  awsm #need to have setup awsm before you can create accounts!
  sso_user_something = sso_user #the sso_user is a somehting, not necessarily a hash
   = actor(:awsm).(sso_user_something)
  unless 
     = actor(:awsm).(sso_user_something)
  end
  
end

#sso_userObject



113
114
115
116
# File 'lib/ey_services_fake/mock_backend.rb', line 113

def sso_user
  awsm
  actor(:awsm).sso_user #allows for nils (some implementations of AWSM may decide this is ok)
end

#trigger_mock_user_deleteObject



210
211
212
# File 'lib/ey_services_fake/mock_backend.rb', line 210

def trigger_mock_user_delete
  actor(:tresfiestas).trigger_mock_user_delete(sso_user)
end

#trigger_mock_user_update(new_email) ⇒ Object



206
207
208
# File 'lib/ey_services_fake/mock_backend.rb', line 206

def trigger_mock_user_update(new_email)
  actor(:tresfiestas).trigger_mock_user_update(sso_user, new_email)
end