-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources-fill.js
65 lines (59 loc) · 1.5 KB
/
resources-fill.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
const request = require('request');
// example: 'http://user:password@domain:port/'
const baseUrl = 'http://test:test@localhost:2200/';
const resourceTemplate = {
"title": "Test",
"author": "",
"year": "",
"description": "test",
"tags": [],
"language": "",
"publisher": "",
"linkToLicense": "",
"subject": [
"Agriculture"
],
"level": [
"Early Education"
],
"openWith": "",
"resourceFor": null,
"medium": "",
"resourceType": "",
"addedBy": "test",
"openUrl": null,
"openWhichFile": "",
"isDownloadable": "",
"sourcePlanet": "test36",
"resideOn": "test36",
"createdDate": Date.now(),
"updatedDate": Date.now()
}
const numberOfTags = 100;
const numberOfResources = 10000;
const addResource = (resources, callback) => {
request.post({ uri: baseUrl + 'resources/_bulk_docs', body: { docs: resources }, json: true }, callback);
}
const newTags = (tags) => {
if (Math.random() > 0.95) {
return tags;
}
const newTag = 'Test' + Math.ceil(Math.random() * numberOfTags);
return newTags(tags.concat([ newTag ]));
}
const prepareResource = (resourceCount) => {
const newResource = Object.assign({}, resourceTemplate);
newResource.title = 'Tag Test ' + resourceCount;
newResource.tags = newTags([]);
return newResource;
}
const addAllResources = () => {
let resources = [];
for (var i = 0; i < numberOfResources; i++) {
resources.push(prepareResource(i + 1));
}
addResource(resources, (err, res) => {
//console.log(res);
});
}
addAllResources();