-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-ds-required-params.js
More file actions
executable file
·191 lines (169 loc) · 5.88 KB
/
Copy pathnodejs-ds-required-params.js
File metadata and controls
executable file
·191 lines (169 loc) · 5.88 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
184
185
186
187
188
189
190
191
/*
* 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 expect = require('chai').expect;
const should = require('should');
const TestRequiredParam = require("./TestRequiredParam.js");
const TestE2EMultiStringsInStringsOut = require("./TestE2EMultiStringsInStringsOut.js");
const TestE2ESession = require("./TestE2ESession.js");
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;
describe('Required-Params-Test', function(){
it('10 to API call', function(done){
TestRequiredParam.on(db).TestE2EItemPrice(10).then(res => {
//console.debug("Return value is : %s", res);
expect(res).to.eql('String10')
done();
})
.catch(err => {
expect.fail(err.toString());
done();
});
});
it('0 to API call', function(done){
TestRequiredParam.on(db).TestE2EItemPrice(0).then(res => {
//console.debug("Return value is : %s", res);
expect(res).to.eql('1')
done();
})
.catch(err => {
expect.fail(err.toString());
done();
});
});
it('-2 to API call', function(done){
TestRequiredParam.on(db).TestE2EItemPrice(-2).then(res => {
//console.debug("Return value is : %s", res);
expect(res).to.eql('-1')
done();
})
.catch(err => {
expect.fail(err.toString());
done();
});
});
it('12 to API call', function(done){
TestRequiredParam.on(db).TestE2EItemPrice(12).then(res => {
//console.debug("Return value is : %s", res);
expect(res).to.eql('13')
done();
})
.catch(err => {
expect.fail(err.toString());
done();
});
});
// Send in float.
it('float to API call', function(done){
TestRequiredParam.on(db).TestE2EIntegerParamReturnDoubleErrorCond(10, 10.06).then(res => {
var tmp = unescape(res);
//console.debug("Return value fo 10, 10 is : %d", tmp);
expect(tmp).to.eql('10110.3')
done();
})
.catch(err => {
expect.fail(err.toString());
done();
});
});
it('Sessions test Create', function(done){
// Should have run Setup docs for services calls in nodejs-ds-setup-docs.js file.
var uri = "session1.json";
var updatedStr;
var session;
session = TestE2ESession.on(db).createSession();
TestE2ESession.on(db).StoreInSession(session, uri, "Updated from original").then( res => {
TestE2ESession.on(db).RetrieveFromSession(session, uri).then( resOut => {
});
});
// Read outside of session
db.documents.read(uri).result( function(documents) {
documents.forEach(function(document) {
updatedStr = JSON.stringify(document);
//console.log(updatedStr);
expect(updatedStr).to.include('Updated from original');
});
}, function(error) {
console.log(JSON.stringify(error, null, 2));
});
done();
});
it('Verify with wrong Session', function(done){
var sess;
var docCont;
var seconds = 5;
var kVal = "content";
try {
sess1 = TestE2ESession.on(db).createSession();
sess2 = TestE2ESession.on(db).createSession();
TestE2ESession.on(db).EnableSession(sess1, "/session1.txt", "Checking first sessions");
TestE2ESession.on(db).CheckOnSession(sess2).then( res => {
// Nothing to do here.
done();
})
.catch(
err => {
//console.debug("Return value for second session:", tmp2);
expect(err.message).to.contain('call to /qa/test/TestE2ESession/CheckOnSession.sjs: cannot process response with 400 status');
const errMapResp = err.body.errorResponse;
expect(errMapResp.statusCode).to.eql(400);
expect(errMapResp.status).to.eql("Bad Request");
expect(errMapResp.messageCode).to.eql('XDMP-ARGTYPE');
expect(errMapResp.message).to.contain('XDMP-ARGTYPE: cts.doc(null) -- arg1 is not of type String');
done();
});
}
catch(err) {
console.debug(err);
done();
}
});
// Error condtions verifications.
it('Error condtion 1 to API call', function(done){
TestRequiredParam.on(db).TestE2EIntegerParamReturnDoubleErrorCond(null, 12).then(res => {
var tmp = unescape(res);
//console.debug("Return value for null, 12 is : %d", tmp);
expect(tmp).to.eql('10000')
done();
})
.catch(err => {
expect.fail(err.toString());
done();
});
});
it('Error condtion 2 to API call', function(done){
TestRequiredParam.on(db).TestE2EIntegerParamReturnDoubleErrorCond(12, null).then(res => {
var tmp = unescape(res);
//console.debug("Return value for 12, null is : %d", tmp);
expect(tmp).to.eql('20000')
done();
})
.catch(err => {
expect.fail(err.toString());
done();
});
});
it('Required param not sent to API call', function(done){
expect(() => TestRequiredParam.on(db).TestRequiredParam()).to.throw('null value not allowed for parameter');
done();
});
it('Unauthorized user to API call', function(done){
TestRequiredParam.on(dbManageAdmin).TestE2EIntegerParamReturnDoubleErrorCond(12, null).then(res => {
var tmp = unescape(res);
//console.debug("Return value for 12, null is : %d", tmp);
done();
})
.catch(err => {
var msg = err.toString();
expect(msg).to.include("cannot process response with 404 status");
expect(msg).to.include(" call to /qa/test/TestRequiredParam/TestE2EIntegerParamReturnDoubleErrorCond.sjs");
done();
});
});
});