-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-ds-dynamic.js
More file actions
executable file
·183 lines (164 loc) · 7.16 KB
/
Copy pathnodejs-ds-dynamic.js
File metadata and controls
executable file
·183 lines (164 loc) · 7.16 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
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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
const fs = require('fs');
const util = require('util')
const path = require("path");
const expect = require('chai').expect;
const should = require('should');
var testconfig = require('../etc/test-config-qa.js');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(testconfig.restEvaluatorConnection);
var dbManageAdmin = marklogic.createDatabaseClient(testconfig.manageAdminConnection);
var sess = null;
// Run tests from test-complete-proxy folder.
describe('Dynamic data services tests', function(){
it('TestE2EItemPrice-param-posNum', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
serviceDeclaration.endpointExtension = '.sjs';
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
const params = {itemId:10};
serviceCaller.call(endpointDeclaration.functionName, params)
.then(output => {
//console.debug("Return value is : %s", output);
expect(output).to.eql('String10')
done();
})
.catch(err => {
console.log('Error from TestE2EItemPrice-param-posNum ' + err);
done(err);
});
});
it('TestE2EItemPrice-param-zero', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
serviceDeclaration.endpointExtension = '.sjs';
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
const params = {itemId:0};
serviceCaller.call(endpointDeclaration.functionName, params)
.then(output => {
//console.debug("Return value is : %s", output);
expect(output).to.eql('1')
done();
})
.catch(err => {
console.log('Error from TestE2EItemPrice-param-zero ' + err);
done(err);
});
});
it('TestE2EItemPrice-param-negNum', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
serviceDeclaration.endpointExtension = '.sjs';
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
const params = {itemId:-2};
serviceCaller.call(endpointDeclaration.functionName, params)
.then(output => {
//console.debug("Return value is : %s", output);
expect(output).to.eql('-1')
done();
})
.catch(err => {
console.log('Error from TestE2EItemPrice-param-negNum ' + err);
done(err);
});
});
it('TestE2EIntegerParamReturnDoubleErrorCond-param-floats', function(done) {
const serviceDeclaration = JSON.parse(
fs.readFileSync('./ml-modules/TestRequiredParam/service.json',
{encoding: 'utf8'})
);
serviceDeclaration.endpointExtension = '.sjs';
const endpointDeclaration = JSON.parse(
fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EIntegerParamReturnDoubleErrorCond.api',
{encoding: 'utf8'})
);
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
const params = {items:10,
price:10.06
};
serviceCaller.call(endpointDeclaration.functionName, params)
.then(output => {
//console.debug("Return value is : %s", output);
var tmp = unescape(output);
expect(tmp).to.eql('10110.3')
done();
})
.catch(err => {
console.log('Error from TestE2EIntegerParamReturnDoubleErrorCond-param-floats ' + err);
done(err);
});
});
it('TestE2EIntegerParamReturnDoubleErrorCond-param-null', function(done) {
const serviceDeclaration = JSON.parse(
fs.readFileSync('./ml-modules/TestRequiredParam/service.json',
{encoding: 'utf8'})
);
serviceDeclaration.endpointExtension = '.sjs';
const endpointDeclaration = JSON.parse(
fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EIntegerParamReturnDoubleErrorCond.api',
{encoding: 'utf8'})
);
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
const params = {items:null,
price:10.06
};
serviceCaller.call(endpointDeclaration.functionName, params)
.then(output => {
//console.debug("Return value is : %s", output);
var tmp = unescape(output);
expect(tmp).to.eql('10000')
done();
})
.catch(err => {
console.log('Error from TestE2EIntegerParamReturnDoubleErrorCond-param-floats ' + err);
done(err);
});
});
it('TestE2EItemPriceWithErrorMap-errorMap', function(done) {
const serviceDeclaration = JSON.parse(
fs.readFileSync('./ml-modules/TestRequiredParam/service.json',
{encoding: 'utf8'})
);
serviceDeclaration.endpointExtension = '.sjs';
const endpointDeclaration = JSON.parse(
fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPriceWithErrorMap.api',
{encoding: 'utf8'})
);
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
const params = {itemId:1000};
serviceCaller.call(endpointDeclaration.functionName, params)
.then(res => {
//console.log('Error from TestE2EItemPriceWithErrorMap-errorMap ' + JSON.stringify(res));
})
.catch(err => {
const errMapResp = err.body.errorResponse;
//console.log(JSON.stringify(err));
expect(errMapResp.message).to.contain('Test for message status code 539');
expect(errMapResp.messageDetail.messageTitle).to.contain('MLQA-ERROR-2');
expect(errMapResp.statusCode).to.eql(539);
expect(errMapResp.status).to.eql("QA Message For 539");
expect(errMapResp.messageCode).to.eql('MLQA-ERROR-2');
});
done();
});
it('TestE2EItemPrice-endpoint-caller', function(done) {
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+endpointDeclaration.functionName+'.sjs';
const endptCaller = db.endpointCaller(endpointDeclaration);
const params = {itemId:10};
endptCaller.call(params)
.then(output => {
//console.debug("Return value is : %s", output);
expect(output).to.eql('String10')
done();
})
.catch(err => {
console.log('Error from TestE2EItemPrice-endpoint-caller ' + err);
done(err);
});
});
});