-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathendpoint-caller.js
More file actions
91 lines (80 loc) · 4.21 KB
/
Copy pathendpoint-caller.js
File metadata and controls
91 lines (80 loc) · 4.21 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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var marklogic = require('../');
var fs = require('fs');
var testconfig = require('../etc/test-config.js');
var expect = require('chai').expect;
var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection);
let gulpConfig = require('../gulpfile.js');
describe('Endpoint caller', function() {
before(function(done){
this.timeout(30000); // set timeout to 30 seconds, because some of the tests take a while
gulpConfig.loadProxyTests();
setTimeout(()=>{done();}, 5000);
});
it('moduleInitSjs endpoint', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/moduleInitSjs/service.json', {encoding: 'utf8'}));
const endpointDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/moduleInitSjs/initializer.api', {encoding: 'utf8'}));
endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+endpointDeclaration.functionName+'.sjs';
const endpointCaller = dbWriter.endpointCaller(endpointDeclaration);
const params = {param1:true, param2: '1.2', param3: [1.2, 3.4], param4:[5, 6] };
endpointCaller.call(params)
.then(output => {
expect(output).to.eql(true);
done();
})
.catch(err => {
done(err);
});
});
it('moduleInitXqy endpoint', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/moduleInitXqy/service.json', {encoding: 'utf8'}));
const endpointDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/moduleInitXqy/initializer.api', {encoding: 'utf8'}));
endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+endpointDeclaration.functionName+'.xqy';
const endpointCaller = dbWriter.endpointCaller(endpointDeclaration);
const params = {param1:true, param2: '1.2', param3: [1.2, 3.4], param4:[5, 6] };
endpointCaller.call(params)
.then(output => {
expect(output).to.eql(true);
done();
})
.catch(err => {
done(err);
});
});
it('postOfMultipartForDocumentArray1 endpoint', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/postOfMultipartForDocument/service.json',
{encoding: 'utf8'}));
const endpointDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/postOfMultipartForDocument/postOfMultipartForDocumentArray1.api',
{encoding: 'utf8'}));
endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+endpointDeclaration.functionName+'.sjs';
const endpointCaller = dbWriter.endpointCaller(endpointDeclaration);
const params = {param1:[{"root":{"child":"text1"}}, {"root":{"child":"text2"}}]};
endpointCaller.call(params)
.then(output => {
expect(output).to.eql(["text1", 1]);
done();
})
.catch(err => {
done(err);
});
});
it('postOfUrlencodedForDocumentArray1 endpoint', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/postOfUrlencodedForDocument/service.json',
{encoding: 'utf8'}));
const endpointDeclaration = JSON.parse(fs.readFileSync('./test-basic-proxy/ml-modules/generated/postOfUrlencodedForDocument/postOfUrlencodedForDocumentArray1.api',
{encoding: 'utf8'}));
endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+endpointDeclaration.functionName+'.mjs';
const endpointCaller = dbWriter.endpointCaller(endpointDeclaration);
const params = {param1:[1.2, 3.4]};
endpointCaller.call(params)
.then(output => {
expect(output).to.eql(["text1", 1]);
done();
})
.catch(err => {
done(err);
});
});
});