boxr 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ #rake spec SPEC_OPTS="-e \"invokes file metadata operations"\"
4
+ describe 'file metadata operations' do
5
+ it "invokes file metadata operations" do
6
+ test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
7
+
8
+ puts "create metadata"
9
+ meta = {"a" => "hello", "b" => "world"}
10
+ metadata = BOX_CLIENT.create_metadata(test_file, meta)
11
+ expect(metadata.a).to eq("hello")
12
+
13
+ puts "update metadata"
14
+ metadata = BOX_CLIENT.update_metadata(test_file, {op: :replace, path: "/b", value: "there"})
15
+ expect(metadata.b).to eq("there")
16
+ metadata = BOX_CLIENT.update_metadata(test_file, [{op: :replace, path: "/b", value: "friend"}])
17
+ expect(metadata.b).to eq("friend")
18
+
19
+ puts "get metadata"
20
+ metadata = BOX_CLIENT.metadata(test_file)
21
+ expect(metadata.a).to eq("hello")
22
+
23
+ puts "delete metadata"
24
+ result = BOX_CLIENT.delete_metadata(test_file)
25
+ expect(result).to eq({})
26
+ end
27
+
28
+ #rake spec SPEC_OPTS="-e \"invokes folder metadata operations"\"
29
+ #NOTE: this test will fail unless you create a metadata template called 'test' with two attributes: 'a' of type text, and 'b' of type text
30
+ it "invokes folder metadata operations" do
31
+ new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder)
32
+
33
+ puts "create folder metadata"
34
+ meta = {"a" => "hello", "b" => "world"}
35
+ metadata = BOX_CLIENT.create_folder_metadata(new_folder, meta, "enterprise", "test")
36
+ expect(metadata.a).to eq("hello")
37
+
38
+ puts "update folder metadata"
39
+ metadata = BOX_CLIENT.update_folder_metadata(new_folder, {op: :replace, path: "/b", value: "there"}, "enterprise", "test")
40
+ expect(metadata.b).to eq("there")
41
+ metadata = BOX_CLIENT.update_folder_metadata(new_folder, [{op: :replace, path: "/b", value: "friend"}], "enterprise", "test")
42
+ expect(metadata.b).to eq("friend")
43
+
44
+ puts "get folder metadata"
45
+ metadata = BOX_CLIENT.folder_metadata(new_folder, "enterprise", "test")
46
+ expect(metadata.a).to eq("hello")
47
+
48
+ puts "delete folder metadata"
49
+ result = BOX_CLIENT.delete_folder_metadata(new_folder, "enterprise", "test")
50
+ expect(result).to eq({})
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ #rake spec SPEC_OPTS="-e \"invokes search operations"\"
4
+ describe 'search operations' do
5
+ it "invokes search operations" do
6
+ #the issue with this test is that Box can take between 5-10 minutes to index any content uploaded; this is just a smoke test
7
+ #so we are searching for something that should return zero results
8
+ puts "perform search"
9
+ results = BOX_CLIENT.search("sdlfjuwnsljsdfuqpoiqweouyvnnadsfkjhiuweruywerbjvhvkjlnasoifyukhenlwdflnsdvoiuawfydfjh")
10
+ expect(results).to eq([])
11
+ end
12
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ #rake spec SPEC_OPTS="-e \"invokes task operations"\"
4
+ describe 'task operations' do
5
+ it "invokes task operations" do
6
+ test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
7
+ collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :editor)
8
+
9
+ puts "create task"
10
+ new_task = BOX_CLIENT.create_task(test_file, message: TEST_TASK_MESSAGE)
11
+ expect(new_task.message).to eq(TEST_TASK_MESSAGE)
12
+ TEST_TASK = new_task
13
+
14
+ puts "inspect file tasks"
15
+ tasks = BOX_CLIENT.file_tasks(test_file)
16
+ expect(tasks.first.id).to eq(TEST_TASK.id)
17
+
18
+ puts "inspect task"
19
+ task = BOX_CLIENT.task(TEST_TASK)
20
+ expect(task.id).to eq(TEST_TASK.id)
21
+
22
+ puts "update task"
23
+ NEW_TASK_MESSAGE = "new task message"
24
+ updated_task = BOX_CLIENT.update_task(TEST_TASK, message: NEW_TASK_MESSAGE)
25
+ expect(updated_task.message).to eq(NEW_TASK_MESSAGE)
26
+
27
+ puts "create task assignment"
28
+ task_assignment = BOX_CLIENT.create_task_assignment(TEST_TASK, assign_to: @test_user.id)
29
+ expect(task_assignment.assigned_to.id).to eq(@test_user.id)
30
+ TASK_ASSIGNMENT = task_assignment
31
+
32
+ puts "inspect task assignment"
33
+ task_assignment = BOX_CLIENT.task_assignment(TASK_ASSIGNMENT)
34
+ expect(task_assignment.id).to eq(TASK_ASSIGNMENT.id)
35
+
36
+ puts "inspect task assignments"
37
+ task_assignments = BOX_CLIENT.task_assignments(TEST_TASK)
38
+ expect(task_assignments.count).to eq(1)
39
+ expect(task_assignments[0].id).to eq(TASK_ASSIGNMENT.id)
40
+
41
+ #TODO: can't do this test yet because the test user needs to confirm their email address before you can do this
42
+ puts "update task assignment"
43
+ expect {
44
+ box_client_as_test_user = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'], as_user_id: @test_user.id)
45
+ new_message = "Updated task message"
46
+ task_assignment = box_client_as_test_user.update_task_assignment(TEST_TASK, resolution_state: :completed)
47
+ expect(task_assignment.resolution_state).to eq('completed')
48
+ }.to raise_error
49
+
50
+ puts "delete task assignment"
51
+ result = BOX_CLIENT.delete_task_assignment(TASK_ASSIGNMENT)
52
+ expect(result).to eq({})
53
+
54
+ puts "delete task"
55
+ result = BOX_CLIENT.delete_task(TEST_TASK)
56
+ expect(result).to eq({})
57
+ end
58
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ #rake spec SPEC_OPTS="-e \"invokes user operations"\"
4
+ describe 'user operations' do
5
+ it "invokes user operations" do
6
+ puts "inspect current user"
7
+ user = BOX_CLIENT.current_user
8
+ expect(user.status).to eq('active')
9
+ user = BOX_CLIENT.me(fields: [:role])
10
+ expect(user.role).to_not be_nil
11
+
12
+ puts "inspect a user"
13
+ user = BOX_CLIENT.user(@test_user)
14
+ expect(user.id).to eq(@test_user.id)
15
+
16
+ puts "inspect all users"
17
+ all_users = BOX_CLIENT.all_users()
18
+ test_user = all_users.find{|u| u.id == @test_user.id}
19
+ expect(test_user).to_not be_nil
20
+
21
+ #create user is tested in the before method
22
+
23
+ puts "update user"
24
+ new_name = "Chuck Nevitt"
25
+ user = BOX_CLIENT.update_user(@test_user, name: new_name)
26
+ expect(user.name).to eq(new_name)
27
+
28
+ puts "move user's folder"
29
+ second_test_user = BOX_CLIENT.create_user("Second Test User", login: "second_test_user@#{('a'..'z').to_a.shuffle[0,10].join}.com", role: 'coadmin')
30
+ folder = BOX_CLIENT.move_users_folder(@test_user, Boxr::ROOT, second_test_user)
31
+ expect(folder.owned_by.id).to eq(second_test_user.id)
32
+
33
+ # TODO: Broken while waiting to figure out permissions
34
+ # puts "add email alias for user"
35
+ # email_alias = "test-boxr-user-alias@boxntest.com" #{('a'..'z').to_a.shuffle[0,10].join}.com"
36
+ # new_alias = BOX_CLIENT.add_email_alias_for_user(@test_user, email_alias)
37
+ # expect(new_alias.type).to eq('email_alias')
38
+
39
+ # puts "get email aliases for user"
40
+ # email_aliases = BOX_CLIENT.email_aliases_for_user(@test_user)
41
+ # expect(email_aliases.first.id).to eq(new_alias.id)
42
+
43
+ # puts "remove email alias for user"
44
+ # result = BOX_CLIENT.remove_email_alias_for_user(@test_user, new_alias.id)
45
+ # expect(result).to eq({})
46
+
47
+ puts "delete users"
48
+ BOX_CLIENT.delete_user(second_test_user, force: true)
49
+ result = BOX_CLIENT.delete_user(@test_user, force: true)
50
+ expect(result).to eq({})
51
+ end
52
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ #rake spec SPEC_OPTS="-e \"invokes watermarking operations"\"
4
+ describe 'watermarking operations' do
5
+ it 'invokes watermarking operations' do
6
+ test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
7
+ folder = BOX_CLIENT.folder(@test_folder)
8
+
9
+ puts "apply watermark on file"
10
+ watermark = BOX_CLIENT.apply_watermark_on_file(test_file)
11
+ expect(watermark.watermark).to_not be_nil
12
+
13
+ puts "get watermark on file"
14
+ watermark = BOX_CLIENT.get_watermark_on_file(test_file)
15
+ expect(watermark.watermark).to_not be_nil
16
+
17
+ puts "remove watermark on file"
18
+ result = BOX_CLIENT.remove_watermark_on_file(test_file)
19
+ expect(result).to eq({})
20
+
21
+ puts "apply watermark on folder"
22
+ watermark = BOX_CLIENT.apply_watermark_on_folder(folder)
23
+ expect(watermark.watermark).to_not be_nil
24
+
25
+ puts "get watermark on folder"
26
+ watermark = BOX_CLIENT.get_watermark_on_folder(folder)
27
+ expect(watermark.watermark).to_not be_nil
28
+
29
+ puts "remove watermark on folder"
30
+ result = BOX_CLIENT.remove_watermark_on_folder(folder)
31
+ expect(result).to eq({})
32
+ end
33
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ #rake spec SPEC_OPTS="-e \"invokes web links operations"\"
4
+ describe "web links operations" do
5
+ it 'invokes web links operations' do
6
+ puts "create web link"
7
+ web_link = BOX_CLIENT.create_web_link(TEST_WEB_URL, '0', name: "my new link", description: "link description...")
8
+ expect(web_link.url).to eq(TEST_WEB_URL)
9
+
10
+ puts "get web link"
11
+ web_link_new = BOX_CLIENT.get_web_link(web_link)
12
+ expect(web_link_new.id).to eq(web_link.id)
13
+
14
+ puts "update web link"
15
+ updated_web_link = BOX_CLIENT.update_web_link(web_link, name: 'new name', description: 'new description', url: TEST_WEB_URL2)
16
+ expect(updated_web_link.url).to eq(TEST_WEB_URL2)
17
+
18
+ puts "delete web link"
19
+ result = BOX_CLIENT.delete_web_link(web_link)
20
+ expect(result).to eq({})
21
+ end
22
+ end
@@ -1,9 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Boxr::Client do
4
-
5
4
  #PLEASE NOTE
