-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathresources-exec.js
More file actions
179 lines (174 loc) · 7.5 KB
/
resources-exec.js
File metadata and controls
179 lines (174 loc) · 7.5 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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
var fs = require('fs');
var valcheck = require('core-util-is');
var testconfig = require('../etc/test-config.js');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(testconfig.restWriterConnection);
var restAdminDB = marklogic.createDatabaseClient(testconfig.restAdminConnection);
describe('when executing resource services', function(){
describe('using XQuery', function() {
var xqyServiceName = 'wrapperService';
var xqyServicePath = './test-basic/data/wrapperService.xqy';
before(function(done){
this.timeout(3000);
restAdminDB.config.resources.write(xqyServiceName, 'xquery', fs.createReadStream(xqyServicePath))
.result(function(response){
done();
})
.catch(done);
});
it('should get one document', function(done){
db.resources.get({name:xqyServiceName, params:{value:'foo'}})
.result(function(response){
valcheck.isArray(response).should.equal(true);
response.length.should.equal(1);
response[0].should.have.property('content');
response[0].content.should.have.property('readDoc');
response[0].content.readDoc.should.have.property('param');
response[0].content.readDoc.param.should.equal('foo');
done();
})
.catch(done);
});
it('should get two documents', function(done){
db.resources.get({
name:xqyServiceName, params:{value:'foo', multipart:'true'}
})
.result(function(response){
valcheck.isArray(response).should.equal(true);
response.length.should.equal(2);
response[0].should.have.property('content');
response[0].content.should.have.property('readDoc');
response[0].content.readDoc.should.have.property('param');
response[0].content.readDoc.param.should.equal('foo');
response[1].should.have.property('content');
response[1].content.should.have.property('readMultiDoc');
response[1].content.readMultiDoc.should.have.property('multiParam');
response[1].content.readMultiDoc.multiParam.should.equal('foo');
done();
})
.catch(done);
});
it('should put one typed document', function(done){
db.resources.put({
name:xqyServiceName, params:{value:'foo'}, documents:[
{contentType:'application/json', content:{one:'typed document'}}
]})
.result(function(response){
response.should.have.property('wroteDoc');
response.wroteDoc.should.have.property('param');
response.wroteDoc.param.should.equal('foo');
response.wroteDoc.should.have.property('inputDoc');
response.wroteDoc.inputDoc.should.have.property('one');
response.wroteDoc.inputDoc.one.should.equal('typed document');
done();
})
.catch(done);
});
it('should put one untyped document', function(done){
db.resources.put({
name:xqyServiceName, params:{value:'foo'}, documents:[
{one:'untyped document'}
]})
.result(function(response){
response.should.have.property('wroteDoc');
response.wroteDoc.should.have.property('param');
response.wroteDoc.param.should.equal('foo');
response.wroteDoc.should.have.property('inputDoc');
response.wroteDoc.inputDoc.should.have.property('one');
response.wroteDoc.inputDoc.one.should.equal('untyped document');
done();
})
.catch(done);
});
it('should put two typed documents', function(done){
db.resources.put({
name:xqyServiceName, params:{value:'foo'}, documents:[
{contentType:'application/json', content:{one:'typed document'}},
{contentType:'application/json', content:{two:'typed document'}}
]})
.result(function(response){
response.should.have.property('wroteDoc');
response.wroteDoc.should.have.property('param');
response.wroteDoc.param.should.equal('foo');
response.wroteDoc.should.have.property('inputDoc');
response.wroteDoc.inputDoc.should.have.property('one');
response.wroteDoc.inputDoc.one.should.equal('typed document');
response.wroteDoc.should.have.property('multiInputDoc');
response.wroteDoc.multiInputDoc.should.have.property('two');
response.wroteDoc.multiInputDoc.two.should.equal('typed document');
done();
})
.catch(done);
});
it('should post two typed documents', function(done){
db.resources.post({
name:xqyServiceName, params:{value:'foo', multipart:'true'}, documents:[
{contentType:'application/json', content:{one:'typed document'}},
{contentType:'application/json', content:{two:'typed document'}}
]})
.result(function(response){
valcheck.isArray(response).should.equal(true);
response.length.should.equal(2);
response[0].should.have.property('content');
response[0].content.should.have.property('appliedDoc');
response[0].content.appliedDoc.should.have.property('param');
response[0].content.appliedDoc.param.should.equal('foo');
response[0].content.appliedDoc.should.have.property('inputDoc');
response[0].content.appliedDoc.inputDoc.should.have.property('one');
response[0].content.appliedDoc.inputDoc.one.should.equal('typed document');
response[0].content.appliedDoc.should.have.property('multiInputDoc');
response[0].content.appliedDoc.multiInputDoc.should.have.property('two');
response[0].content.appliedDoc.multiInputDoc.two.should.equal('typed document');
response[1].should.have.property('content');
response[1].content.should.have.property('appliedMultiDoc');
response[1].content.appliedMultiDoc.should.have.property('multiParam');
response[1].content.appliedMultiDoc.multiParam.should.equal('foo');
done();
})
.catch(done);
});
it('should remove one document', function(done){
db.resources.remove({name:xqyServiceName, params:{value:'foo'}})
.result(function(response){
response.should.have.property('deletedDoc');
response.deletedDoc.should.have.property('param');
response.deletedDoc.param.should.equal('foo');
done();
})
.catch(done);
});
// TODO: formats, multiple, single, or empty response, chunked streams, JavaScript resource services
});
describe('using JavaScript', function() {
var jsServiceName = 'versionService';
var jsServicePath = './test-basic/data/versionService.js';
before(function(done){
this.timeout(3000);
restAdminDB.config.resources.write(jsServiceName, 'javascript', fs.createReadStream(jsServicePath))
.result(function(response){
done();
})
.catch(done);
});
it('should get one document', function(done){
db.resources.get({name:jsServiceName})
.result(function(response){
valcheck.isArray(response).should.equal(true);
response.length.should.equal(1);
response[0].should.have.property('content');
response[0].content.should.have.property('architecture');
response[0].content.should.have.property('edition');
response[0].content.should.have.property('platform');
response[0].content.should.have.property('version');
done();
})
.catch(done);
});
// TODO: other services for JavaScript
});
});