-
Notifications
You must be signed in to change notification settings - Fork 11
/
h.CheckDataGrabber.js
153 lines (145 loc) · 4.74 KB
/
h.CheckDataGrabber.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const assert = require('chai').assert;
const expect = require('chai').expect;
const should = require('chai').should();
const CheckDataGrabber = require('../src/js/components/core/create_project/CheckDataGrabber.js');
const CheckStore = require('../src/js/stores/CheckStore.js');
const CoreStore = require('../src/js/stores/CoreStore.js');
const path = require('path-extra');
const api = window.ModuleApi;
const fs = require(window.__base + 'node_modules/fs-extra');
const PARENT = path.datadir('translationCore');
const PACKAGE_SAVE_LOCATION = path.join(PARENT, 'packages-compiled');
const testTool = path.join(PACKAGE_SAVE_LOCATION, 'ExampleChecker');
const testCheckArray = [
{
"name": "ExampleChecker",
"location": path.join(PACKAGE_SAVE_LOCATION , "ExampleChecker")
},
{
"name": "TPane",
"location": path.join(PACKAGE_SAVE_LOCATION , "TPane")
},
{
"name": "ExampleTool",
"location": path.join(PACKAGE_SAVE_LOCATION , "ExampleTool")
},
{
"name": "CommentBox",
"location": path.join(PACKAGE_SAVE_LOCATION , "CommentBox")
}
];
const testCheckArrayBadPath = [
{
"name": "ExampleChecker",
"location": path.join(PACKAGE_SAVE_LOCATION , "ExampleChecker")
},
{
"name": "TPane",
"location": path.join(PACKAGE_SAVE_LOCATION , "TPane")
},
{
"name": "ExampleTool",
"location": path.join(PACKAGE_SAVE_LOCATION , "ExampleTool")
},
{
"name": "CommentBox",
"location": path.join(PACKAGE_SAVE_LOCATION , "HiliarysEmails")
}
];
const testDataObject = {
"name": "ExampleChecker",
"title": "Example Check",
"version": "1.0.0",
"description": "This is an example check app for reference for developers.",
"main": "View.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"display": "app",
"repository": {
"type": "git"
},
"include": [
"TPane",
"ExampleTool",
"CommentBox"
],
"dependencies": {
"babel-preset-react": "^6.16.0"
}
};
const testDataObjectBadPackageJSON = {
"name": "ExampleChecker",
"version": "1.0.0",
"description": "This is an example check app for reference for developers.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"display": "app",
"repository": {
"type": "git"
},
"include": [
"TPane",
"ExampleTool",
"CommentBox"
],
"dependencies": {
"babel-preset-react": "^6.16.0"
}
};
describe('CheckDataGrabber.saveModules', function () {
it('should fetch the data given a valid check array', function (done) {
CheckDataGrabber.saveModules(testCheckArray, function (err, checksThatNeedToBeFetched) {
assert.isNull(err);
assert.isArray(checksThatNeedToBeFetched);
done();
});
});
});
describe('CheckDataGrabber.fetchModules', function () {
it('should fail on a bad path of a checking tool sub modules', function (done) {
CheckDataGrabber.fetchModules(testCheckArrayBadPath, function (err, success) {
assert.isNotNull(err);
assert.isFalse(success);
assert.isTrue(CoreStore.doneLoading);
done();
});
});
it('should fetch the data given a valid check array', function (done) {
CheckDataGrabber.fetchModules(testCheckArray, function (err, success) {
assert.isNull(err);
assert.isTrue(success);
done();
});
});
});
describe('CheckDataGrabber.loadModuleAndDependencies', function () {
it('should load a tool', function (done) {
CheckDataGrabber.loadModuleAndDependencies(testTool, (err, success) => {
assert.isNull(err);
assert.isTrue(success);
assert.isObject(api.getDataFromCommon('params'));
expect(api.getDataFromCommon('arrayOfChecks')).to.exist;
expect(api.modules['ExampleChecker']).to.exist;
done();
});
});
});
describe('CheckDataGrabber.createCheckArray', function () {
it('should not create a check array from a bad data object', function (done) {
CheckDataGrabber.createCheckArray(testDataObjectBadPackageJSON, testTool, (err, checkArray) => {
assert.isNotNull(err);
assert.isNull(checkArray);
done();
});
});
it('should create a check array from a sample data object', function (done) {
CheckDataGrabber.createCheckArray(testDataObject, testTool, (err, checkArray) => {
assert.isNull(err);
assert.isArray(checkArray);
assert.deepEqual(checkArray, testCheckArray);
done();
});
});
});