forked from marklogic/node-client-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupqa.js
More file actions
executable file
·113 lines (105 loc) · 3.23 KB
/
setupqa.js
File metadata and controls
executable file
·113 lines (105 loc) · 3.23 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
/*
* Copyright © 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
'use strict';
var util = require('../node_modules/core-util-is/lib/util.js');
var fs = require('fs');
var valcheck = require('core-util-is');
var marklogic = require('../lib/marklogic.js');
var testlib = require('./testlib.js');
var clientConnectdef = require('./connectdef.js');
var testName = clientConnectdef.name;
var planServerdef = clientConnectdef.plan;
var testLoad = require('./loaddata.js');
var testUser = require('./userconfig.js');
var db = marklogic.createDatabaseClient({
host: planServerdef.host,
port: planServerdef.port,
user: 'admin',
password: 'admin',
authType: planServerdef.authType
});
var dbMod = marklogic.createDatabaseClient({
database: testName+'Modules',
host: planServerdef.host,
port: planServerdef.port,
user: 'admin',
password: 'admin',
authType: planServerdef.authType
});
var manager = testlib.createManager(marklogic.createDatabaseClient({
host: planServerdef.host,
port: 8002,
user: 'admin',
password: 'admin',
authType: planServerdef.authType
}));
console.log('checking for '+testName);
var check = manager.get({
endpoint: '/v1/rest-apis/'+testName
}).result();
check.then(function(response) {
if (response.statusCode !== 404) {
return check;
}
console.log('creating database and REST server for '+testName);
return manager.post({
endpoint: '/v1/rest-apis',
body: {
'rest-api': {
name: testName,
group: 'Default',
database: testName,
'modules-database': testName+'Modules',
port: planServerdef.port
}
}
}).result();
})
.then(function(response){
console.log('setting up rest eval role');
return testUser.addRestEvalRole(manager).result();
})
.then(function(response){
console.log('setting up rest reader user');
return testUser.addRestReaderUser(manager).result();
})
.then(function(response){
console.log('setting up tde template on module database');
return testLoad.writeDocumentsToMod(dbMod).result();
})
.then(function(response){
console.log('setting up sample documents');
return testLoad.writeDocuments(db).result();
})
.then(function(response){
console.log('setting up graphs1');
return testLoad.writeGraphs1(db).result();
})
.then(function(response){
console.log('setting up graphs2');
return testLoad.writeGraphs2(db).result();
})
.then(function(response){
console.log('setting up database setup file');
return db.config.extlibs.write({
path:'/ext/optic/test/databaseconfig.sjs', contentType:'application/javascript', source:fs.createReadStream('./config-optic/databaseconfig.sjs')
}).result();
})
.then(function(response) {
console.log('setting up database configuration');
var dbEval = marklogic.createDatabaseClient({
host: planServerdef.host,
port: planServerdef.port,
user: 'rest-evaluator',
password: 'x',
authType: planServerdef.authType
});
return dbEval.invoke('/ext/optic/test/databaseconfig.sjs').result();
})
.then(function(response){
console.log('setup done');
})
.catch(function(error){
console.log(error);
});