onlyoffice-docs_integration_sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/onlyoffice/docs_integration_sdk/document_editor/config.rb +1479 -0
- data/lib/onlyoffice/docs_integration_sdk/document_editor/config_test.rb +1713 -0
- data/lib/onlyoffice/docs_integration_sdk/document_editor.rb +29 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/command.rb +417 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/command_test.rb +672 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/conversion.rb +477 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/conversion_test.rb +682 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/healthcheck.rb +101 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/healthcheck_test.rb +209 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/jwt.rb +116 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/jwt_test.rb +70 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/response.rb +73 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/response_test.rb +49 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/service.rb +44 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/ua.rb +31 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client/ua_test.rb +35 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client.rb +321 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server/client_test.rb +1259 -0
- data/lib/onlyoffice/docs_integration_sdk/document_server.rb +29 -0
- data/lib/onlyoffice/docs_integration_sdk/document_storage/callback.rb +276 -0
- data/lib/onlyoffice/docs_integration_sdk/document_storage/callback_test.rb +291 -0
- data/lib/onlyoffice/docs_integration_sdk/document_storage.rb +29 -0
- data/lib/onlyoffice/docs_integration_sdk/jwt.rb +448 -0
- data/lib/onlyoffice/docs_integration_sdk/jwt_test.rb +598 -0
- data/lib/onlyoffice/docs_integration_sdk/test_test.rb +113 -0
- data/lib/onlyoffice/docs_integration_sdk/version.rb +26 -0
- data/lib/onlyoffice/docs_integration_sdk/version_test.rb +33 -0
- data/lib/onlyoffice/docs_integration_sdk.rb +31 -0
- data/lib/onlyoffice.rb +21 -0
- metadata +283 -0
@@ -0,0 +1,672 @@
|
|
1
|
+
#
|
2
|
+
# (c) Copyright Ascensio System SIA 2025
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
# typed: true
|
18
|
+
# frozen_string_literal: true
|
19
|
+
|
20
|
+
require "test/unit"
|
21
|
+
require_relative "../../jwt"
|
22
|
+
require_relative "../../test_test"
|
23
|
+
require_relative "../client_test"
|
24
|
+
require_relative "command"
|
25
|
+
|
26
|
+
module Onlyoffice
|
27
|
+
module DocsIntegrationSdk
|
28
|
+
module DocumentServer
|
29
|
+
class Client
|
30
|
+
class CommandService
|
31
|
+
class ErrorTest < ::Test::Unit::TestCase
|
32
|
+
extend T::Sig
|
33
|
+
include Test::DescriptiveEnumMarshalling
|
34
|
+
|
35
|
+
sig {override.returns(T::Array[[Integer, String, Error]])}
|
36
|
+
def cases
|
37
|
+
[
|
38
|
+
[
|
39
|
+
0,
|
40
|
+
"No errors",
|
41
|
+
Error::None,
|
42
|
+
],
|
43
|
+
[
|
44
|
+
1,
|
45
|
+
"Document key is missing or no document with such key could be found",
|
46
|
+
Error::MissingDocumentKey,
|
47
|
+
],
|
48
|
+
[
|
49
|
+
2,
|
50
|
+
"Callback url not correct",
|
51
|
+
Error::IncorrectCallbackUrl,
|
52
|
+
],
|
53
|
+
[
|
54
|
+
3,
|
55
|
+
"Internal server error",
|
56
|
+
Error::InternalError,
|
57
|
+
],
|
58
|
+
[
|
59
|
+
4,
|
60
|
+
"No changes were applied to the document before the forcesave command was received",
|
61
|
+
Error::NoChanges,
|
62
|
+
],
|
63
|
+
[
|
64
|
+
5,
|
65
|
+
"Command not correct",
|
66
|
+
Error::IncorrectCommand,
|
67
|
+
],
|
68
|
+
[
|
69
|
+
6,
|
70
|
+
"Invalid token",
|
71
|
+
Error::InvalidToken,
|
72
|
+
],
|
73
|
+
]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Request
|
78
|
+
class CTest < ::Test::Unit::TestCase
|
79
|
+
extend T::Sig
|
80
|
+
include Test::BasicEnumMarshalling
|
81
|
+
|
82
|
+
sig {override.returns(T::Array[[String, C]])}
|
83
|
+
def cases
|
84
|
+
[
|
85
|
+
["deleteForgotten", C::DeleteForgotten],
|
86
|
+
["drop", C::Drop],
|
87
|
+
["forcesave", C::Forcesave],
|
88
|
+
["getForgotten", C::GetForgotten],
|
89
|
+
["getForgottenList", C::GetForgottenList],
|
90
|
+
["info", C::Info],
|
91
|
+
["license", C::License],
|
92
|
+
["meta", C::Meta],
|
93
|
+
["version", C::Version],
|
94
|
+
]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class LicenseTest < ::Test::Unit::TestCase
|
99
|
+
extend T::Sig
|
100
|
+
include Test::StructMarshalling
|
101
|
+
|
102
|
+
sig {override.returns(T::Array[[T.untyped, License]])}
|
103
|
+
def cases
|
104
|
+
[
|
105
|
+
[
|
106
|
+
{},
|
107
|
+
License.new,
|
108
|
+
],
|
109
|
+
[
|
110
|
+
{
|
111
|
+
"end_date" => "2025-01-01",
|
112
|
+
"trial" => true,
|
113
|
+
"customization" => true,
|
114
|
+
"connections" => 10,
|
115
|
+
"connections_view" => 10,
|
116
|
+
"users_count" => 10,
|
117
|
+
"users_view_count" => 10,
|
118
|
+
"users_expire" => 10,
|
119
|
+
},
|
120
|
+
License.new(
|
121
|
+
end_date: "2025-01-01",
|
122
|
+
trial: true,
|
123
|
+
customization: true,
|
124
|
+
connections: 10,
|
125
|
+
connections_view: 10,
|
126
|
+
users_count: 10,
|
127
|
+
users_view_count: 10,
|
128
|
+
users_expire: 10,
|
129
|
+
),
|
130
|
+
],
|
131
|
+
]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class Server
|
136
|
+
class ResultTypeTest < ::Test::Unit::TestCase
|
137
|
+
extend T::Sig
|
138
|
+
include Test::DescriptiveEnumMarshalling
|
139
|
+
|
140
|
+
sig {override.returns(T::Array[[Integer, String, ResultType]])}
|
141
|
+
def cases
|
142
|
+
[
|
143
|
+
[
|
144
|
+
1,
|
145
|
+
"An error occurred",
|
146
|
+
ResultType::Error,
|
147
|
+
],
|
148
|
+
[
|
149
|
+
2,
|
150
|
+
"The license expired",
|
151
|
+
ResultType::LicenseExpired,
|
152
|
+
],
|
153
|
+
[
|
154
|
+
3,
|
155
|
+
"The license is still available",
|
156
|
+
ResultType::LicenseAvailable,
|
157
|
+
],
|
158
|
+
[
|
159
|
+
6,
|
160
|
+
"The trial license expired",
|
161
|
+
ResultType::TrialLicenseExpired,
|
162
|
+
],
|
163
|
+
]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class PackageTypeTest < ::Test::Unit::TestCase
|
168
|
+
extend T::Sig
|
169
|
+
include Test::BasicEnumMarshalling
|
170
|
+
|
171
|
+
sig {override.returns(T::Array[[Integer, PackageType]])}
|
172
|
+
def cases
|
173
|
+
[
|
174
|
+
[0, PackageType::OpenSource],
|
175
|
+
[1, PackageType::Enterprise],
|
176
|
+
[2, PackageType::Developer],
|
177
|
+
]
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class ServerTest < ::Test::Unit::TestCase
|
183
|
+
extend T::Sig
|
184
|
+
include Test::StructMarshalling
|
185
|
+
|
186
|
+
sig {override.returns(T::Array[[T.untyped, Server]])}
|
187
|
+
def cases
|
188
|
+
[
|
189
|
+
[
|
190
|
+
{},
|
191
|
+
Server.new,
|
192
|
+
],
|
193
|
+
[
|
194
|
+
{
|
195
|
+
"resultType" => 1,
|
196
|
+
"packageType" => 1,
|
197
|
+
"buildDate" => "2025-01-01",
|
198
|
+
"buildVersion" => "1.0",
|
199
|
+
"buildNumber" => 1,
|
200
|
+
},
|
201
|
+
Server.new(
|
202
|
+
result_type: Server::ResultType::Error,
|
203
|
+
package_type: Server::PackageType::Enterprise,
|
204
|
+
build_date: "2025-01-01",
|
205
|
+
build_version: "1.0",
|
206
|
+
build_number: 1,
|
207
|
+
),
|
208
|
+
],
|
209
|
+
]
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
class Quota
|
214
|
+
class UserTest < ::Test::Unit::TestCase
|
215
|
+
extend T::Sig
|
216
|
+
include Test::StructMarshalling
|
217
|
+
|
218
|
+
sig {override.returns(T::Array[[T.untyped, User]])}
|
219
|
+
def cases
|
220
|
+
[
|
221
|
+
[
|
222
|
+
{},
|
223
|
+
User.new,
|
224
|
+
],
|
225
|
+
[
|
226
|
+
{
|
227
|
+
"userid" => "user_1",
|
228
|
+
"expire" => "2025-01-01",
|
229
|
+
},
|
230
|
+
User.new(
|
231
|
+
userid: "user_1",
|
232
|
+
expire: "2025-01-01",
|
233
|
+
),
|
234
|
+
],
|
235
|
+
]
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
class QuotaTest < ::Test::Unit::TestCase
|
241
|
+
extend T::Sig
|
242
|
+
include Test::StructMarshalling
|
243
|
+
|
244
|
+
sig {override.returns(T::Array[[T.untyped, Quota]])}
|
245
|
+
def cases
|
246
|
+
[
|
247
|
+
[
|
248
|
+
{},
|
249
|
+
Quota.new,
|
250
|
+
],
|
251
|
+
[
|
252
|
+
{
|
253
|
+
"users" => [
|
254
|
+
{
|
255
|
+
"userid" => "user_1",
|
256
|
+
},
|
257
|
+
],
|
258
|
+
"users_view" => [
|
259
|
+
{
|
260
|
+
"userid" => "user_1",
|
261
|
+
},
|
262
|
+
],
|
263
|
+
},
|
264
|
+
Quota.new(
|
265
|
+
users: [
|
266
|
+
Quota::User.new(
|
267
|
+
userid: "user_1",
|
268
|
+
),
|
269
|
+
],
|
270
|
+
users_view: [
|
271
|
+
Quota::User.new(
|
272
|
+
userid: "user_1",
|
273
|
+
),
|
274
|
+
],
|
275
|
+
),
|
276
|
+
],
|
277
|
+
]
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
class MetaTest < ::Test::Unit::TestCase
|
282
|
+
extend T::Sig
|
283
|
+
include Test::StructMarshalling
|
284
|
+
|
285
|
+
sig {override.returns(T::Array[[T.untyped, Meta]])}
|
286
|
+
def cases
|
287
|
+
[
|
288
|
+
[
|
289
|
+
{},
|
290
|
+
Meta.new,
|
291
|
+
],
|
292
|
+
[
|
293
|
+
{
|
294
|
+
"title" => "Title",
|
295
|
+
},
|
296
|
+
Meta.new(
|
297
|
+
title: "Title",
|
298
|
+
),
|
299
|
+
],
|
300
|
+
]
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
class RequestTest < ::Test::Unit::TestCase
|
306
|
+
extend T::Sig
|
307
|
+
include Test::StructMarshalling
|
308
|
+
|
309
|
+
sig {override.returns(T::Array[[T.untyped, Request]])}
|
310
|
+
def cases
|
311
|
+
[
|
312
|
+
[
|
313
|
+
{},
|
314
|
+
Request.new,
|
315
|
+
],
|
316
|
+
[
|
317
|
+
{
|
318
|
+
"c" => "deleteForgotten",
|
319
|
+
"key" => "***",
|
320
|
+
"users" => ["User 1", "User 2"],
|
321
|
+
"userdata" => "Data",
|
322
|
+
"license" => {
|
323
|
+
"end_date" => "2025-01-01",
|
324
|
+
},
|
325
|
+
"server" => {
|
326
|
+
"resultType" => 1,
|
327
|
+
},
|
328
|
+
"quota" => {
|
329
|
+
"users" => [],
|
330
|
+
},
|
331
|
+
"meta" => {
|
332
|
+
"title" => "Title",
|
333
|
+
},
|
334
|
+
},
|
335
|
+
Request.new(
|
336
|
+
c: Request::C::DeleteForgotten,
|
337
|
+
key: "***",
|
338
|
+
users: ["User 1", "User 2"],
|
339
|
+
userdata: "Data",
|
340
|
+
license: Request::License.new(
|
341
|
+
end_date: "2025-01-01",
|
342
|
+
),
|
343
|
+
server: Request::Server.new(
|
344
|
+
result_type: Request::Server::ResultType::Error,
|
345
|
+
),
|
346
|
+
quota: Request::Quota.new(
|
347
|
+
users: [],
|
348
|
+
),
|
349
|
+
meta: Request::Meta.new(
|
350
|
+
title: "Title",
|
351
|
+
),
|
352
|
+
),
|
353
|
+
],
|
354
|
+
]
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
class ResultTest < ::Test::Unit::TestCase
|
359
|
+
extend T::Sig
|
360
|
+
include Test::StructMarshalling
|
361
|
+
|
362
|
+
sig {override.returns(T::Array[[T.untyped, Result]])}
|
363
|
+
def cases
|
364
|
+
[
|
365
|
+
[
|
366
|
+
{},
|
367
|
+
Result.new,
|
368
|
+
],
|
369
|
+
[
|
370
|
+
{
|
371
|
+
"key" => "***",
|
372
|
+
"url" => "http://example.com/",
|
373
|
+
"keys" => ["Key 1", "Key 2"],
|
374
|
+
"users" => ["User 1", "User 2"],
|
375
|
+
"version" => "1.0",
|
376
|
+
},
|
377
|
+
Result.new(
|
378
|
+
key: "***",
|
379
|
+
url: "http://example.com/",
|
380
|
+
keys: ["Key 1", "Key 2"],
|
381
|
+
users: ["User 1", "User 2"],
|
382
|
+
version: "1.0",
|
383
|
+
),
|
384
|
+
],
|
385
|
+
]
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
class CommandServiceTest < ::Test::Unit::TestCase
|
391
|
+
extend T::Sig
|
392
|
+
include Test::DocumentServer::Client
|
393
|
+
|
394
|
+
sig {returns(String)}
|
395
|
+
def req_s
|
396
|
+
'{"c":"info"}'
|
397
|
+
end
|
398
|
+
|
399
|
+
sig {returns(T::Hash[String, T.untyped])}
|
400
|
+
def req_h
|
401
|
+
{"c" => "info"}
|
402
|
+
end
|
403
|
+
|
404
|
+
sig {returns(CommandService::Request)}
|
405
|
+
def req_o
|
406
|
+
req = CommandService::Request.new(
|
407
|
+
c: CommandService::Request::C::Info,
|
408
|
+
)
|
409
|
+
end
|
410
|
+
|
411
|
+
sig {returns(String)}
|
412
|
+
def res_s
|
413
|
+
'{"key":"***"}'
|
414
|
+
end
|
415
|
+
|
416
|
+
sig {returns(CommandService::Result)}
|
417
|
+
def res_o
|
418
|
+
CommandService::Result.new(
|
419
|
+
key: "***",
|
420
|
+
)
|
421
|
+
end
|
422
|
+
|
423
|
+
def test_do_does
|
424
|
+
t = self
|
425
|
+
|
426
|
+
m = "POST"
|
427
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
428
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
429
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
430
|
+
|
431
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
432
|
+
t.check_request_basics(m, p, req)
|
433
|
+
t.check_request_headers_with_content_type(m, u, req)
|
434
|
+
t.assert_equal(t.req_s, req.body)
|
435
|
+
t.assert_nil(body)
|
436
|
+
t.assert_nil(block)
|
437
|
+
t.create_ok(t.res_s)
|
438
|
+
end
|
439
|
+
|
440
|
+
c = Client.new(base_uri: u, http: h)
|
441
|
+
|
442
|
+
com, res = c.command.do(req_o)
|
443
|
+
assert_nil(res.error)
|
444
|
+
|
445
|
+
assert_equal(res_s, res.response.body)
|
446
|
+
# todo: assert_equal(res_o, com)
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_do_does_with_the_subpath
|
450
|
+
t = self
|
451
|
+
|
452
|
+
m = "POST"
|
453
|
+
u = T.cast(URI.parse("http://localhost:8080/sub/"), URI::HTTP)
|
454
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
455
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
456
|
+
|
457
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
458
|
+
t.check_request_basics(m, p, req)
|
459
|
+
t.check_request_headers_with_content_type(m, u, req)
|
460
|
+
t.assert_equal(t.req_s, req.body)
|
461
|
+
t.assert_nil(body)
|
462
|
+
t.assert_nil(block)
|
463
|
+
t.create_ok(t.res_s)
|
464
|
+
end
|
465
|
+
|
466
|
+
c = Client.new(base_uri: u, http: h)
|
467
|
+
|
468
|
+
com, res = c.command.do(req_o)
|
469
|
+
assert_nil(res.error)
|
470
|
+
|
471
|
+
assert_equal(res_s, res.response.body)
|
472
|
+
# todo: assert_equal(res_o, com)
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_do_does_with_the_user_agent
|
476
|
+
t = self
|
477
|
+
|
478
|
+
m = "POST"
|
479
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
480
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
481
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
482
|
+
|
483
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
484
|
+
t.check_request_basics(m, p, req)
|
485
|
+
t.check_request_headers_with_content_type_and_custom_user_agent(m, u, "my-agent", req)
|
486
|
+
t.assert_equal(t.req_s, req.body)
|
487
|
+
t.assert_nil(body)
|
488
|
+
t.assert_nil(block)
|
489
|
+
t.create_ok(t.res_s)
|
490
|
+
end
|
491
|
+
|
492
|
+
c = Client.new(base_uri: u, http: h, user_agent: "my-agent")
|
493
|
+
|
494
|
+
com, res = c.command.do(req_o)
|
495
|
+
assert_nil(res.error)
|
496
|
+
|
497
|
+
assert_equal(res_s, res.response.body)
|
498
|
+
# todo: assert_equal(res_o, com)
|
499
|
+
end
|
500
|
+
|
501
|
+
def test_do_does_with_the_jwt
|
502
|
+
t = self
|
503
|
+
|
504
|
+
w = DocsIntegrationSdk::Jwt.new(secret: "***")
|
505
|
+
m = "POST"
|
506
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
507
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
508
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
509
|
+
|
510
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
511
|
+
t.check_request_basics(m, p, req)
|
512
|
+
t.check_request_headers_with_jwt(m, u, w, t.req_h, req)
|
513
|
+
t.check_request_body_with_jwt(w, t.req_h, req)
|
514
|
+
t.assert_nil(body)
|
515
|
+
t.assert_nil(block)
|
516
|
+
t.create_ok(t.res_s)
|
517
|
+
end
|
518
|
+
|
519
|
+
j = Jwt.new(jwt: w)
|
520
|
+
c = Client.new(base_uri: u, http: h).with_jwt(j)
|
521
|
+
|
522
|
+
com, res = c.command.do(req_o)
|
523
|
+
assert_nil(res.error)
|
524
|
+
|
525
|
+
assert_equal(res_s, res.response.body)
|
526
|
+
# todo: assert_equal(res_o, com)
|
527
|
+
end
|
528
|
+
|
529
|
+
def test_do_returns_an_error_if_the_response_body_is_invalid_json
|
530
|
+
t = self
|
531
|
+
|
532
|
+
m = "POST"
|
533
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
534
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
535
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
536
|
+
|
537
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
538
|
+
t.check_request_basics(m, p, req)
|
539
|
+
t.check_request_headers_with_content_type(m, u, req)
|
540
|
+
t.assert_equal(t.req_s, req.body)
|
541
|
+
t.assert_nil(body)
|
542
|
+
t.assert_nil(block)
|
543
|
+
t.create_ok("}")
|
544
|
+
end
|
545
|
+
|
546
|
+
c = Client.new(base_uri: u, http: h)
|
547
|
+
|
548
|
+
com, res = c.command.do(req_o)
|
549
|
+
|
550
|
+
err = T.cast(res.error, JSON::ParserError)
|
551
|
+
assert_equal("unexpected token at '}'", err.message)
|
552
|
+
|
553
|
+
assert_equal("}", res.response.body)
|
554
|
+
# todo: assert_equal(CommandService::Result.new, com)
|
555
|
+
end
|
556
|
+
|
557
|
+
def test_do_returns_an_error_if_the_doing_fails
|
558
|
+
for v in CommandService::Error.values
|
559
|
+
if v == CommandService::Error::None
|
560
|
+
next
|
561
|
+
end
|
562
|
+
|
563
|
+
t = self
|
564
|
+
|
565
|
+
m = "POST"
|
566
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
567
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
568
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
569
|
+
|
570
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
571
|
+
t.check_request_basics(m, p, req)
|
572
|
+
t.check_request_headers_with_content_type(m, u, req)
|
573
|
+
t.assert_equal(t.req_s, req.body)
|
574
|
+
t.assert_nil(body)
|
575
|
+
t.assert_nil(block)
|
576
|
+
t.create_ok("{\"error\":#{v.serialize}}")
|
577
|
+
end
|
578
|
+
|
579
|
+
c = Client.new(base_uri: u, http: h)
|
580
|
+
|
581
|
+
com, res = c.command.do(req_o)
|
582
|
+
assert_equal(v, res.error)
|
583
|
+
|
584
|
+
assert_equal("{\"error\":#{v.serialize}}", res.response.body)
|
585
|
+
# todo: assert_equal(CommandService::Result.new, com)
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_do_returns_an_error_if_the_doing_fails_with_an_unknown_error
|
590
|
+
t = self
|
591
|
+
|
592
|
+
m = "POST"
|
593
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
594
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
595
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
596
|
+
|
597
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
598
|
+
t.check_request_basics(m, p, req)
|
599
|
+
t.check_request_headers_with_content_type(m, u, req)
|
600
|
+
t.assert_equal(t.req_s, req.body)
|
601
|
+
t.assert_nil(body)
|
602
|
+
t.assert_nil(block)
|
603
|
+
t.create_ok('{"error":9999}')
|
604
|
+
end
|
605
|
+
|
606
|
+
c = Client.new(base_uri: u, http: h)
|
607
|
+
|
608
|
+
com, res = c.command.do(req_o)
|
609
|
+
|
610
|
+
err = T.cast(res.error, KeyError)
|
611
|
+
assert_equal("Enum Onlyoffice::DocsIntegrationSdk::DocumentServer::Client::CommandService::Error key not found: 9999", err.message)
|
612
|
+
|
613
|
+
assert_equal('{"error":9999}', res.response.body)
|
614
|
+
# todo: assert_equal(CommandService::Result.new, com)
|
615
|
+
end
|
616
|
+
|
617
|
+
def test_do_ignores_the_error_if_it_is_none
|
618
|
+
t = self
|
619
|
+
|
620
|
+
m = "POST"
|
621
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
622
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
623
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
624
|
+
|
625
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
626
|
+
t.check_request_basics(m, p, req)
|
627
|
+
t.check_request_headers_with_content_type(m, u, req)
|
628
|
+
t.assert_equal(t.req_s, req.body)
|
629
|
+
t.assert_nil(body)
|
630
|
+
t.assert_nil(block)
|
631
|
+
t.create_ok('{"error":0,"key":"***"}')
|
632
|
+
end
|
633
|
+
|
634
|
+
c = Client.new(base_uri: u, http: h)
|
635
|
+
|
636
|
+
com, res = c.command.do(req_o)
|
637
|
+
assert_nil(res.error)
|
638
|
+
|
639
|
+
assert_equal('{"error":0,"key":"***"}', res.response.body)
|
640
|
+
# todo: assert_equal(CommandService::Result.new, com)
|
641
|
+
end
|
642
|
+
|
643
|
+
def test_do_ignores_unknown_keys_in_the_response
|
644
|
+
t = self
|
645
|
+
|
646
|
+
m = "POST"
|
647
|
+
u = T.cast(URI.parse("http://localhost:8080/"), URI::HTTP)
|
648
|
+
p = T.cast(URI.join(u.to_s, "coauthoring/CommandService.ashx"), URI::HTTP)
|
649
|
+
h = T.let(Net::HTTP.new(u.hostname, u.port), Net::HTTP)
|
650
|
+
|
651
|
+
h.define_singleton_method(:request) do |req, body = nil, &block|
|
652
|
+
t.check_request_basics(m, p, req)
|
653
|
+
t.check_request_headers_with_content_type(m, u, req)
|
654
|
+
t.assert_equal(t.req_s, req.body)
|
655
|
+
t.assert_nil(body)
|
656
|
+
t.assert_nil(block)
|
657
|
+
t.create_ok('{"unknown":true}')
|
658
|
+
end
|
659
|
+
|
660
|
+
c = Client.new(base_uri: u, http: h)
|
661
|
+
|
662
|
+
com, res = c.command.do(req_o)
|
663
|
+
assert_nil(res.error)
|
664
|
+
|
665
|
+
assert_equal('{"unknown":true}', res.response.body)
|
666
|
+
# todo: assert_equal(CommandService::Result.new, com)
|
667
|
+
end
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
671
|
+
end
|
672
|
+
end
|