-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdocuments-temporal-document.js
More file actions
118 lines (117 loc) · 4.09 KB
/
Copy pathdocuments-temporal-document.js
File metadata and controls
118 lines (117 loc) · 4.09 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
/*
* 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);
describe('temporal document', function() {
var content = {
systemStartTime: '1111-11-11T11:11:11Z',
systemEndTime: '9999-12-31T23:59:59Z',
validStartTime: '1111-11-11T11:11:11Z',
validEndTime: '9999-12-31T23:59:59Z'
};
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){
return db.documents.protect({
uri: 'tempDoc3.json',
temporalCollection: 'temporalCollection',
duration: 'PT0S'
}).result();
}).then(function(response){
return db.documents.wipe({
uri: 'tempDoc3.json',
temporalCollection: 'temporalCollection'
}).result();
}).then(function(response){
done();
}).catch(done);
});
it('should write a temporal document with a temporal URI', function(done) {
db.documents.write({
documents:{
uri: 'tempDoc1-v1.json',
temporalDocument: 'tempDoc1.json',
content: content
},
temporalCollection: 'temporalCollection'
}).result(function(response){
var documents = response.documents;
documents.should.have.property('length');
documents.length.should.equal(1);
response.should.have.property('systemTime');
return db.documents.read({
uris: documents[0].uri,
categories: 'metadata'
}).result();
}).then(function(documents){
documents.should.have.property('length');
documents.length.should.equal(1);
documents[0].should.have.property('metadataValues');
documents[0].metadataValues.should.have.property('temporalDocURI');
var tempDocURI = documents[0].metadataValues.temporalDocURI;
tempDocURI.should.equal('tempDoc1.json');
done();
}).catch(done);
});
it('should write multiple temporal documents with temporal URIs', function(done) {
db.documents.write({
documents:[{
uri: 'tempDoc2-v1.json',
temporalDocument: 'tempDoc2.json',
content: content
},{
uri: 'tempDoc3-v1.json',
temporalDocument: 'tempDoc3.json',
content: content
}],
temporalCollection: 'temporalCollection'
}).result(function(response){
var documents = response.documents;
documents.should.have.property('length');
documents.length.should.equal(2);
response.should.have.property('systemTime');
var uris = documents.map(function(document){return document.uri;});
return db.documents.read({
uris: uris,
categories: 'metadata'
}).result();
}).then(function(documents){
documents.should.have.property('length');
documents.length.should.equal(2);
documents[0].should.have.property('metadataValues');
documents[0].metadataValues.should.have.property('temporalDocURI');
var tempDocURI1 = documents[0].metadataValues.temporalDocURI;
tempDocURI1.should.equal('tempDoc2.json');
documents[1].should.have.property('metadataValues');
documents[1].metadataValues.should.have.property('temporalDocURI');
var tempDocURI2 = documents[1].metadataValues.temporalDocURI;
tempDocURI2.should.equal('tempDoc3.json');
done();
}).catch(function (error) {
console.dir(error);
done();
});
});
});