-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdocuments-temporal-patch.js
More file actions
106 lines (104 loc) · 3.41 KB
/
Copy pathdocuments-temporal-patch.js
File metadata and controls
106 lines (104 loc) · 3.41 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
/*
* 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.js');
var marklogic = require('../');
var db = marklogic.createDatabaseClient(testconfig.restTemporalConnection);
var p = marklogic.patchBuilder;
describe('temporal patch', function() {
var content = {
property1: 'original',
systemStartTime: '1111-11-11T11:11:11Z',
systemEndTime: '9999-12-31T23:59:59Z',
validStartTime: '1111-11-11T11:11:11Z',
validEndTime: '9999-12-31T23:59:59Z'
};
before(function(done){
db.documents.write({
documents: {
uri: 'tempDoc1.json',
content: content
},
temporalCollection: 'temporalCollection'
}).result(function(response){
return db.documents.write({
documents:{
uri: 'tempDoc2-v1.json',
content: content,
temporalDocument: 'tempDoc2.json'
},
temporalCollection: 'temporalCollection'
}).result()
}).then(function(response){
done();
}).catch(done);
});
after(function(done){
db.documents.protect({
uri: 'tempDoc1.json',
temporalCollection: 'temporalCollection',
duration: 'PT0S'
}).result(function(response){
return db.documents.wipe({
uri: 'tempDoc1.json',
temporalCollection: 'temporalCollection'
}).result();
}).then(function(response){
return db.documents.protect({
uri: 'tempDoc2.json',
temporalCollection: 'temporalCollection',
duration: 'PT0S'
}).result();
}).then(function(response){
return db.documents.wipe({
uri: 'tempDoc2.json',
temporalCollection: 'temporalCollection'
}).result();
}).then(function(response){
done();
}).catch(done);
});
it('should patch a temporal document', function(done) {
db.documents.patch({
uri: 'tempDoc1.json',
operations: p.replace('property1', 'replacement'),
categories: ['content'],
temporalCollection: 'temporalCollection'
}).result(function(response) {
response.should.have.property('uri');
response.uri.should.equal('tempDoc1.json');
return db.documents.read(response.uri).result();
})
.then(function(response){
response.should.have.property('length');
response.length.should.equal(1);
var content = response[0].content;
content.should.have.property('property1');
content.property1.should.equal('replacement');
done();
})
.catch(done);
});
it('should patch a temporal document with temporal URI and source URI', function(done) {
db.documents.patch({
uri: 'tempDoc2-v2.json',
operations: p.replace('property1', 'replacement'),
categories: ['content'],
sourceDocument: 'tempDoc2-v1.json',
temporalDocument: 'tempDoc2.json',
temporalCollection: 'temporalCollection'
}).result(function(response) {
response.should.have.property('uri');
response.uri.should.equal('tempDoc2-v2.json');
return db.documents.read(response.uri).result();
}).then(function(response){
response.should.have.property('length');
response.length.should.equal(1);
var content = response[0].content;
content.should.have.property('property1');
content.property1.should.equal('replacement');
done();
}).catch(done);
});
});