-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathoptic-update-execute.js
More file actions
125 lines (116 loc) · 4.22 KB
/
optic-update-execute.js
File metadata and controls
125 lines (116 loc) · 4.22 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
'use strict';
const should = require('should');
const testconfig = require('../etc/test-config.js');
const marklogic = require('../');
const db = marklogic.createDatabaseClient(testconfig.restWriterConnection);
const Stream = require('stream');
const testlib = require("../etc/test-lib");
const op = marklogic.planBuilder;
let removeStream = new Stream.PassThrough({objectMode: true});
let uris = [];
let serverConfiguration = {};
describe('optic-update execute tests', function() {
this.timeout(30000);
before(function (done) {
try {
testlib.findServerConfiguration(serverConfiguration);
setTimeout(()=>{done();}, 3000);
} catch(error){
done(error);
}
});
describe('execute ', function () {
before(function(done){
if(serverConfiguration.serverVersion < 11){
this.skip();
}
done();
});
beforeEach(function (done) {
let readable = new Stream.Readable({objectMode: true});
removeStream = new Stream.PassThrough({objectMode: true});
uris = [];
for (let i = 0; i < 100; i++) {
const temp = {
uri: '/test/fromDocUris/' + i + '.json',
contentType: 'application/json',
content: {['key']: 'initialValue'}
};
readable.push(temp);
removeStream.push(temp.uri);
uris.push(temp.uri);
}
readable.push(null);
removeStream.push(null);
db.documents.writeAll(readable, {
onCompletion: ((summary) => {
done();
})
});
});
afterEach(function (done) {
db.documents.remove(uris)
.result(function (response) {
done();
})
.catch(err => done(err))
.catch(done);
});
it('test with fromDocUris -> remove', function (done) {
const options = serverConfiguration.serverVersion <= 11.1? null : {'update' : true};
try {
db.rows.execute(op.fromDocUris(op.cts.directoryQuery('/test/fromDocUris/')).remove(), options);
setTimeout(function () {
verifyDocs(done);
}, 3000);
} catch (e) {
done(e);
}
});
it('test with no optic plan', function (done) {
try {
db.rows.execute();
} catch (e) {
e.toString().includes('Error: built plan required');
done();
}
});
it('test with fromDocUris and trace option -> remove', function (done) {
const options = serverConfiguration.serverVersion <= 11.1? {trace: "fromDocUris"} : {trace: "fromDocUris",'update' : true};
try {
db.rows.execute(op.fromDocUris(op.cts.directoryQuery('/test/fromDocUris/')).remove(), options);
setTimeout(function () {
verifyDocs(done);
}, 3000);
} catch (e) {
done(e);
}
});
it('test with fromDocUris using query function -> remove', function (done) {
const options = serverConfiguration.serverVersion <= 11.1? null : {'update' : true};
try {
db.rows.query(op.fromDocUris(op.cts.directoryQuery('/test/fromDocUris/')).remove(), options)
.then(res => {
const arrayOfUris = res.rows.map(item => item.uri.value).sort();
arrayOfUris.should.deepEqual(uris.sort());
done();
}).catch(e => {
done(e);
});
} catch (e) {
done(e);
}
});
});
});
function verifyDocs(done){
db.documents.read(uris)
.result(function (documents) {
documents.length.should.equal(0);
})
.then(()=> done())
.catch(err=> done(err));
}