Module: CcApiStub::Users

Extended by:
Helper
Defined in:
lib/cc_api_stub/users.rb

Class Method Summary collapse

Methods included from Helper

fail_request, fail_to_load, fail_to_load_many, fail_to_update, fail_with_error, find_fixture, fixture_prefix, host, host=, load_fixtures, object_class, object_name, response, response, stub_delete, stub_get, stub_post, stub_put, stub_request, succeed_to_create, succeed_to_delete, succeed_to_load, succeed_to_load_empty, succeed_to_load_many, succeed_to_update

Class Method Details

.fail_to_createObject



51
52
53
# File 'lib/cc_api_stub/users.rb', line 51

def fail_to_create
  CcApiStub::Helper.fail_request(:post, 500, {}, /users/)
end

.fail_to_find(options = {}) ⇒ Object



42
43
44
# File 'lib/cc_api_stub/users.rb', line 42

def fail_to_find(options = {})
  stub_get(object_endpoint(options[:id]), {}, response(404, {:code => 20003, :description => "The user could not be found"}))
end

.fail_to_replace_permissions(options = {}) ⇒ Object



59
60
61
# File 'lib/cc_api_stub/users.rb', line 59

def fail_to_replace_permissions(options = {})
  stub_put(object_endpoint(options[:id]), {}, response(500))
end

.organization_fixture_hash(options = {}) ⇒ Object



67
68
69
70
71
72
# File 'lib/cc_api_stub/users.rb', line 67

def organization_fixture_hash(options={})
  fixture = organizations_fixture.first
  fixture["entity"].delete("spaces") if options[:no_spaces]
  fixture["entity"].delete("managers") if options[:no_managers]
  MultiJson.load(fixture.to_json, :symbolize_keys => true)
end

.organizations_fixtureObject



63
64
65
# File 'lib/cc_api_stub/users.rb', line 63

def organizations_fixture
  Helper.load_fixtures("fake_cc_user")["entity"]["organizations"]
end

.succeed_to_createObject



46
47
48
49
# File 'lib/cc_api_stub/users.rb', line 46

def succeed_to_create
  response_body = Helper.load_fixtures("fake_cc_created_user")
  stub_post(collection_endpoint, {}, response(201, response_body))
end

.succeed_to_load(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cc_api_stub/users.rb', line 6

def succeed_to_load(options={})
  response_body = Helper.load_fixtures(options[:fixture] || "fake_cc_user")
  response_body["metadata"]["guid"] = options[:id] || "user-id-1"

  if options[:no_organizations]
    response_body["entity"]["organizations"] = []
  else
    def space(space_id) {"metadata" => { "guid" => space_id }, "entity" => {}} end

    organization = response_body["entity"]["organizations"].first
    organization["metadata"]["guid"] = options[:organization_id] || "organization-id-1"
    organization["entity"]["spaces"] = [] if options[:no_spaces]

    permissions = options[:permissions] || [:organization_manager]

    response_body["entity"]["managed_organizations"] << organization if permissions.include?(:organization_manager)
    response_body["entity"]["billing_managed_organizations"] << organization if permissions.include?(:organization_billing_manager)
    response_body["entity"]["audited_organizations"] << organization if permissions.include?(:organization_auditor)

    unless options[:no_spaces]
      space = space("space-id-1")
      response_body["entity"]["spaces"] << space         if permissions.include?(:space_developer)
      response_body["entity"]["managed_spaces"] << space if permissions.include?(:space_manager)
      response_body["entity"]["audited_spaces"] << space if permissions.include?(:space_auditor)

      space2 = space("space-id-2")
      response_body["entity"]["spaces"] << space2         if permissions.include?(:space2_developer)
      response_body["entity"]["managed_spaces"] << space2 if permissions.include?(:space2_manager)
      response_body["entity"]["audited_spaces"] << space2 if permissions.include?(:space2_auditor)
    end
  end

  stub_get(%r{/v2/users/[^/]+\?inline-relations-depth=2$}, {}, response(200, response_body))
  stub_get(%r{/v2/users/[^/]+/summary(\?inline-relations-depth=\d)?$}, {}, response(200, response_body))
end

.succeed_to_replace_permissions(options = {}) ⇒ Object



55
56
57
# File 'lib/cc_api_stub/users.rb', line 55

def succeed_to_replace_permissions(options = {})
  stub_put(object_endpoint(options[:id]), {}, response(200, ""))
end