6
- #This test is intentionally NOT a series of unit tests. The goal is to smoke test the entire code base
5
+ #These tests are intentionally NOT a series of unit tests. The goal is to smoke test the entire code base
7
6
  #against an actual Box account, making real calls to the Box API. The Box API is subject to frequent
8
7
  #changes and it is not sufficient to mock responses as those responses will change over time. Successfully
9
8
  #running this test suite shows that the code base works with the current Box API. The main premise here
@@ -15,7 +14,7 @@ describe Boxr::Client do
15
14
 
16
15
  #follow the directions in .env.example to set up your BOX_DEVELOPER_TOKEN
17
16
  #keep in mind it is only valid for 60 minutes
18
- BOX_CLIENT = Boxr::Client.new #using ENV['BOX_DEVELOPER_TOKEN']
17
+ BOX_CLIENT = Boxr::Client.new # using ENV['BOX_DEVELOPER_TOKEN']
19
18
 
20
19
  #uncomment this line to see the HTTP request and response debug info in the rspec output
21
20
  # Boxr::turn_on_debugging
@@ -30,559 +29,10 @@ describe Boxr::Client do
30
29
  COMMENT_MESSAGE = 'this is a comment'
31
30
  REPLY_MESSAGE = 'this is a comment reply'
32
31
  CHANGED_COMMENT_MESSAGE = 'this comment has been changed'
