-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-javascript-invoke-params.js
More file actions
103 lines (89 loc) · 3.39 KB
/
Copy pathnodejs-javascript-invoke-params.js
File metadata and controls
103 lines (89 loc) · 3.39 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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
var testconfig = require('../etc/test-config-qa.js');
var fs = require('fs');
var marklogic = require('../');
var db = marklogic.createDatabaseClient(testconfig.restReaderConnection);
var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection);
var dbEval = marklogic.createDatabaseClient(testconfig.restEvaluatorConnection);
var dbAdmin = marklogic.createDatabaseClient(testconfig.restAdminConnection);
describe('Javascript invoke test', function () {
var fsPath = __dirname + '/data/sourceParams.js';
var invokePath = '/ext/invokeTest/sourceParams.sjs';
before(function (done) {
this.timeout(10000);
dbAdmin.config.extlibs.write({
path: invokePath, contentType: 'application/javascript', source: fs.createReadStream(fsPath)
}).
result(function (response) {
done();
}, done);
});
after(function (done) {
dbAdmin.config.extlibs.remove(invokePath).
result(function (response) {
done();
}, done);
});
it('should do javascript invoke with params', function (done) {
dbEval.invoke(invokePath, { num1: 2, num2: 3 }).result(function (values) {
//console.log(values);
values[0].value.should.equal(5);
done();
}, done);
});
it('should do javascript invoke with params on stream', function (done) {
dbEval.invoke(invokePath, { num1: 2, num2: 3 }).
stream().
on('data', function (data) {
//console.log(data);
data.value.should.equal(5);
}).
on('end', function () {
done();
}, done);
});
it('should do javascript invoke with params and transaction', function (done) {
var tid = 0;
dbEval.transactions.open({ transactionName: 'invokeTransaction', timeLimit: 60 })
.result(function (response) {
tid = response.txid;
return dbEval.invoke({
path: invokePath,
variables: { num1: 2, num2: 3 },
txid: tid
}).result();
})
.then(function (response) {
//console.log(response);
response[0].value.should.equal(5);
return dbEval.transactions.commit(tid).result();
})
.then(function (response) {
//console.log(response);
done();
}, done);
});
it('should do javascript invoke with wrong params', function (done) {
dbEval.invoke(invokePath, { numa: 2, num2: 3 }).result(function (values) {
//console.log(values);
values[0].value.should.equal('NaN');
done();
}, function (error) {
console.log(error);
done();
});
});
it('should do javascript invoke with wrong numbers of params', function (done) {
dbEval.invoke(invokePath, { num1: 2, num2: 3, num3: 5 }).result(function (values) {
//console.log(values);
values[0].value.should.equal(5);
done();
}, function (error) {
console.log(error);
done();
});
});
});