-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-documents-crud-negative.js
More file actions
162 lines (147 loc) · 5.69 KB
/
Copy pathnodejs-documents-crud-negative.js
File metadata and controls
162 lines (147 loc) · 5.69 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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
var testconfig = require('../etc/test-config-qa.js');
var valcheck = require('core-util-is');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(testconfig.restReaderConnection);
var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection);
describe('Document CRUD negative test', function () {
it('should fail to create invalid json document', function (done) {
dbWriter.documents.write({
uri: '/test/negative/invalidDoc.json',
contentType: 'application/json',
content: '{"invalid"}'
}).
result(function (response) {
response.should.equal('SHOULD HAVE FAILED');
done();
}, function (error) {
error.body.errorResponse.messageCode.should.equal('XDMP-JSONCHAR');
error.statusCode.should.equal(400);
done();
});
});
it('verify the stack property', function (done) {
dbWriter.documents.write({
uri: '/test/negative/invalidDoc.json',
contentType: 'application/json',
content: '{"invalid"}'
}).
result(function (response) {
response.should.equal('SHOULD HAVE FAILED');
done();
}, function (error) {
//console.log(JSON.stringify(error.stack, null, 2))
error.stack.should.not.be.null;
error.stack.should.containEql('Operation.makeError');
done();
});
});
it('should fail to create invalid xml document', function (done) {
dbWriter.documents.write({
uri: '/test/negative/invalidXmlDoc.xml',
contentType: 'application/xml',
content: '<a><b>foo</a>'
}).
result(function (response) {
(valcheck.isNullOrUndefined(response.documents[0].contentType)).should.equal(true);
done();
}, function (error) {
//console.log(error);
error.body.errorResponse.messageCode.should.equal('XDMP-DOCNOENDTAG');
error.statusCode.should.equal(400);
done();
});
});
it('should fail to create json document with invalid content type', function (done) {
dbWriter.documents.write({
uri: '/test/negative/invalidType.xml',
contentType: 'application/json',
content: { title: 'invalid type' }
}).
result(function (response) {
(valcheck.isNullOrUndefined(response.documents[0].contentType)).should.equal(true);
done();
}, function (error) {
//console.log(error.body);
error.body.errorResponse.messageCode.should.equal('XDMP-DOCROOTTEXT');
error.statusCode.should.equal(400);
done();
});
});
it('should fail to create document with invalid user role', function (done) {
db.documents.write({
uri: '/test/negative/invalidRole.json',
contentType: 'application/json',
content: { title: 'invalid role' }
}).
result(function (response) {
response.should.equal('SHOULD HAVE FAILED');
done();
}, function (error) {
//console.log(error.body);
error.body.errorResponse.messageCode.should.equal('SEC-PRIV');
error.statusCode.should.equal(403);
done();
});
});
it('should fail to remove all document with invalid user role', function (done) {
db.documents.removeAll({ all: true }).
result(function (response) {
response.should.equal('SHOULD HAVE FAILED');
done();
}, function (error) {
//console.log(error.body);
error.body.errorResponse.messageCode.should.equal('SEC-PRIV');
error.statusCode.should.equal(403);
done();
});
});
it('should fail to write document without uri', function (done) {
dbWriter.documents.write({
contentType: 'application/json',
content: { title: 'no uri' }
}).
result(function (response) {
response.should.equal('SHOULD HAVE FAILED');
done();
}, function (error) {
//console.log(error);
error.body.errorResponse.messageCode.should.equal('RESTAPI-INVALIDREQ');
error.statusCode.should.equal(400);
done();
});
});
it('should fail to read metadata from non-existent document', function (done) {
db.documents.read({
uris: '/doc/nonExistent.json',
categories: ['metadata']
}).
result(function (response) {
response.length.should.equal(0);
done();
}, function (error) {
//console.log(error);
done();
});
});
/*it('should fail to write with invalid content type', function(done){
dbWriter.documents.write({
uri: '/test/negative/invalidDoc',
contentType: 'foo',
content: { title: 'invalid' }
}).
result(function(response) {
response.should.equal('SHOULD HAVE FAILED');
done();
}, function(error) {
console.log(error.body);
console.log(error.body.errorResponse.messageCode);
error.statusCode.should.equal(400);
done();
});
});*/
});