-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (66 loc) · 2.17 KB
/
test.js
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
"use strict;"
const {spawn, exec}=require('child_process')
const util=require('util');
const pexec = util.promisify(exec);
const MongoModels = require('mongo-models');
function startUp() {
return new Promise(async (ok,ko)=>{
try{
const { stdout, stderr } = await pexec('mkdir tmp');
console.log('stdout:', stdout);
console.log('stderr:', stderr);
}
catch(err){
if(err.code!==1){
console.info(err);
ko(err);
}
//else just fall through and continue
}
const dbPipe = spawn('mongod', ['--dbpath=./tmp', '--port', '27017'])
dbPipe.stdout.on('data', function (data) {
console.log(data.toString('utf8'));
});
dbPipe.stderr.on('data', (data) => {
console.log(data.toString('utf8'));
});
dbPipe.on('close', (code) => {
console.info('Process exited with code: '+ code);
});
ok();
})
}
function shutDown(){
return new Promise(async (ok,ko)=>{
MongoModels.disconnect(); // make sure everything gets flushed before killing the db
const shutdown=spawn('mongo', ['--eval', "db.getSiblingDB('admin').shutdownServer();quit()"]);
shutdown.on('close',code=>{
if(!code) return ok();
console.error('Shutdown process exited with code', code);
ko();
})
})
}
const iotas=[
{
path: '/the-beginning',
subject: 'this is the beginning',
description: 'this is the beginning of an iota test',
webComponent: "webComponent",
participants: {moderator: "me", participan1: "them"},
component: {component: 'data-component'},
userId: 'abc123',
parentId: '123abc',
bp_info: {election_date: "2020_11_05"}
}
];
async function testIt(){
await startUp();
const Iota=require('./index')(iotas)
await Iota.connectInit();
var doc=await Iota.findOne({path: '/the-beginning'});
console.info("doc:", doc);
await shutDown();
}
process.env.MONGODB_URI="mongodb://localhost:27017/tmp?connectTimeoutMS=3000000"
testIt();