Skip to content

Commit febd145

Browse files
author
U-MARKLOGIC\ageorge
committed
#567 - New tests
1 parent 0ca3548 commit febd145

File tree

1 file changed

+195
-0
lines changed

1 file changed

+195
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*
2+
* Copyright 2014-2020 MarkLogic Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const fs = require('fs');
18+
const util = require('util')
19+
const path = require("path");
20+
21+
const expect = require('chai').expect;
22+
const should = require('should');
23+
24+
var testconfig = require('../etc/test-config-qa.js');
25+
26+
var marklogic = require('../');
27+
var q = marklogic.queryBuilder;
28+
var db = marklogic.createDatabaseClient(testconfig.restEvaluatorConnection);
29+
var dbManageAdmin = marklogic.createDatabaseClient(testconfig.manageAdminConnection);
30+
var sess = null;
31+
// Run tests from test-complete-proxy folder.
32+
describe('Dynamic data services tests', function(){
33+
it('TestE2EItemPrice-param-posNum', function(done) {
34+
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
35+
serviceDeclaration.endpointExtension = '.sjs';
36+
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
37+
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
38+
const params = {itemId:10};
39+
40+
serviceCaller.call(endpointDeclaration.functionName, params)
41+
.then(output => {
42+
//console.debug("Return value is : %s", output);
43+
expect(output).to.eql('String10')
44+
done();
45+
})
46+
.catch(err => {
47+
console.log('Error from TestE2EItemPrice-param-posNum ' + err);
48+
done(err);
49+
});
50+
});
51+
52+
it('TestE2EItemPrice-param-zero', function(done) {
53+
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
54+
serviceDeclaration.endpointExtension = '.sjs';
55+
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
56+
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
57+
const params = {itemId:0};
58+
59+
serviceCaller.call(endpointDeclaration.functionName, params)
60+
.then(output => {
61+
//console.debug("Return value is : %s", output);
62+
expect(output).to.eql('1')
63+
done();
64+
})
65+
.catch(err => {
66+
console.log('Error from TestE2EItemPrice-param-zero ' + err);
67+
done(err);
68+
});
69+
});
70+
71+
it('TestE2EItemPrice-param-negNum', function(done) {
72+
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
73+
serviceDeclaration.endpointExtension = '.sjs';
74+
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
75+
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
76+
const params = {itemId:-2};
77+
78+
serviceCaller.call(endpointDeclaration.functionName, params)
79+
.then(output => {
80+
//console.debug("Return value is : %s", output);
81+
expect(output).to.eql('-1')
82+
done();
83+
})
84+
.catch(err => {
85+
console.log('Error from TestE2EItemPrice-param-negNum ' + err);
86+
done(err);
87+
});
88+
});
89+
90+
it('TestE2EIntegerParamReturnDoubleErrorCond-param-floats', function(done) {
91+
const serviceDeclaration = JSON.parse(
92+
fs.readFileSync('./ml-modules/TestRequiredParam/service.json',
93+
{encoding: 'utf8'})
94+
);
95+
serviceDeclaration.endpointExtension = '.sjs';
96+
const endpointDeclaration = JSON.parse(
97+
fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EIntegerParamReturnDoubleErrorCond.api',
98+
{encoding: 'utf8'})
99+
);
100+
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
101+
const params = {items:10,
102+
price:10.06
103+
};
104+
105+
serviceCaller.call(endpointDeclaration.functionName, params)
106+
.then(output => {
107+
//console.debug("Return value is : %s", output);
108+
var tmp = unescape(output);
109+
expect(tmp).to.eql('10110.3')
110+
done();
111+
})
112+
.catch(err => {
113+
console.log('Error from TestE2EIntegerParamReturnDoubleErrorCond-param-floats ' + err);
114+
done(err);
115+
});
116+
});
117+
118+
it('TestE2EIntegerParamReturnDoubleErrorCond-param-null', function(done) {
119+
const serviceDeclaration = JSON.parse(
120+
fs.readFileSync('./ml-modules/TestRequiredParam/service.json',
121+
{encoding: 'utf8'})
122+
);
123+
serviceDeclaration.endpointExtension = '.sjs';
124+
const endpointDeclaration = JSON.parse(
125+
fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EIntegerParamReturnDoubleErrorCond.api',
126+
{encoding: 'utf8'})
127+
);
128+
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
129+
const params = {items:null,
130+
price:10.06
131+
};
132+
133+
serviceCaller.call(endpointDeclaration.functionName, params)
134+
.then(output => {
135+
//console.debug("Return value is : %s", output);
136+
var tmp = unescape(output);
137+
expect(tmp).to.eql('10000')
138+
done();
139+
})
140+
.catch(err => {
141+
console.log('Error from TestE2EIntegerParamReturnDoubleErrorCond-param-floats ' + err);
142+
done(err);
143+
});
144+
});
145+
146+
it('TestE2EItemPriceWithErrorMap-errorMap', function(done) {
147+
const serviceDeclaration = JSON.parse(
148+
fs.readFileSync('./ml-modules/TestRequiredParam/service.json',
149+
{encoding: 'utf8'})
150+
);
151+
serviceDeclaration.endpointExtension = '.sjs';
152+
const endpointDeclaration = JSON.parse(
153+
fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPriceWithErrorMap.api',
154+
{encoding: 'utf8'})
155+
);
156+
const serviceCaller = db.serviceCaller(serviceDeclaration, [endpointDeclaration]);
157+
const params = {itemId:1000};
158+
159+
serviceCaller.call(endpointDeclaration.functionName, params)
160+
.then(res => {
161+
//console.log('Error from TestE2EItemPriceWithErrorMap-errorMap ' + JSON.stringify(res));
162+
})
163+
.catch(err => {
164+
const errMapResp = err.body.errorResponse;
165+
//console.log(JSON.stringify(err));
166+
expect(errMapResp.message).to.contain('Test for message status code 539');
167+
expect(errMapResp.messageDetail.messageTitle).to.contain('MLQA-ERROR-2');
168+
expect(errMapResp.statusCode).to.eql(539);
169+
expect(errMapResp.status).to.eql("QA Message For 539");
170+
expect(errMapResp.messageCode).to.eql('MLQA-ERROR-2');
171+
172+
});
173+
done();
174+
});
175+
176+
it('TestE2EItemPrice-endpoint-caller', function(done) {
177+
const serviceDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/service.json', {encoding: 'utf8'}));
178+
const endpointDeclaration = JSON.parse(fs.readFileSync('./ml-modules/TestRequiredParam/TestE2EItemPrice.api', {encoding: 'utf8'}));
179+
endpointDeclaration.endpoint = serviceDeclaration.endpointDirectory+endpointDeclaration.functionName+'.sjs';
180+
const endptCaller = db.endpointCaller(endpointDeclaration);
181+
const params = {itemId:10};
182+
183+
endptCaller.call(params)
184+
.then(output => {
185+
//console.debug("Return value is : %s", output);
186+
expect(output).to.eql('String10')
187+
done();
188+
})
189+
.catch(err => {
190+
console.log('Error from TestE2EItemPrice-endpoint-caller ' + err);
191+
done(err);
192+
});
193+
});
194+
195+
});

0 commit comments

Comments
 (0)