enterprises_test.rb
3.67 KB
1
2
3
4
5
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require File.dirname(__FILE__) + '/test_helper'
class EnterprisesTest < ActiveSupport::TestCase
def setup
Enterprise.delete_all
login_api
end
should 'list only enterprises' do
community = fast_create(Community) # should not list this community
enterprise = fast_create(Enterprise, :public_profile => true)
get "/api/v1/enterprises?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_includes json['enterprises'].map {|c| c['id']}, enterprise.id
assert_not_includes json['enterprises'].map {|c| c['id']}, community.id
end
should 'list all enterprises' do
enterprise1 = fast_create(Enterprise, :public_profile => true)
enterprise2 = fast_create(Enterprise)
get "/api/v1/enterprises?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent [enterprise1.id, enterprise2.id], json['enterprises'].map {|c| c['id']}
end
should 'not list invisible enterprises' do
enterprise1 = fast_create(Enterprise)
fast_create(Enterprise, :visible => false)
get "/api/v1/enterprises?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']}
end
should 'not list private enterprises without permission' do
enterprise1 = fast_create(Enterprise)
fast_create(Enterprise, :public_profile => false)
get "/api/v1/enterprises?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal [enterprise1.id], json['enterprises'].map {|c| c['id']}
end
should 'list private enterprise for members' do
c1 = fast_create(Enterprise)
c2 = fast_create(Enterprise, :public_profile => false)
c2.add_member(person)
get "/api/v1/enterprises?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent [c1.id, c2.id], json['enterprises'].map {|c| c['id']}
end
should 'get enterprise' do
enterprise = fast_create(Enterprise)
get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal enterprise.id, json['enterprise']['id']
end
should 'not get invisible enterprise' do
enterprise = fast_create(Enterprise, :visible => false)
get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert json['enterprise'].blank?
end
should 'not get private enterprises without permission' do
enterprise = fast_create(Enterprise)
fast_create(Enterprise, :public_profile => false)
get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal enterprise.id, json['enterprise']['id']
end
should 'get private enterprise for members' do
enterprise = fast_create(Enterprise, :public_profile => false)
enterprise.add_member(person)
get "/api/v1/enterprises/#{enterprise.id}?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal enterprise.id, json['enterprise']['id']
end
should 'list person enterprises' do
enterprise = fast_create(Enterprise)
fast_create(Enterprise)
enterprise.add_member(person)
get "/api/v1/people/#{person.id}/enterprises?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent [enterprise.id], json['enterprises'].map {|c| c['id']}
end
should 'not list person enterprises invisible' do
c1 = fast_create(Enterprise)
c2 = fast_create(Enterprise, :visible => false)
c1.add_member(person)
c2.add_member(person)
get "/api/v1/people/#{person.id}/enterprises?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equivalent [c1.id], json['enterprises'].map {|c| c['id']}
end
end