-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdocColTypes-test.js
More file actions
154 lines (139 loc) · 6.1 KB
/
Copy pathdocColTypes-test.js
File metadata and controls
154 lines (139 loc) · 6.1 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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
'use strict';
const should = require('should');
const testconfig = require('../etc/test-config.js');
const marklogic = require('../');
const testlib = require("../etc/test-lib");
const db = marklogic.createDatabaseClient(testconfig.restWriterConnection);
const op = marklogic.planBuilder;
let serverConfiguration = {};
describe('optic-update docColTypes tests', function() {
this.timeout(6000);
before(function (done) {
try {
testlib.findServerConfiguration(serverConfiguration);
setTimeout(()=>{done();}, 3000);
} catch(error){
done(error);
}
});
describe('optic docColTypes test ', function () {
before(function(done){
if(serverConfiguration.serverVersion < 11){
this.skip();
}
done();
});
it('test with fromParam', function (done) {
const rows = [{uri: '/test/docColTypes/0.json'}];
const plan = op.fromParam('bindingParam', null, op.docColTypes());
const temp = {bindingParam: rows};
db.rows.query(plan, null, temp).then(res => {
const row = res.rows[0];
row.uri.value.should.equal('/test/docColTypes/0.json');
done();
}).catch(e => done(e));
});
it('test with fromParam and 1 argument', function (done) {
const rows = [{uri: '/test/docColTypes/0.json'}];
try {
const plan = op.fromParam('bindingParam', null, op.docColTypes(op.col('uri')));
const temp = {bindingParam: rows};
db.rows.query(plan, null, temp);
done(new Error("Expected an error to be thrown due to only 1 argument to fromParam"));
} catch (e) {
e.toString().includes('Error: PlanBuilder.docColTypes takes a maximum of 0 arguments but received: 1');
done();
}
});
it('test with fromParam and xml files and no metadata', function (done) {
const bindingParam = "bindingXmlFiles";
const rows = [{doc: 'doc1.xml'}, {doc: 'doc2.xml'}];
const attachments = [{"doc1.xml": "<doc>1</doc>"}, {"doc2.xml": "<doc>2</doc>"}];
const planBuilderTemplate = op.fromParam(bindingParam, null, op.docColTypes());
const bindParam = {[bindingParam]: rows, attachments: attachments};
db.rows.query(planBuilderTemplate, null, bindParam).then(res => {
try {
const rows = res.rows;
rows[0].doc.value.should.equal('doc1.xml');
rows[1].doc.value.should.equal('doc2.xml');
done();
} catch (e) {
done(e);
}
}).catch(e => {
done(e);
});
});
it('test with fromParam and xml files with metadata', function (done) {
const bindingParam = "bindingAttachments";
const rows = [{doc: 'doc.xml'}];
const attachments = [{"doc.xml": "<doc>doc1</doc>"}];
const metadata = {
"attachments": {
"docs": [
{"rowsField": bindingParam, "column": "doc"},
]
}
};
const planBuilderTemplate = op.fromParam(bindingParam, null, op.docColTypes());
const bindParam = {[bindingParam]: rows, attachments: attachments, metadata: metadata};
db.rows.query(planBuilderTemplate, null, bindParam).then(res => {
try {
const rows = res.rows;
rows[0].doc.value.should.equal('<doc>doc1</doc>');
done();
} catch (e) {
done(e);
}
}).catch(e => {
done(e);
});
});
it('test with optic fromDocDescriptors and write should throw error', function (done) {
const docsDescriptor = {
uri: '/test/docColTypes/data1.json',
doc: {"desc": "doc2"},
collections: ['fromDocDescriptors'],
permissions: [{'role-name': 'app-user', capabilities: ['read']}],
metadata: {'meta': 'value1'},
quality: 1,
};
try {
db.rows.query(op.fromDocDescriptors(docsDescriptor).write(op.docColTypes()));
done(new Error('Expecting an error to be thrown due to invalid document descriptor'));
} catch (e) {
e.toString().includes('Error: doc-cols argument at 0 of PlanModifyPlan.write() must have type PlanDocColsIdentifier');
done();
}
});
it('test with fromParam and all arguments', function (done) {
const rows = [{
uri: '/test/docColTypes/data1.json',
doc: {"desc": "doc2"},
collections: ['docColTypes'],
permissions: [{'role-name': 'app-user', capabilities: ['read']}],
metadata: {'meta': 'value1'},
quality: 1
}];
try {
const plan = op.fromParam('bindingParam', null, op.docColTypes());
const temp = {bindingParam: rows};
db.rows.query(plan, null, temp).then(res => {
const row = res.rows[0];
row.uri.value.should.equal('/test/docColTypes/data1.json');
row.doc.value.should.deepEqual({"desc": "doc2"});
row.collections.value.should.deepEqual(['docColTypes']);
row.permissions.value.should.deepEqual([{"role-name": "app-user", "capabilities": ["read"]}]);
row.metadata.value.should.deepEqual({'meta': 'value1'});
row.quality.value.should.equal(1);
done();
}).catch(e => done(e));
} catch (e) {
done(e);
}
});
});
});