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_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



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

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

.fail_to_findObject



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

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

.fail_to_replace_permissionsObject



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

def fail_to_replace_permissions
  stub_put(object_endpoint, {}, response(500))
end

.organization_fixture_hash(options = {}) ⇒ Object



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

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



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

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

.succeed_to_createObject



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

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
# 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))
end

.succeed_to_replace_permissionsObject



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

def succeed_to_replace_permissions
  stub_put(object_endpoint, {}, response(200, ""))
end