Skip to content

Commit 15f19b1

Browse files
committed
create signup endpoint
1 parent 41c1f51 commit 15f19b1

File tree

4 files changed

+110
-2
lines changed

4 files changed

+110
-2
lines changed

lib/ey-core/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ class Ey::Core::Client < Cistern::Service
296296
request :reboot_server
297297
request :run_cluster_component_action
298298
request :run_environment_application_action
299+
request :signup
299300
request :update_addon
300301
request :update_addon_attachment
301302
request :update_alert

lib/ey-core/requests/signup.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

spec/accounts_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
it "should create an account" do
2828
name = Faker::Name.first_name
2929

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")
3135

3236
expect(account.name).to eq(name)
3337
expect(account.support_plan).to eq("standard")
34-
expect(account.signup_via).to eq("deis")
3538

3639
users = account.users.all
3740
expect(users.size).to eq(1)

spec/signups_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

0 commit comments

Comments
 (0)