File tree Expand file tree Collapse file tree 4 files changed +110
-2
lines changed Expand file tree Collapse file tree 4 files changed +110
-2
lines changed Original file line number Diff line number Diff line change @@ -296,6 +296,7 @@ class Ey::Core::Client < Cistern::Service
296
296
request :reboot_server
297
297
request :run_cluster_component_action
298
298
request :run_environment_application_action
299
+ request :signup
299
300
request :update_addon
300
301
request :update_addon_attachment
301
302
request :update_alert
Original file line number Diff line number Diff line change
1
+ class Ey ::Core ::Client
2
+ class Real
3
+ def signup ( user , account , features = nil )
4
+ params = {
5
+ "user" => user ,
6
+ "account" => account ,
7
+ }
8
+ params [ "features" ] = features if features
9
+
10
+ request (
11
+ :method => :post ,
12
+ :path => "/signups" ,
13
+ :params => params ,
14
+ )
15
+ end
16
+ end # Real
17
+
18
+ class Mock
19
+ def signup ( user , account , features = nil )
20
+ if self . authentication != :hmac
21
+ response ( status : 403 )
22
+ end
23
+
24
+ user_id = self . uuid
25
+
26
+ user = user . dup
27
+ user [ "token" ] = SecureRandom . hex ( 20 )
28
+
29
+ user . merge! ( {
30
+ "id" => user_id ,
31
+ "accounts" => url_for ( "/users/#{ user_id } /accounts" ) ,
32
+ "memberships" => url_for ( "/users/#{ user_id } /memberships" ) ,
33
+ "keypairs" => url_for ( "/users/#{ user_id } /keypairs" ) ,
34
+ } )
35
+
36
+ self . data [ :users ] [ user_id ] = user
37
+
38
+ account_id = self . uuid
39
+ account = mock_account_setup ( account_id , account . dup )
40
+
41
+ self . data [ :accounts ] [ account_id ] = account . merge ( :account_users => [ user_id ] , :account_owners => [ user_id ] )
42
+
43
+ features . each do |resource_id |
44
+ feature = self . data [ :features ] [ resource_id ]
45
+
46
+ account_url = url_for ( "/accounts/#{ account_id } " )
47
+ feature [ "account" ] = account_url
48
+ end
49
+
50
+ response (
51
+ :body => {
52
+ "signup" => {
53
+ "user_id" => user_id ,
54
+ "account_id" => account_id ,
55
+ } ,
56
+ } ,
57
+ :status => 201 ,
58
+ )
59
+ end
60
+ end # Mock
61
+ end # Ey::Core::Client
Original file line number Diff line number Diff line change 27
27
it "should create an account" do
28
28
name = Faker ::Name . first_name
29
29
30
- account = hmac_client . accounts . create! ( owner : user , name : name , signup_via : "deis" )
30
+ account = hmac_client . accounts . create! ( owner : user , name : name )
31
+
32
+ # signup_via is foyer only
33
+ # account = hmac_client.accounts.create!(owner: user, name: name, signup_via: "deis")
34
+ # expect(account.signup_via).to eq("deis")
31
35
32
36
expect ( account . name ) . to eq ( name )
33
37
expect ( account . support_plan ) . to eq ( "standard" )
34
- expect ( account . signup_via ) . to eq ( "deis" )
35
38
36
39
users = account . users . all
37
40
expect ( users . size ) . to eq ( 1 )
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe 'signups' do
4
+ context "with a hmac client" do
5
+ let! ( :client ) { create_hmac_client }
6
+
7
+ let! ( :public_feature ) do
8
+ if Ey ::Core ::Client . mocking?
9
+ client . create_feature (
10
+ :id => "public_feature" ,
11
+ :privacy => "public" ,
12
+ :name => "A Public Feature" ,
13
+ )
14
+ else
15
+ client . features . all . first
16
+ end
17
+ end
18
+
19
+ it "should create a user and account" do
20
+ user_params = {
21
+ :name => Faker ::Name . name ,
22
+ :email => Faker ::Internet . email ,
23
+ :password => SecureRandom . hex ( 8 ) ,
24
+ }
25
+ account_params = {
26
+ :account_name => SecureRandom . hex ( 6 ) ,
27
+ }
28
+ features = [ public_feature . id ]
29
+
30
+ signup = client . signup ( user_params , account_params , features ) . body [ "signup" ]
31
+ user = client . users . get ( signup [ "user_id" ] )
32
+ account = client . accounts . get ( signup [ "account_id" ] )
33
+
34
+ expect ( user . name ) . to eq ( user_params [ :name ] )
35
+ expect ( user . email ) . to eq ( user_params [ :email ] )
36
+
37
+ expect ( account . name ) . to eq ( account_params [ :name ] )
38
+
39
+ expect ( user . accounts ) . to contain_exactly ( account )
40
+ expect ( account . features . map ( &:id ) ) . to include ( *features )
41
+ end
42
+ end
43
+ end
You can’t perform that action at this time.
0 commit comments