Skip to content

Commit cdb8c6e

Browse files
committed
add more tests (#61)
1 parent d341b2a commit cdb8c6e

File tree

4 files changed

+157
-4
lines changed

4 files changed

+157
-4
lines changed

src/systems/classes/_OSGi-class.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"component": "_OSGi",
9393
"state": "uninstall",
9494
"action":
95-
"function uninstall(id) {\n var search = {},\n system = null,\n behaviorId = '',\n collection = '',\n componentId = '',\n length = 0,\n i = 0,\n coreComponents = ['admin', 'channel', 'db', 'logger', 'metamodel', 'runtime'];\n\n search = $db._System.find({\n '_id': id\n });\n\n if (search.length) {\n system = search[0];\n // remove behaviors\n if (system.behaviors) {\n for (behaviorId in system.behaviors) {\n $db._Behavior.remove({\n '_id': system.behaviors[behaviorId]._id\n });\n }\n }\n // remove components\n if (system.components) {\n for (collection in system.components) {\n for (componentId in system.components[collection]) {\n if (coreComponents.indexOf(componentId) === -1) {\n $db[collection].remove({\n '_id': componentId\n });\n }\n }\n }\n }\n }\n if (this.require(id) && this.require(id).state) {\n this.require(id).state('uninstalled');\n channel.$systemUninstalled(id);\n }\n}",
95+
"function uninstall(id) {\n var search = {},\n system = null,\n behaviorId = '',\n collection = '',\n componentId = '',\n length = 0,\n i = 0,\n coreComponents = ['admin', 'channel', 'db', 'logger', 'metamodel', 'runtime'];\n\n search = $db._System.find({\n '_id': id\n });\n\n if (search.length) {\n system = search[0];\n // remove behaviors\n if (system.behaviors) {\n for (behaviorId in system.behaviors) {\n $db._Behavior.remove({\n '_id': system.behaviors[behaviorId]._id\n });\n }\n }\n // remove components\n if (system.components) {\n for (collection in system.components) {\n for (componentId in system.components[collection]) {\n if (coreComponents.indexOf(componentId) === -1) {\n $db[collection].remove({\n '_id': componentId\n });\n }\n }\n }\n }\n }\n if (this.require(id) && this.require(id).state) {\n this.require(id).state('uninstalled');\n this.require('channel').$systemUninstalled(id);\n }\n}",
9696
"useCoreAPI": true,
9797
"core": true
9898
},

tasks/mocha_istanbul.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
"src": [
44
"test/module",
55
"test/runtime"
6-
]
6+
],
7+
"options": {
8+
"excludes": [
9+
"src/log.js",
10+
"src/helper.js"
11+
]
12+
}
713
},
814
"coveralls": {
915
"src": [
@@ -13,7 +19,11 @@
1319
"options": {
1420
"reporter": "spec",
1521
"coverage": true,
16-
"coverageFolder": "coverage"
22+
"coverageFolder": "coverage",
23+
"excludes": [
24+
"src/log.js",
25+
"src/helper.js"
26+
]
1727
}
1828
}
1929
}

