ruby-egnyte 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +23 -0
- data/README.markdown +113 -0
- data/Rakefile +4 -0
- data/egnyte.gemspec +32 -0
- data/includes/cacert.pem +3849 -0
- data/lib/egnyte.rb +25 -0
- data/lib/egnyte/client.rb +11 -0
- data/lib/egnyte/errors.rb +28 -0
- data/lib/egnyte/file.rb +51 -0
- data/lib/egnyte/folder.rb +112 -0
- data/lib/egnyte/folder_structure.rb +13 -0
- data/lib/egnyte/group.rb +185 -0
- data/lib/egnyte/helper.rb +41 -0
- data/lib/egnyte/item.rb +43 -0
- data/lib/egnyte/link.rb +109 -0
- data/lib/egnyte/permission.rb +181 -0
- data/lib/egnyte/session.rb +197 -0
- data/lib/egnyte/user.rb +207 -0
- data/lib/egnyte/version.rb +3 -0
- data/spec/file_spec.rb +71 -0
- data/spec/fixtures/folder_listing_no_files.json +12 -0
- data/spec/fixtures/group/group_all.json +17 -0
- data/spec/fixtures/group/group_by_parameter.json +10 -0
- data/spec/fixtures/group/group_by_parameter_empty.json +7 -0
- data/spec/fixtures/group/group_create.json +1 -0
- data/spec/fixtures/link/link.json +1 -0
- data/spec/fixtures/link/link_create.json +1 -0
- data/spec/fixtures/link/link_list.json +1 -0
- data/spec/fixtures/link/link_list_empty.json +1 -0
- data/spec/fixtures/list_file.json +27 -0
- data/spec/fixtures/list_folder.json +23 -0
- data/spec/fixtures/permission/permission_list.json +1 -0
- data/spec/fixtures/user/user_all.json +1007 -0
- data/spec/fixtures/user/user_by_email.json +27 -0
- data/spec/fixtures/user/user_create.json +20 -0
- data/spec/fixtures/user/user_find.json +20 -0
- data/spec/fixtures/user/user_update.json +20 -0
- data/spec/folder_spec.rb +207 -0
- data/spec/group_spec.rb +166 -0
- data/spec/helper_spec.rb +30 -0
- data/spec/links_spec.rb +156 -0
- data/spec/permissions_spec.rb +98 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/user_spec.rb +212 -0
- metadata +260 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
{
|
2
|
+
"startIndex":1,
|
3
|
+
"totalResults":1,
|
4
|
+
"itemsPerPage":100,
|
5
|
+
"resources":[
|
6
|
+
{
|
7
|
+
"id":12408258604,
|
8
|
+
"userName":"afisher",
|
9
|
+
"externalId":"afisher",
|
10
|
+
"email":"afisher@example.com",
|
11
|
+
"name":{
|
12
|
+
"formatted":"Alberta Fisher",
|
13
|
+
"familyName":"Fisher",
|
14
|
+
"givenName":"Alberta"
|
15
|
+
},
|
16
|
+
"active":false,
|
17
|
+
"locked":false,
|
18
|
+
"emailChangePending":true,
|
19
|
+
"authType":"sso",
|
20
|
+
"userType":"power",
|
21
|
+
"idpUserId":"afisher",
|
22
|
+
"userPrincipalName":null,
|
23
|
+
"expiryDate":null,
|
24
|
+
"deleteOnExpiry":null
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"id":12163350648,
|
3
|
+
"userName":"userA",
|
4
|
+
"externalId":null,
|
5
|
+
"email":"userA@example.com",
|
6
|
+
"name":{
|
7
|
+
"formatted":"user A",
|
8
|
+
"familyName":"A",
|
9
|
+
"givenName":"user"
|
10
|
+
},
|
11
|
+
"active":true,
|
12
|
+
"locked":false,
|
13
|
+
"emailChangePending":null,
|
14
|
+
"authType":"egnyte",
|
15
|
+
"userType":"power",
|
16
|
+
"idpUserId":null,
|
17
|
+
"userPrincipalName":null,
|
18
|
+
"expiryDate":null,
|
19
|
+
"deleteOnExpiry":null
|
20
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"id":12408258604,
|
3
|
+
"userName":"afisher",
|
4
|
+
"externalId":"afisher",
|
5
|
+
"email":"afisher@example.com",
|
6
|
+
"name":{
|
7
|
+
"formatted":"Alberta Fisher",
|
8
|
+
"familyName":"Fisher",
|
9
|
+
"givenName":"Alberta"
|
10
|
+
},
|
11
|
+
"active":false,
|
12
|
+
"locked":false,
|
13
|
+
"emailChangePending":true,
|
14
|
+
"authType":"sso",
|
15
|
+
"userType":"power",
|
16
|
+
"idpUserId":"afisher",
|
17
|
+
"userPrincipalName":null,
|
18
|
+
"expiryDate":null,
|
19
|
+
"deleteOnExpiry":null
|
20
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"id":12163350648,
|
3
|
+
"userName":"usera",
|
4
|
+
"externalId":"",
|
5
|
+
"email":"userA@example.com",
|
6
|
+
"name":{
|
7
|
+
"formatted":"user A",
|
8
|
+
"familyName":"A",
|
9
|
+
"givenName":"user"
|
10
|
+
},
|
11
|
+
"active":true,
|
12
|
+
"locked":false,
|
13
|
+
"emailChangePending":true,
|
14
|
+
"authType":"egnyte",
|
15
|
+
"userType":"power",
|
16
|
+
"idpUserId":"",
|
17
|
+
"userPrincipalName":null,
|
18
|
+
"expiryDate":null,
|
19
|
+
"deleteOnExpiry":null
|
20
|
+
}
|
data/spec/folder_spec.rb
ADDED
@@ -0,0 +1,207 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Egnyte::Folder do
|
6
|
+
before(:each) do
|
7
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/userinfo").
|
8
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'User-Agent'=>'Ruby'}).
|
9
|
+
to_return(:status => 200, :body => "", :headers => {})
|
10
|
+
@session = Egnyte::Session.new({
|
11
|
+
key: 'api_key',
|
12
|
+
domain: 'test',
|
13
|
+
access_token: 'access_token'
|
14
|
+
}, :implicit, 0.0)
|
15
|
+
@client = Egnyte::Client.new(@session)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#upload" do
|
19
|
+
context "when the upload fails (e.g. when the service is unavailable)" do
|
20
|
+
it "raises an appropriate exception" do
|
21
|
+
file_contents = 'Some data.'
|
22
|
+
|
23
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v1/fs-content/apple/banana/LICENSE.txt")
|
24
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' }, :body => file_contents)
|
25
|
+
.to_return(:body => '', :status => 503)
|
26
|
+
|
27
|
+
folder = Egnyte::Folder.new({
|
28
|
+
'path' => 'apple/banana',
|
29
|
+
'name' => 'banana'
|
30
|
+
}, @session)
|
31
|
+
|
32
|
+
expect {
|
33
|
+
folder.upload('LICENSE.txt', StringIO.new(file_contents))
|
34
|
+
}.to raise_error(Egnyte::RequestError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "upload file to appropriate endpoint, and return a file object" do
|
39
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v1/fs-content/apple/banana/LICENSE.txt")
|
40
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' }, :body => File.open('./LICENSE.txt').read)
|
41
|
+
.to_return(:body => '', :status => 200, :headers => {
|
42
|
+
'ETag' => 'c0c6c151-104b-4ddd-a0c7-eea809fc8a6a',
|
43
|
+
'X-Sha512-Checksum' => '434390eddf638ab28e0f4668dca32e4a2b05c96eb3c8c0ca889788e204158cb4f240f1055ebac35745ede0e2349c83b407b9e4e0109bdc0b5ccdfe332a60fcfc',
|
44
|
+
'last_modified' => 'Mon, 05 Aug 2013 22:37:35 GMT'
|
45
|
+
})
|
46
|
+
|
47
|
+
folder = Egnyte::Folder.new({
|
48
|
+
'path' => 'apple/banana',
|
49
|
+
'name' => 'banana'
|
50
|
+
}, @session)
|
51
|
+
|
52
|
+
file = nil
|
53
|
+
|
54
|
+
File.open( './LICENSE.txt' ) do |data|
|
55
|
+
file = folder.upload('LICENSE.txt', data)
|
56
|
+
end
|
57
|
+
|
58
|
+
expect(file.is_folder).to be false
|
59
|
+
expect(file.name).to eq('LICENSE.txt')
|
60
|
+
expect(file.entry_id).to eq('c0c6c151-104b-4ddd-a0c7-eea809fc8a6a')
|
61
|
+
expect(file.checksum).to eq('434390eddf638ab28e0f4668dca32e4a2b05c96eb3c8c0ca889788e204158cb4f240f1055ebac35745ede0e2349c83b407b9e4e0109bdc0b5ccdfe332a60fcfc')
|
62
|
+
expect(file.last_modified).to eq('Mon, 05 Aug 2013 22:37:35 GMT')
|
63
|
+
expect(file.size).to eq(1103)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#create" do
|
68
|
+
it "should call post to fs/path with appropriate payload and return folder object" do
|
69
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v1/fs/apple/banana/New%20Folder")
|
70
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' }, :body => JSON.dump({"action" => "add_folder"}))
|
71
|
+
.to_return(:body => '', :status => 200)
|
72
|
+
|
73
|
+
folder = Egnyte::Folder.new({
|
74
|
+
'path' => 'apple/banana',
|
75
|
+
'name' => 'banana'
|
76
|
+
}, @session)
|
77
|
+
|
78
|
+
new_folder = folder.create('New Folder')
|
79
|
+
expect(new_folder.name).to eq('New Folder')
|
80
|
+
expect(new_folder.path).to eq('apple/banana/New Folder')
|
81
|
+
expect(new_folder.folders).to eq([])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Folder::find" do
|
86
|
+
it "should return a folder object if the folder exists" do
|
87
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
88
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
89
|
+
.to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
|
90
|
+
|
91
|
+
expect(@client.folder.name).to eq('docs')
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should raise FileOrFolderNotFound error for a non-existent folder" do
|
95
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/banana")
|
96
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
97
|
+
.to_return(:status => 404)
|
98
|
+
|
99
|
+
expect {@client.folder('banana')}.to raise_error( Egnyte::RecordNotFound )
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should raise FolderExpected if path to file provided" do
|
103
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
104
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
105
|
+
.to_return(:body => File.read('./spec/fixtures/list_file.json'), :status => 200)
|
106
|
+
|
107
|
+
expect {@client.folder}.to raise_error( Egnyte::FolderExpected )
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "Folder::permissions" do
|
112
|
+
it "should return a folder permissions object if the folder exists" do
|
113
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
114
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
115
|
+
.to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
|
116
|
+
expect(@client.folder.name).to eq('docs')
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should raise FileOrFolderNotFound error for a non-existent folder" do
|
120
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/banana")
|
121
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
122
|
+
.to_return(:status => 404)
|
123
|
+
|
124
|
+
expect {@client.folder('banana')}.to raise_error( Egnyte::RecordNotFound )
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should raise FolderExpected if path to file provided" do
|
128
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
129
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
130
|
+
.to_return(:body => File.read('./spec/fixtures/list_file.json'), :status => 200)
|
131
|
+
|
132
|
+
expect {@client.folder}.to raise_error( Egnyte::FolderExpected )
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#files" do
|
137
|
+
it "should return an array of file objects" do
|
138
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
139
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
140
|
+
.to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
|
141
|
+
|
142
|
+
folder = @client.folder
|
143
|
+
file = folder.files.first
|
144
|
+
expect(file).to be_instance_of(Egnyte::File)
|
145
|
+
expect(file.path).to eq('Shared/test.txt')
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should return an empty array if there arent any files in the folder" do
|
149
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
150
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
151
|
+
.to_return(:body => File.read('./spec/fixtures/folder_listing_no_files.json'), :status => 200)
|
152
|
+
|
153
|
+
folder = @client.folder
|
154
|
+
files = folder.files
|
155
|
+
expect(files.size).to eq(0)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#folders" do
|
160
|
+
it "should return an array of file objects" do
|
161
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
162
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
163
|
+
.to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
|
164
|
+
|
165
|
+
folder = @client.folder
|
166
|
+
file = folder.folders.first
|
167
|
+
expect(file).to be_instance_of(Egnyte::Folder)
|
168
|
+
expect(file.path).to eq('Shared/subfolder1')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "permissions" do
|
173
|
+
before(:each) do
|
174
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
|
175
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
176
|
+
.to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "#permissions" do
|
180
|
+
it "should returned a parsed list permissions" do
|
181
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/perms/folder/Shared")
|
182
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
183
|
+
.to_return(:body => File.read('./spec/fixtures/permission/permission_list.json'), :status => 200)
|
184
|
+
folder = Egnyte::Folder.find(@session, 'Shared')
|
185
|
+
permissions = folder.permissions
|
186
|
+
expect(permissions.class).to eq Egnyte::Permission
|
187
|
+
expect(permissions.data['groups'].size).to eq 2
|
188
|
+
expect(permissions.data['users'].size).to eq 66
|
189
|
+
expect(permissions.data['users']['knikolaus']).to eq "Owner"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "#apply_permission" do
|
194
|
+
it "should call the apply method in Egnyte::Permission" do
|
195
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v1/perms/folder/Shared")
|
196
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
197
|
+
.to_return(:body => "", :status => 200)
|
198
|
+
perm_obj = Egnyte::Permission.build_from_api_listing({'users' => [{'subject' => 'thintz', 'permission' => 'Viewer'}]})
|
199
|
+
folder = Egnyte::Folder.find(@session, 'Shared')
|
200
|
+
expect(Egnyte::Permission).to receive(:apply)
|
201
|
+
folder.apply_permissions(perm_obj)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
data/spec/group_spec.rb
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Egnyte::Group do
|
4
|
+
before(:each) do
|
5
|
+
@invalid_group_params = {}
|
6
|
+
@valid_group_params = {
|
7
|
+
:displayName => "Test with members",
|
8
|
+
:members => [9967960066, 9967960068]
|
9
|
+
}
|
10
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/userinfo").
|
11
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'User-Agent'=>'Ruby'}).
|
12
|
+
to_return(:status => 200, :body => "", :headers => {})
|
13
|
+
@session = Egnyte::Session.new({
|
14
|
+
key: 'api_key',
|
15
|
+
domain: 'test',
|
16
|
+
access_token: 'access_token'
|
17
|
+
}, :implicit, 0.0)
|
18
|
+
@client = Egnyte::Client.new(@session)
|
19
|
+
@group = Egnyte::Group.new(@session, @valid_group_params)
|
20
|
+
@group2 = Egnyte::Group.new(@session, "Test without members")
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#initialize" do
|
24
|
+
|
25
|
+
it 'instantiates a valid group if only a name is provided' do
|
26
|
+
expect(@group).to be_valid
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'instantiates a valid group if a name and group members are provided' do
|
30
|
+
expect(@group2).to be_valid
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#create" do
|
36
|
+
|
37
|
+
it "should create a new group if valid" do
|
38
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v2/groups")
|
39
|
+
.with(:body => @group.to_json_for_api_call,
|
40
|
+
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
41
|
+
.to_return(:status => 201, :body => File.read('./spec/fixtures/group/group_create.json'), :headers => {})
|
42
|
+
@group = Egnyte::Group.create(@session, @valid_group_params)
|
43
|
+
expect(@group.id).to eq "5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should raise an error if it tries to create an invaid group" do
|
47
|
+
expect{ Egnyte::Group.create(@session, @invalid_group_params) }.to raise_error(Egnyte::MissingAttribute)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#save" do
|
53
|
+
|
54
|
+
it 'should raise an error if an attribute is missing' do
|
55
|
+
@group.displayName = nil
|
56
|
+
expect{ @group.save }.to raise_error(Egnyte::MissingAttribute)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should save a valid new group object by sending a POST to the Egnyte Group API' do
|
60
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v2/groups")
|
61
|
+
.with(:body => @group.to_json_for_api_call,
|
62
|
+
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'})
|
63
|
+
.to_return(:status => 201, :body => File.read('./spec/fixtures/group/group_create.json'), :headers => {})
|
64
|
+
@group = @group.save
|
65
|
+
expect(@group.id).to eq "5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc"
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should update an existing group object by sending a PUT to the Egnyte Group API' do
|
69
|
+
stub_request(:put, "https://test.egnyte.com/pubapi/v2/groups/5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc")
|
70
|
+
.with(:body => @group.to_json_for_api_call,
|
71
|
+
:headers => {'Authorization'=>'Bearer access_token', 'Content-Type'=>'application/json'})
|
72
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/group/group_create.json'), :headers => {})
|
73
|
+
@valid_group_params[:id] = "5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc"
|
74
|
+
@group = Egnyte::Group.new(@session, @valid_group_params)
|
75
|
+
@group.save
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#Group::find" do
|
81
|
+
|
82
|
+
it 'should find a group by id if the group exists' do
|
83
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/groups/5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc")
|
84
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
85
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/group/group_create.json'), :headers => {})
|
86
|
+
@group = @client.group('5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc')
|
87
|
+
expect(@group).to be_an Egnyte::Group
|
88
|
+
expect(@group.id).to eq '5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc'
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#Groups::all" do
|
94
|
+
|
95
|
+
it 'should list all users' do
|
96
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/groups?count=100&startIndex=1")
|
97
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
98
|
+
.to_return(:body => File.read('./spec/fixtures/group/group_all.json'), :status => 200)
|
99
|
+
list = Egnyte::Group.all(@session)
|
100
|
+
expect(list).to be_an Array
|
101
|
+
expect(list.first).to be_an Egnyte::Group
|
102
|
+
expect(list.size).to eq 3
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#Group::where" do
|
108
|
+
|
109
|
+
it 'should find groups that match the where filter' do
|
110
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/groups?count=100&filter=displayName%20eq%20%22Finance%22&startIndex=1")
|
111
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
112
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/group/group_by_parameter.json'), :headers => {})
|
113
|
+
group_list = Egnyte::Group.where(@session, {displayName: "Finance"})
|
114
|
+
expect(group_list).to be_an Array
|
115
|
+
expect(group_list.first).to be_an Egnyte::Group
|
116
|
+
expect(group_list.first.id).to eq "d5ea2e76-63e4-4b47-92af-0d7ba6972e3c"
|
117
|
+
expect(group_list.size).to eq 1
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should return an empty array if no match is found' do
|
121
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/groups?count=100&filter=displayName%20eq%20%22FakeEmailThatDoesNotExist%22&startIndex=1")
|
122
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
123
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/group/group_by_parameter_empty.json'), :headers => {})
|
124
|
+
group_list = Egnyte::Group.where(@session, {displayName: "FakeEmailThatDoesNotExist"})
|
125
|
+
expect(group_list).to be_an Array
|
126
|
+
expect(group_list.size).to eq 0
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#User::search" do
|
132
|
+
|
133
|
+
before(:each) do
|
134
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/groups?count=100&startIndex=1")
|
135
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
136
|
+
.to_return(:body => File.read('./spec/fixtures/group/group_all.json'), :status => 200)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should find users that match the search criteria' do
|
140
|
+
user_list = Egnyte::Group.search(@session, "Fin")
|
141
|
+
expect(user_list).to be_an Array
|
142
|
+
expect(user_list.first).to be_an Egnyte::Group
|
143
|
+
expect(user_list.size).to eq 1
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should return an empty array if no match is found' do
|
147
|
+
user_list = Egnyte::Group.search(@session, 'NonexistantSearchCriteria')
|
148
|
+
expect(user_list).to be_an Array
|
149
|
+
expect(user_list.size).to eq 0
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "#Group::delete" do
|
155
|
+
|
156
|
+
it 'should delete a group by id if the group exists' do
|
157
|
+
stub_request(:delete, "https://test.egnyte.com/pubapi/v2/groups/5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc")
|
158
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
159
|
+
.to_return(:status => 200, :body => "", :headers => {})
|
160
|
+
expect(Egnyte::User).to receive(:delete).and_return({})
|
161
|
+
Egnyte::User.delete(@session, "5ef70bb0-edeb-4fcb-86d4-e1e1a0b6c9dc")
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|