33
- TEST_USER_LOGIN = "test-boxr-user@#{('a'..'z').to_a.shuffle[0,10].join}.com" #needs to be unique across anyone running this test
32
+ TEST_USER_LOGIN = "test-boxr-user@#{('a'..'z').to_a.shuffle[0,10].join}.com" # needs to be unique across anyone running this test
34
33
  TEST_USER_NAME = "Test Boxr User"
35
34
  TEST_GROUP_NAME= "Test Boxr Group"
36
35
  TEST_TASK_MESSAGE = "Please review"
37
36
  TEST_WEB_URL = 'https://www.box.com'
38
37
  TEST_WEB_URL2 = 'https://www.google.com'
39
-
40
- before(:each) do
41
- puts "-----> Resetting Box Environment"
42
- sleep BOX_SERVER_SLEEP
43
- root_folders = BOX_CLIENT.root_folder_items.folders
44
- test_folder = root_folders.find{|f| f.name == TEST_FOLDER_NAME}
45
- if(test_folder)
46
- BOX_CLIENT.delete_folder(test_folder, recursive: true)
47
- end
48
- new_folder = BOX_CLIENT.create_folder(TEST_FOLDER_NAME, Boxr::ROOT)
49
- @test_folder = new_folder
50
-
51
- all_users = BOX_CLIENT.all_users
52
- test_users = all_users.select{|u| u.name == TEST_USER_NAME}
53
- test_users.each do |u|
54
- BOX_CLIENT.delete_user(u, force: true)
55
- end
56
- sleep BOX_SERVER_SLEEP
57
- test_user = BOX_CLIENT.create_user(TEST_USER_NAME, login: TEST_USER_LOGIN)
58
- @test_user = test_user
59
-
60
- all_groups = BOX_CLIENT.groups
61
- test_group = all_groups.find{|g| g.name == TEST_GROUP_NAME}
62
- if(test_group)
63
- BOX_CLIENT.delete_group(test_group)
64
- end
65
- end
66
-
67
- # use this command to just execute this scenario
68
- # rake spec SPEC_OPTS="-e \"invokes folder operations"\"
69
- it 'invokes folder operations' do
70
- puts "get folder using path"
71
- folder = BOX_CLIENT.folder_from_path(TEST_FOLDER_NAME)
72
- expect(folder.id).to eq(@test_folder.id)
73
-
74
- puts "get folder info"
75
- folder = BOX_CLIENT.folder(@test_folder)
76
- expect(folder.id).to eq(@test_folder.id)
77
-
78
- puts "create new folder"
79
- new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder)
80
- expect(new_folder).to be_a BoxrMash
81
- SUB_FOLDER = new_folder
82
-
83
- puts "update folder"
84
- updated_folder = BOX_CLIENT.update_folder(SUB_FOLDER, description: SUB_FOLDER_DESCRIPTION)
85
- expect(updated_folder.description).to eq(SUB_FOLDER_DESCRIPTION)
86
-
87
- puts "copy folder"
88
- new_folder = BOX_CLIENT.copy_folder(SUB_FOLDER,@test_folder, name: "copy of #{SUB_FOLDER_NAME}")
89
- expect(new_folder).to be_a BoxrMash
90
- SUB_FOLDER_COPY = new_folder
91
-
92
- puts "create shared link for folder"
93
- updated_folder = BOX_CLIENT.create_shared_link_for_folder(@test_folder, access: :open)
94
- expect(updated_folder.shared_link.access).to eq("open")
95
-
96
- puts "create password-protected shared link for folder"
97
- updated_folder = BOX_CLIENT.create_shared_link_for_folder(@test_folder, password: 'password')
98
- expect(updated_folder.shared_link.is_password_enabled).to eq(true)
99
- shared_link = updated_folder.shared_link.url
100
-
101
- puts "inspect shared link"
102
- shared_item = BOX_CLIENT.shared_item(shared_link)
103
- expect(shared_item.id).to eq(@test_folder.id)
104
-
105
- puts "disable shared link for folder"
106
- updated_folder = BOX_CLIENT.disable_shared_link_for_folder(@test_folder)
107
- expect(updated_folder.shared_link).to be_nil
108
-
109
- puts "move folder"
110
- folder_to_move = BOX_CLIENT.create_folder("Folder to move", @test_folder)
111
- folder_to_move_into = BOX_CLIENT.create_folder("Folder to move into", @test_folder)
112
- folder_to_move = BOX_CLIENT.move_folder(folder_to_move, folder_to_move_into)
113
- expect(folder_to_move.parent.id).to eq(folder_to_move_into.id)
114
-
115
- puts "delete folder"
116
- result = BOX_CLIENT.delete_folder(SUB_FOLDER_COPY, recursive: true)
117
- expect(result).to eq ({})
118
-
119
- puts "inspect the trash"
120
- trash = BOX_CLIENT.trash()
121
- expect(trash).to be_a Array
122
-
123
- puts "inspect trashed folder"
124
- trashed_folder = BOX_CLIENT.trashed_folder(SUB_FOLDER_COPY)
125
- expect(trashed_folder.item_status).to eq("trashed")
126
-
127
- puts "restore trashed folder"
128
- restored_folder = BOX_CLIENT.restore_trashed_folder(SUB_FOLDER_COPY)
129
- expect(restored_folder.item_status).to eq("active")
130
-
131
- puts "trash and permanently delete folder"
132
- BOX_CLIENT.delete_folder(SUB_FOLDER_COPY, recursive: true)
133
- result = BOX_CLIENT.delete_trashed_folder(SUB_FOLDER_COPY)
134
- expect(result).to eq({})
135
- end
136
-
137
- #rake spec SPEC_OPTS="-e \"invokes file operations"\"
138
- it "invokes file operations" do
139
- puts "upload a file"
140
- new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
141
- expect(new_file.name).to eq(TEST_FILE_NAME)
142
- test_file = new_file
143
-
144
- puts "upload a file with custom name"
145
- new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder, name: TEST_FILE_NAME_CUSTOM)
146
- expect(new_file.name).to eq(TEST_FILE_NAME_CUSTOM)
147
-
148
- puts "get file using path"
149
- file = BOX_CLIENT.file_from_path("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
150
- expect(file.id).to eq(test_file.id)
151
-
152
- puts "get file download url"
153
- download_url = BOX_CLIENT.download_url(test_file)
154
- expect(download_url).to start_with("https://")
155
-
156
- puts "get file info"
157
- file_info = BOX_CLIENT.file(test_file)
158
- expect(file_info.id).to eq(test_file.id)
159
-
160
- puts "get file preview link"
161
- preview_url = BOX_CLIENT.preview_url(test_file)
162
- expect(preview_url).to start_with("https://")
163
-
164
- puts "update file"
165
- new_description = 'this file is used to test Boxr'
166
- tags = ['tag one','tag two']
167
- updated_file_info = BOX_CLIENT.update_file(test_file, description: new_description, tags: tags)
168
- expect(updated_file_info.description).to eq(new_description)
169
- tag_file_info = BOX_CLIENT.file(updated_file_info, fields: [:tags])
170
- expect(tag_file_info.tags.length).to eq(2)
171
-
172
- puts "lock file"
173
- expires_at_utc = Time.now.utc + (60*60*24) #one day from now
174
- locked_file = BOX_CLIENT.lock_file(test_file, expires_at: expires_at_utc, is_download_prevented: true)
175
- locked_file = BOX_CLIENT.file(locked_file, fields: [:lock])
176
- expect(locked_file.lock.type).to eq('lock')
177
- expect(locked_file.lock.expires_at).to_not be_nil
178
- expect(locked_file.lock.is_download_prevented).to eq(true)
179
-
180
- puts "unlock file"
181
- unlocked_file = BOX_CLIENT.unlock_file(locked_file)
182
- unlocked_file = BOX_CLIENT.file(unlocked_file, fields: [:lock])
183
- expect(unlocked_file.lock).to be_nil
184
-
185
- puts "download file"
186
- file = BOX_CLIENT.download_file(test_file)
187
- f = File.open("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}", 'w+')
188
- f.write(file)
189
- f.close
190
- expect(FileUtils.identical?("./spec/test_files/#{TEST_FILE_NAME}","./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")).to eq(true)
191
- File.delete("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")
192
-
193
- puts "upload new version of file"
194
- new_version = BOX_CLIENT.upload_new_version_of_file("./spec/test_files/#{TEST_FILE_NAME}", test_file)
195
- expect(new_version.id).to eq(test_file.id)
196
-
197
- puts "inspect versions of file"
198
- versions = BOX_CLIENT.versions_of_file(test_file)
199
- expect(versions.count).to eq(1) #the reason this is 1 instead of 2 is that Box considers 'versions' to be a versions other than 'current'
200
- v1 = versions.first
201
-
202
- puts "promote old version of file"
203
- newer_version = BOX_CLIENT.promote_old_version_of_file(test_file, v1)
204
- versions = BOX_CLIENT.versions_of_file(test_file)
205
- expect(versions.count).to eq(2)
206
-
207
- puts "delete old version of file"
208
- result = BOX_CLIENT.delete_old_version_of_file(test_file,v1)
209
- versions = BOX_CLIENT.versions_of_file(test_file)
210
- expect(versions.count).to eq(2) #this is still 2 because with Box you can restore a trashed old version
211
-
212
- puts "get file thumbnail"
213
- thumb = BOX_CLIENT.thumbnail(test_file)
214
- expect(thumb).not_to be_nil
215
-
216
- puts "create shared link for file"
217
- updated_file = BOX_CLIENT.create_shared_link_for_file(test_file, access: :open)
218
- expect(updated_file.shared_link.access).to eq("open")
219
-
220
- puts "create password-protected shared link for file"
221
- updated_file = BOX_CLIENT.create_shared_link_for_file(test_file, password: 'password')
222
- expect(updated_file.shared_link.is_password_enabled).to eq(true)
223
-
224
- puts "disable shared link for file"
225
- updated_file = BOX_CLIENT.disable_shared_link_for_file(test_file)
226
- expect(updated_file.shared_link).to be_nil
227
-
228
- puts "copy file"
229
- new_file_name = "copy of #{TEST_FILE_NAME}"
230
- new_file = BOX_CLIENT.copy_file(test_file, @test_folder, name: new_file_name)
231
- expect(new_file.name).to eq(new_file_name)
232
- NEW_FILE = new_file
233
-
234
- puts "move file"
235
- new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder)
236
- test_file = BOX_CLIENT.move_file(test_file, new_folder.id)
237
- expect(test_file.parent.id).to eq(new_folder.id)
238
-
239
- puts "delete file"
240
- result = BOX_CLIENT.delete_file(NEW_FILE)
241
- expect(result).to eq({})
242
-
243
- puts "get trashed file info"
244
- trashed_file = BOX_CLIENT.trashed_file(NEW_FILE)
245
- expect(trashed_file.item_status).to eq("trashed")
246
-
247
- puts "restore trashed file"
248
- restored_file = BOX_CLIENT.restore_trashed_file(NEW_FILE)
249
- expect(restored_file.item_status).to eq("active")
250
-
251
- puts "trash and permanently delete file"
252
- BOX_CLIENT.delete_file(NEW_FILE)
253
- result = BOX_CLIENT.delete_trashed_file(NEW_FILE)
254
- expect(result).to eq({})
255
- end
256
-
257
- #rake spec SPEC_OPTS="-e \"invokes web links operations"\"
258
- it 'invokes web links operations' do
259
- puts "create web link"
260
- web_link = BOX_CLIENT.create_web_link(TEST_WEB_URL, '0', name: "my new link", description: "link description...")
261
- expect(web_link.url).to eq(TEST_WEB_URL)
262
-
263
- puts "get web link"
264
- web_link_new = BOX_CLIENT.get_web_link(web_link)
265
- expect(web_link_new.id).to eq(web_link.id)
266
-
267
- puts "update web link"
268
- updated_web_link = BOX_CLIENT.update_web_link(web_link, name: 'new name', description: 'new description', url: TEST_WEB_URL2)
269
- expect(updated_web_link.url).to eq(TEST_WEB_URL2)
270
-
271
- puts "delete web link"
272
- result = BOX_CLIENT.delete_web_link(web_link)
273
- expect(result).to eq({})
274
- end
275
-
276
- #rake spec SPEC_OPTS="-e \"invokes watermarking operations"\"
277
- it 'invokes watermarking operations' do
278
- test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
279
- folder = BOX_CLIENT.folder(@test_folder)
280
-
281
- puts "apply watermark on file"
282
- watermark = BOX_CLIENT.apply_watermark_on_file(test_file)
283
- expect(watermark.watermark).to_not be_nil
284
-
285
- puts "get watermark on file"
286
- watermark = BOX_CLIENT.get_watermark_on_file(test_file)
287
- expect(watermark.watermark).to_not be_nil
288
-
289
- puts "remove watermark on file"
290
- result = BOX_CLIENT.remove_watermark_on_file(test_file)
291
- expect(result).to eq({})
292
-
293
- puts "apply watermark on folder"
294
- watermark = BOX_CLIENT.apply_watermark_on_folder(folder)
295
- expect(watermark.watermark).to_not be_nil
296
-
297
- puts "get watermark on folder"
298
- watermark = BOX_CLIENT.get_watermark_on_folder(folder)
299
- expect(watermark.watermark).to_not be_nil
300
-
301
- puts "remove watermark on folder"
302
- result = BOX_CLIENT.remove_watermark_on_folder(folder)
303
- expect(result).to eq({})
304
- end
305
-
306
- #rake spec SPEC_OPTS="-e \"invokes user operations"\"
307
- it "invokes user operations" do
308
- puts "inspect current user"
309
- user = BOX_CLIENT.current_user
310
- expect(user.status).to eq('active')
311
- user = BOX_CLIENT.me(fields: [:role])
312
- expect(user.role).to_not be_nil
313
-
314
- puts "inspect a user"
315
- user = BOX_CLIENT.user(@test_user)
316
- expect(user.id).to eq(@test_user.id)
317
-
318
- puts "inspect all users"
319
- all_users = BOX_CLIENT.all_users()
320
- test_user = all_users.find{|u| u.id == @test_user.id}
321
- expect(test_user).to_not be_nil
322
-
323
- #create user is tested in the before method
324
-
325
- puts "update user"
326
- new_name = "Chuck Nevitt"
327
- user = BOX_CLIENT.update_user(@test_user, name: new_name)
328
- expect(user.name).to eq(new_name)
329
-
330
- puts "add email alias for user"
331
- email_alias = "test-boxr-user-alias@boxntest.com" #{('a'..'z').to_a.shuffle[0,10].join}.com"
332
- new_alias = BOX_CLIENT.add_email_alias_for_user(@test_user, email_alias)
333
- expect(new_alias.type).to eq('email_alias')
334
-
335
- puts "get email aliases for user"
336
- email_aliases = BOX_CLIENT.email_aliases_for_user(@test_user)
337
- expect(email_aliases.first.id).to eq(new_alias.id)
338
-
339
- puts "remove email alias for user"
340
- result = BOX_CLIENT.remove_email_alias_for_user(@test_user, new_alias.id)
341
- expect(result).to eq({})
342
-
343
- puts "delete user"
344
- result = BOX_CLIENT.delete_user(@test_user, force: true)
345
- expect(result).to eq({})
346
- end
347
-
348
- #rake spec SPEC_OPTS="-e \"invokes group operations"\"
349
- it "invokes group operations" do
350
- puts "create group"
351
- group = BOX_CLIENT.create_group(TEST_GROUP_NAME)
352
- expect(group.name).to eq(TEST_GROUP_NAME)
353
-
354
- puts "inspect groups"
355
- groups = BOX_CLIENT.groups
356
- test_group = groups.find{|g| g.name == TEST_GROUP_NAME}
357
- expect(test_group).to_not be_nil
358
-
359
- puts "update group"
360
- new_name = "Test Boxr Group Renamed"
361
- group = BOX_CLIENT.update_group(test_group, new_name)
362
- expect(group.name).to eq(new_name)
363
- group = BOX_CLIENT.rename_group(test_group,TEST_GROUP_NAME)
364
- expect(group.name).to eq(TEST_GROUP_NAME)
365
-
366
- puts "add user to group"
367
- group_membership = BOX_CLIENT.add_user_to_group(@test_user, test_group)
368
- expect(group_membership.user.id).to eq(@test_user.id)
369
- expect(group_membership.group.id).to eq(test_group.id)
370
- membership = group_membership
371
-
372
- puts "inspect group membership"
373
- group_membership = BOX_CLIENT.group_membership(membership)
374
- expect(group_membership.id).to eq(membership.id)
375
-
376
- puts "inspect group memberships"
377
- group_memberships = BOX_CLIENT.group_memberships(test_group)
378
- expect(group_memberships.count).to eq(1)
379
- expect(group_memberships.first.id).to eq(membership.id)
380
-
381
- puts "inspect group memberships for a user"
382
- group_memberships = BOX_CLIENT.group_memberships_for_user(@test_user)
383
- expect(group_memberships.count).to eq(1)
384
- expect(group_memberships.first.id).to eq(membership.id)
385
-
386
- puts "inspect group memberships for me"
387
- #this is whatever user your developer token is tied to
388
- group_memberships = BOX_CLIENT.group_memberships_for_me
389
- expect(group_memberships).to be_a(Array)
390
-
391
- puts "update group membership"
392
- group_membership = BOX_CLIENT.update_group_membership(membership, :admin)
393
- expect(group_membership.role).to eq("admin")
394
-
395
- puts "delete group membership"
396
- result = BOX_CLIENT.delete_group_membership(membership)
397
- expect(result).to eq({})
398
- group_memberships = BOX_CLIENT.group_memberships_for_user(@test_user)
399
- expect(group_memberships.count).to eq(0)
400
-
401
- puts "inspect group collaborations"
402
- group_collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: test_group.id, type: :group}, :editor)
403
- expect(group_collaboration.accessible_by.id).to eq(test_group.id)
404
-
405
- puts "delete group"
406
- response = BOX_CLIENT.delete_group(test_group)
407
- expect(response).to eq({})
408
- end
409
-
410
- #rake spec SPEC_OPTS="-e \"invokes comment operations"\"
411
- it "invokes comment operations" do
412
- new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
413
- test_file = new_file
414
-
415
- puts "add comment to file"
416
- comment = BOX_CLIENT.add_comment_to_file(test_file, message: COMMENT_MESSAGE)
417
- expect(comment.message).to eq(COMMENT_MESSAGE)
418
- COMMENT = comment
419
-
420
- puts "reply to comment"
421
- reply = BOX_CLIENT.reply_to_comment(COMMENT, message: REPLY_MESSAGE)
422
- expect(reply.message).to eq(REPLY_MESSAGE)
423
-
424
- puts "get file comments"
425
- comments = BOX_CLIENT.file_comments(test_file)
426
- expect(comments.count).to eq(2)
427
-
428
- puts "update a comment"
429
- comment = BOX_CLIENT.change_comment(COMMENT, CHANGED_COMMENT_MESSAGE)
430
- expect(comment.message).to eq(CHANGED_COMMENT_MESSAGE)
431
-
432
- puts "get comment info"
433
- comment = BOX_CLIENT.comment(COMMENT)
434
- expect(comment.id).to eq(COMMENT.id)
435
-
436
- puts "delete comment"
437
- result = BOX_CLIENT.delete_comment(COMMENT)
438
- expect(result).to eq({})
439
- end
440
-
441
- #rake spec SPEC_OPTS="-e \"invokes collaborations operations"\"
442
- it "invokes collaborations operations" do
443
- puts "add collaboration"
444
- collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :viewer_uploader)
445
- expect(collaboration.accessible_by.id).to eq(@test_user.id)
446
- COLLABORATION = collaboration
447
-
448
- puts "inspect collaboration"
449
- collaboration = BOX_CLIENT.collaboration(COLLABORATION)
450
- expect(collaboration.id).to eq(COLLABORATION.id)
451
-
452
- puts "edit collaboration"
453
- collaboration = BOX_CLIENT.edit_collaboration(COLLABORATION, role: "viewer uploader")
454
- expect(collaboration.role).to eq("viewer uploader")
455
-
456
- puts "inspect folder collaborations"
457
- collaborations = BOX_CLIENT.folder_collaborations(@test_folder)
458
- expect(collaborations.count).to eq(1)
459
- expect(collaborations[0].id).to eq(COLLABORATION.id)
460
-
461
- puts "remove collaboration"
462
- result = BOX_CLIENT.remove_collaboration(COLLABORATION)
463
- expect(result).to eq({})
464
- collaborations = BOX_CLIENT.folder_collaborations(@test_folder)
465
- expect(collaborations.count).to eq(0)
466
-
467
- puts "inspect pending collaborations"
468
- pending_collaborations = BOX_CLIENT.pending_collaborations
469
- expect(pending_collaborations).to eq([])
470
-
471
- puts "add invalid collaboration"
472
- expect { BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :invalid_role)}.to raise_error
473
- end
474
-
475
- #rake spec SPEC_OPTS="-e \"invokes task operations"\"
476
- it "invokes task operations" do
477
- test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
478
- collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :editor)
479
-
480
- puts "create task"
481
- new_task = BOX_CLIENT.create_task(test_file, message: TEST_TASK_MESSAGE)
482
- expect(new_task.message).to eq(TEST_TASK_MESSAGE)
483
- TEST_TASK = new_task
484
-
485
- puts "inspect file tasks"
486
- tasks = BOX_CLIENT.file_tasks(test_file)
487
- expect(tasks.first.id).to eq(TEST_TASK.id)
488
-
489
- puts "inspect task"
490
- task = BOX_CLIENT.task(TEST_TASK)
491
- expect(task.id).to eq(TEST_TASK.id)
492
-
493
- puts "update task"
494
- NEW_TASK_MESSAGE = "new task message"
495
- updated_task = BOX_CLIENT.update_task(TEST_TASK, message: NEW_TASK_MESSAGE)
496
- expect(updated_task.message).to eq(NEW_TASK_MESSAGE)
497
-
498
- puts "create task assignment"
499
- task_assignment = BOX_CLIENT.create_task_assignment(TEST_TASK, assign_to: @test_user.id)
500
- expect(task_assignment.assigned_to.id).to eq(@test_user.id)
501
- TASK_ASSIGNMENT = task_assignment
502
-
503
- puts "inspect task assignment"
504
- task_assignment = BOX_CLIENT.task_assignment(TASK_ASSIGNMENT)
505
- expect(task_assignment.id).to eq(TASK_ASSIGNMENT.id)
506
-
507
- puts "inspect task assignments"
508
- task_assignments = BOX_CLIENT.task_assignments(TEST_TASK)
509
- expect(task_assignments.count).to eq(1)
510
- expect(task_assignments[0].id).to eq(TASK_ASSIGNMENT.id)
511
-
512
- #TODO: can't do this test yet because the test user needs to confirm their email address before you can do this
513
- puts "update task assignment"
514
- expect {
515
- box_client_as_test_user = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'], as_user_id: @test_user.id)
516
- new_message = "Updated task message"
517
- task_assignment = box_client_as_test_user.update_task_assignment(TEST_TASK, resolution_state: :completed)
518
- expect(task_assignment.resolution_state).to eq('completed')
519
- }.to raise_error
520
-
521
- puts "delete task assignment"
522
- result = BOX_CLIENT.delete_task_assignment(TASK_ASSIGNMENT)
523
- expect(result).to eq({})
524
-
525
- puts "delete task"
526
- result = BOX_CLIENT.delete_task(TEST_TASK)
527
- expect(result).to eq({})
528
- end
529
-
530
- #rake spec SPEC_OPTS="-e \"invokes file metadata operations"\"
531
- it "invokes file metadata operations" do
532
- test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
533
-
534
- puts "create metadata"
535
- meta = {"a" => "hello", "b" => "world"}
536
- metadata = BOX_CLIENT.create_metadata(test_file, meta)
537
- expect(metadata.a).to eq("hello")
538
-
539
- puts "update metadata"
540
- metadata = BOX_CLIENT.update_metadata(test_file, {op: :replace, path: "/b", value: "there"})
541
- expect(metadata.b).to eq("there")
542
- metadata = BOX_CLIENT.update_metadata(test_file, [{op: :replace, path: "/b", value: "friend"}])
543
- expect(metadata.b).to eq("friend")
544
-
545
- puts "get metadata"
546
- metadata = BOX_CLIENT.metadata(test_file)
547
- expect(metadata.a).to eq("hello")
548
-
549
- puts "delete metadata"
550
- result = BOX_CLIENT.delete_metadata(test_file)
551
- expect(result).to eq({})
552
- end
553
-
554
- #rake spec SPEC_OPTS="-e \"invokes folder metadata operations"\"
555
- #NOTE: this test will fail unless you create a metadata template called 'test' with two attributes: 'a' of type text, and 'b' of type text
556
- it "invokes folder metadata operations" do
557
- new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder)
558
-
559
- puts "create folder metadata"
560
- meta = {"a" => "hello", "b" => "world"}
561
- metadata = BOX_CLIENT.create_folder_metadata(new_folder, meta, "enterprise", "test")
562
- expect(metadata.a).to eq("hello")
563
-
564
- puts "update folder metadata"
565
- metadata = BOX_CLIENT.update_folder_metadata(new_folder, {op: :replace, path: "/b", value: "there"}, "enterprise", "test")
566
- expect(metadata.b).to eq("there")
567
- metadata = BOX_CLIENT.update_folder_metadata(new_folder, [{op: :replace, path: "/b", value: "friend"}], "enterprise", "test")
568
- expect(metadata.b).to eq("friend")
569
-
570
- puts "get folder metadata"
571
- metadata = BOX_CLIENT.folder_metadata(new_folder, "enterprise", "test")
572
- expect(metadata.a).to eq("hello")
573
-
574
- puts "delete folder metadata"
575
- result = BOX_CLIENT.delete_folder_metadata(new_folder, "enterprise", "test")
576
- expect(result).to eq({})
577
- end
578
-
579
- #rake spec SPEC_OPTS="-e \"invokes search operations"\"
580
- it "invokes search operations" do
581
- #the issue with this test is that Box can take between 5-10 minutes to index any content uploaded; this is just a smoke test
582
- #so we are searching for something that should return zero results
583
- puts "perform search"
584
- results = BOX_CLIENT.search("sdlfjuwnsljsdfuqpoiqweouyvnnadsfkjhiuweruywerbjvhvkjlnasoifyukhenlwdflnsdvoiuawfydfjh")
585
- expect(results).to eq([])
586
- end
587
-
588
38
  end