test/runtime/component-spec.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ describe('a System Runtime component', function () {
1717
'lastName': 'property',
1818
'address': 'property',
1919
'likes': 'property',
20+
'custom': 'property',
2021
'fullName': 'method',
22+
'testMethod': 'method',
2123
'children': 'collection',
2224
'father': 'link',
2325
'moving': 'event'
@@ -50,9 +52,17 @@ describe('a System Runtime component', function () {
5052
'mandatory': false,
5153
'default': []
5254
},
55+
'custom': {
56+
'type': 'mycustomType',
57+
'readOnly': false,
58+
'mandatory': false,
59+
'default': {}
60+
},
5361
'fullName': {
5462
'result': 'string'
5563
},
64+
'testMethod': {
65+
},
5666
'father': {
5767
'type': 'Person',
5868
'readOnly': false,
@@ -73,6 +83,44 @@ describe('a System Runtime component', function () {
7383
'_inherit': ['Person']
7484
});
7585

86+
metamodel.type({
87+
"name": "mycustomType",
88+
"description": "",
89+
"type": "object",
90+
"schema": {
91+
"property1": {
92+
"type": "array",
93+
"mandatory": false,
94+
"default": []
95+
},
96+
"property2": {
97+
"type": "object",
98+
"mandatory": false,
99+
"default": {}
100+
},
101+
"property3": {
102+
"type": "any",
103+
"mandatory": false,
104+
"default": {}
105+
},
106+
"property4": {
107+
"type": "boolean",
108+
"mandatory": false,
109+
"default": false
110+
},
111+
"property5": {
112+
"type": "date",
113+
"mandatory": false,
114+
"default": ""
115+
},
116+
"property6": {
117+
"type": "json",
118+
"mandatory": false,
119+
"default": {}
120+
}
121+
}
122+
});
123+
76124
metamodel.create();
77125
});
78126

@@ -518,4 +566,27 @@ describe('a System Runtime component', function () {
518566

519567
expect(eikichi.fullName()).equal('Great Teacher Eikichi Onizuka');
520568
});
569+
570+
it('can send an error', function (done) {
571+
const Person = runtime.require('Person');
572+
const yoda = new Person({
573+
'firstName': 'Yoda',
574+
'lastName': 'Master',
575+
'likes': ['teaching']
576+
});
577+
578+
yoda.on('error', function (data) {
579+
this.lastName('error');
580+
});
581+
582+
yoda.on('testMethod', function () {
583+
ANonDefinedFunction();
584+
});
585+
yoda.testMethod();
586+
587+
setTimeout(function () {
588+
expect(yoda.lastName()).equal('error');
589+
done();
590+
}, 1);
591+
});
521592
});

test/runtime/runtime-spec.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,79 @@ describe('System Runtime runtime component', () => {
3030

3131
it('can get the status of all installed systems', () => {
3232
const status = runtime.status();
33-
33+
3434
expect(status).to.not.be.undefined;
3535
});
36+
37+
it('can install a system', () => {
38+
const systemId = runtime.install({
39+
"name": "Test",
40+
"master": true,
41+
"version": "0.0.1",
42+
"description": "",
43+
"schemas": {
44+
"k141cc1821c1b775": {
45+
"_id": "k141cc1821c1b775",
46+
"_name": "TestSchema",
47+
"_inherit": [
48+
"_Component"
49+
]
50+
}
51+
},
52+
"models": {
53+
"b19c171575f1824b": {
54+
"_id": "b19c171575f1824b",
55+
"_name": "TestSchema",
56+
"_description": ""
57+
}
58+
},
59+
"behaviors": {
60+
"n1e72b1ed051cf36": {
61+
"_id": "n1e72b1ed051cf36",
62+
"component": "k16d101760d1ec2a",
63+
"state": "start",
64+
"action": "function start() { \n \n}",
65+
"useCoreAPI": false,
66+
"core": false
67+
}
68+
},
69+
"types": {
70+
"TestType": {
71+
"_id": "o1cf651e05613735",
72+
"name": "TestType",
73+
"description": "",
74+
"type": "object",
75+
"schema": {
76+
"property1": {
77+
"type": "any",
78+
"mandatory": false,
79+
"default": ""
80+
},
81+
"property2": {
82+
"type": "any",
83+
"mandatory": false,
84+
"default": ""
85+
}
86+
}
87+
}
88+
},
89+
"components": {
90+
"TestSchema": {
91+
"z1f91a1beb01f48f": {
92+
"_id": "z1f91a1beb01f48f"
93+
}
94+
}
95+
},
96+
"_id": "k16d101760d1ec2a"
97+
});
98+
99+
expect(systemId).equal('k16d101760d1ec2a');
100+
});
101+
102+
it('can uninstall a system', () => {
103+
runtime.uninstall('k16d101760d1ec2a');
104+
const state = runtime.require('k16d101760d1ec2a').state();
105+
106+
expect(state).equal('uninstalled');
107+
});
36108
});

0 commit comments

Comments
 (0)