/
automation-tests.js
501 lines (421 loc) · 14.1 KB
/
automation-tests.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
var expect = chai.expect;
describe("Nuxeo automation", function() {
function failCallback(xhr, status, msg) {
throw msg
};
describe("CRUD", function() {
var container,
children = [],
createOp
it('create container document', function(done) {
function containerCreated(doc, status, xhr) {
container = doc;
expect(doc.uid).to.exist
done();
};
nuxeo.op("Document.Create", {
automationParams : {
params : {
type : "Folder",
name : "TestDocs",
properties : "dc:title=Test Docs \ndc:description=Simple container"
},
input : "doc:/"
}
}).fail(failCallback).execute({
done: containerCreated
});
})
it('create first child', function(done) {
function childCreated(doc, status, xhr) {
expect(doc.uid).to.exist
expect(doc.path.indexOf(container.path)).to.equal(0)
children.push(doc);
done()
};
createOp = nuxeo.op("Document.Create").param("type", "File").param("name", "TestFile1")
.input("doc:" + container.path).fail(failCallback).execute({ done: childCreated });
})
it('create second child', function(done) {
function childCreated(doc, status, xhr) {
expect(doc.uid).to.exist
expect(doc.path.indexOf(container.path)).to.equal(0)
children.push(doc);
done();
};
createOp.param("name", "TestFile2").execute({ done: childCreated });
})
it('update second child', function(done) {
function childUpdated(doc, status, xhr) {
expect(doc.properties["dc:description"]).to.equal("Simple File")
expect(doc.properties["dc:subjects"]).to.have.length(2);
done()
};
nuxeo.op("Document.Update", {
automationParams : {
params : {
save : "true",
properties : "dc:description=Simple File\ndc:subjects=subject1,subject2"
},
input : "doc:" + children[1].path
}
}).fail(failCallback).execute({ done: childUpdated });
})
it('get children', function(done) {
function childrenRetrieved(docs, status, xhr) {
expect(docs.entries).to.have.length(2)
done()
};
nuxeo.op("Document.GetChildren")
.input("doc:" + container.path).fail(failCallback)
.execute({ done: childrenRetrieved })
})
})
describe("query and pagination", function() {
var container
function createChild(index, done) {
function childCreated(doc) {
expect(doc.uid).to.exist
expect(doc.path.indexOf(container.path)).to.equal(0)
done()
}
nuxeo.op("Document.Create", {
automationParams : {
params : {
type : "File",
name : "TestFile" + index
},
input : "doc:" + container.path
}
}).fail(failCallback).execute({ done: childCreated })
}
it("create container document", function(done) {
function containerCreated(doc) {
container = doc
expect(doc.uid).to.exist
done()
}
nuxeo.op("Document.Create", {
automationParams : {
params : {
type : "Folder",
name : "TestPagination",
properties : "dc:title=Test Pagination \ndc:description=Simple container"
},
input : "doc:/"
}
}).fail(failCallback).execute({ done: containerCreated })
})
it("create first child", function(done) {
createChild(1, done)
})
it("create second child", function(done) {
createChild(2, done)
})
it("create third child", function(done) {
createChild(3, done)
})
it("query first page", function(done) {
function firstPageRetrieved(docs) {
expect(docs.entries).to.have.length(2)
expect(docs.pageSize).to.equal(2)
expect(docs.pageCount).to.equal(2)
expect(docs.totalSize).to.equal(3)
done()
}
nuxeo.op("Document.PageProvider").params({
query: "select * from Document where ecm:parentId = ?",
pageSize: 2,
page: 0,
queryParams: container.uid
})
.fail(failCallback).done(firstPageRetrieved)
.execute()
})
it("query second page", function(done) {
function secondPageRetrieved(docs) {
expect(docs.entries).to.have.length(1)
expect(docs.pageSize).to.equal(2)
expect(docs.pageCount).to.equal(2)
expect(docs.totalSize).to.equal(3)
done()
}
nuxeo.op("Document.PageProvider").params({
query: "select * from Document where ecm:parentId = ?",
pageSize: 2,
page: 1,
queryParams: container.uid
})
.fail(failCallback).done(secondPageRetrieved)
.execute()
})
})
describe("blob upload", function() {
var container
it("create container document", function(done) {
function containerCreated(doc) {
container = doc
expect(doc.uid).to.exist
done()
}
nuxeo.op("Document.Create", {
automationParams : {
params : {
type : "Folder",
name : "TestBlobs",
properties : "dc:title=Test Blobs \ndc:description=Simple container"
},
input : "doc:/"
}
}).fail(failCallback).execute({ done: containerCreated })
})
it("create text blob", function(done) {
function noteCreated(doc) {
expect(doc.type).to.equal("Note")
expect(doc.title).to.equal("testMe.text")
done()
};
var blob = new Blob([ "some content in plain text" ], {
"type" : "text/plain"
});
nuxeo.op("FileManager.Import").context({ currentDocument: container.path })
.input(blob).fail(failCallback).done(noteCreated).execute({
filename: "testMe.text"
})
})
it("create binary blob", function(done) {
function fileCreated(doc) {
expect(doc.type).to.equal("File")
expect(doc.title).to.equal("testBin.bin")
done()
};
var blob = new Blob([ "some fake bin content" ], {
"type" : "application/something"
});
nuxeo.op("FileManager.Import").context({ currentDocument: container.path })
.input(blob).fail(failCallback).done(fileCreated)
.execute({
filename: "testBin.bin"
})
})
it("get children", function(done) {
function childrenRetrieved(docs) {
expect(docs.entries).to.have.length(2)
done()
};
nuxeo.op("Document.GetChildren").input("doc:" + container.path)
.fail(failCallback).done(childrenRetrieved).execute()
})
})
describe("batch upload", function() {
var container,
importOp
it("create container document", function(done) {
function containerCreated(doc) {
container = doc
expect(doc.uid).to.exist
done()
}
nuxeo.op("Document.Create", {
automationParams : {
params : {
type : "Folder",
name : "TestBlobs",
properties : "dc:title=Test Blobs Batch \ndc:description=Simple container"
},
input : "doc:/"
}
}).fail(failCallback).execute({ done: containerCreated })
})
it("upload text blob", function(done) {
function blobUploaded(fileIndex, fileObj) {
expect(fileIndex).to.equal(0)
done()
}
var blob = new Blob([ "some content in plain text" ], {
"type" : "text/plain"
});
blob.name = "testMe.text"
importOp = nuxeo.op("FileManager.Import").context({ currentDocument: container.path })
.input(blob).fail(failCallback)
importOp.uploader().uploadFile(blob, blobUploaded)
})
it("upload binary blob", function(done) {
function blobUploaded(fileIndex, fileObj) {
expect(fileIndex).to.equal(1)
done()
}
var blob = new Blob([ "some fake bin content" ], {
"type" : "text/something"
});
blob.name = "testBin.bin"
importOp.uploader().uploadFile(blob, blobUploaded)
})
it("import", function(done) {
function documentsCreated(docs) {
expect(docs.entries).to.have.length(2)
done()
}
var blob = new Blob([ "some fake bin content" ], {
"type" : "text/something"
});
blob.name = "testBin.bin"
importOp.uploader().fail(failCallback)
.execute({ done: documentsCreated })
})
it("get children", function(done) {
function childrenRetrieved(docs) {
expect(docs.entries).to.have.length(2)
done()
};
nuxeo.op("Document.GetChildren").input("doc:" + container.path)
.fail(failCallback).done(childrenRetrieved).execute()
})
})
describe("REST tests", function() {
var doc
it("fetch domain document", function(done) {
function checkDocFetcher(data) {
doc = data;
expect(doc.uid).to.exist;
done();
}
nuxeo.doc("/default-domain").fetch({done : checkDocFetcher , fail : failCallback});
})
it("update fetched document", function(done) {
function checkDocUpdated(data) {
console.log("checking update result");
doc = data;
expect(doc.uid).to.exist;
expect(doc.properties['dc:source']).to.equal(newSourceValue);
done();
}
var newSourceValue = 'automaton-test-' + (new Date()).getTime();
doc.update({'dc:source':newSourceValue});
expect(doc.getChangeSet,"getChangeSet method should have been added to document object").to.exist;
expect(doc.getChangeSet(), "getChangeSet method should return a minimal doc").to.exist;
expect(doc.getChangeSet().properties, "getChangeSet method should return a doc with non empty properties").to.exist;
expect(doc.getChangeSet().properties['dc:source'], "getChangeSet should contains an entry for dc:source").to.exist;
expect(doc.save, "save method should have been added to document object").to.exist;
console.log("saving");
doc.save({done : checkDocUpdated , fail : failCallback});
})
})
})
function batchBlobUpdateTestSuite() {
var root = {};
var child = {};
var failedCB = function(xhr, status, msg) {
alert(msg)
};
var createOp;
var suite = new AutomationTestSuite(
"use batch manager in Blob update operation",
[
// **********************
// create root
function testCreateRoot() {
function createdOK(doc, status, xhr) {
root = doc;
AssertThat(doc.uid, "created container with uid : "
+ doc.uid);
suite.nextTest();
}
;
var createOp = jQuery()
.automation(
"Document.Create",
{
automationParams : {
params : {
type : "Folder",
name : "TestBlobsUpdate",
properties : "dc:title=Test Blobs update via Batch \ndc:description=Simple container"
},
input : "doc:/"
}
});
createOp.execute(createdOK, failedCB);
},
// **********************
// create first child
function testCreateChild1() {
function createdOK(doc, status, xhr) {
AssertThat((doc.uid != null)
&& (doc.path.indexOf(root.path) == 0),
"created file with uid : " + doc.uid
+ " and path " + doc.path);
child = doc;
suite.nextTest();
}
;
createOp = jQuery().automation("Document.Create", {
automationParams : {
params : {
type : "File",
name : "TestFile1"
},
input : "doc:" + root.path
}
});
createOp.execute(createdOK, failedCB);
},
// **********************
// upload Blob
function testUploadBlobText() {
function uploadedOK(fileIndex, fileObj) {
AssertThat(fileIndex == 0, "uploaded file1");
suite.nextTest();
}
;
createOp = jQuery().automation("FileManager.Import", {
automationParams : {
params : {},
context : {
currentDocument : root.path
}
}
});
var fakeFile = {
name : "testMe.txt",
type : "text/plain",
size : "26",
fakeData : 'some content in plain text'
};
createOp.uploader().uploadFile(fakeFile, uploadedOK);
},
// **********************
// update child with Blob from batch
function testUpdateChild() {
function updatedOK(doc, status, xhr) {
AssertThat(
doc.properties['dc:description'] == "New Description",
"description updated ok "
+ doc.properties['dc:description']);
AssertThat(
doc.properties['file:content']['name'] == "testMe.txt",
"file uploaded ok");
}
;
var properties = {};
properties['dc:description'] = 'New Description';
properties['file:content'] = {
'upload-batch' : createOp.uploader().batchId,
'upload-fileId' : '0',
'type' : 'blob'
};
var updateOp = jQuery().automation("Document.Update", {
documentSchemas : "common,dublincore,file",
automationParams : {
params : {
save : "true",
//properties : JSON.stringify(properties)
properties : properties
},
input : "doc:" + child. uid
}
});
updateOp.execute(updatedOK, failedCB);
} ]);
return suite;
}