-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathbasePath-test.js
More file actions
89 lines (82 loc) · 3.55 KB
/
basePath-test.js
File metadata and controls
89 lines (82 loc) · 3.55 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
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
const testconfig = require('../etc/test-config.js');
const marklogic = require('../');
let assert = require('assert');
let writeObject = {
uri: '/write/string1.json',
contentType: 'application/json',
content: '{"key1":"value 1"}'
};
describe('basePath tests', function() {
it('basePath without slash(s)', function(done){
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath'));
})
.catch(err=>
{
assert(err.toString().includes('path: invalid/v1/documents'));
done();
});
});
it('basePath with slash', function(done){
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with a leading slash'));
})
.catch(err=>
{
assert(err.toString().includes('path: /invalid/v1/documents'));
done();
});
});
it('basePath with trailing slash', function(done){
testconfig.restWriterConnectionWithBasePath.basePath = 'invalid/';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with a trailing slash'));
})
.catch(err=>
{
assert(err.toString().includes('path: invalid/v1/documents'));
done();
});
});
it('basePath with starting and trailing slashes', function(done){
testconfig.restWriterConnectionWithBasePath.basePath = '/invalid/';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with starting and trailing slashes'));
})
.catch(err=>
{
assert(err.toString().includes('path: /invalid/v1/documents'));
done();
});
});
it('basePath with multiple starting and trailing slashes', function(done){
testconfig.restWriterConnectionWithBasePath.basePath = '//invalid//';
const dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnectionWithBasePath);
dbWriter.documents.write(writeObject)
.result(function(response){
done(new Error('Expecting an error to be thrown due to invalid basePath with multiple starting and trailing slashes'));
})
.catch(err=>
{
try{
assert(err.toString().includes('path: //invalid//v1/documents'));
done();
} catch(err){
done(err);
}
});
});
});