Skip to content

Commit f2bee3d

Browse files
committed
#39: Initial tests for AboutCodeDB
Signed-off-by: Jillian Daguil <[email protected]>
1 parent f337b51 commit f2bee3d

File tree

1 file changed

+152
-158
lines changed

1 file changed

+152
-158
lines changed

test/scanData.test.js

Lines changed: 152 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
var jsdom = require("jsdom");
2-
var window = jsdom.jsdom().defaultView;
3-
var $ = require("jquery")(window);
1+
const jsdom = require("jsdom");
2+
const window = jsdom.jsdom().defaultView;
3+
const $ = require("jquery")(window);
44
global.$ = $;
5-
var ScanData = require("../assets/js/scandata");
6-
var exportToDejaCode = require("../assets/js/export-to-dejacode");
5+
const ScanData = require("../assets/js/scandata");
6+
const AboutCodeDB = require("../assets/js/aboutCodeDB");
77

8-
var assert = require("chai").assert;
9-
var fs = require("fs");
8+
const assert = require("chai").assert;
9+
const fs = require("fs");
1010

1111
describe("getScanData", function () {
1212
it("should return an array", function () {
@@ -18,93 +18,6 @@ describe("getScanData", function () {
1818
})
1919
});
2020

21-
describe("checkJSTreeDataFormat", function () {
22-
var expectedJSTreeData = [
23-
{
24-
id: 'root',
25-
text: 'root',
26-
parent: '#',
27-
type: 'file', // TODO: This is a bug that needs to be fixed
28-
scanData: { path: 'root' }
29-
},
30-
{
31-
id: 'root/dir1',
32-
text: 'dir1',
33-
parent: 'root',
34-
type: 'folder',
35-
scanData: { path: 'root/dir1/file1' }
36-
},
37-
{
38-
id: 'root/dir1/file1',
39-
text: 'file1',
40-
parent: 'root/dir1',
41-
type: 'file',
42-
scanData: { path: 'root/dir1/file1' }
43-
},
44-
{
45-
id: 'root/dir1/file2',
46-
text: 'file2',
47-
parent: 'root/dir1',
48-
type: 'file',
49-
scanData: { path: 'root/dir1/file2' }
50-
}
51-
];
52-
53-
it("should return the parent child jsTree format", function () {
54-
var json = JSON.parse(fs.readFileSync(__dirname + "/data/scandata.json", "utf8"));
55-
var scandata = new ScanData(json);
56-
assert.deepEqual(scandata.jsTreeData, expectedJSTreeData);
57-
})
58-
});
59-
60-
describe("checkNodeViewDataFormat", function () {
61-
var expectedNodeViewData =
62-
{
63-
"id": "root",
64-
"name": "root",
65-
"parent": "#",
66-
"children": [
67-
{
68-
"id": "root/dir1",
69-
"name": "dir1",
70-
"parent": "root",
71-
"children": [
72-
{
73-
"id": "root/dir1/file1",
74-
"name": "file1",
75-
"parent": "root/dir1",
76-
"children": [],
77-
"scanData": {
78-
"path": "root/dir1/file1"
79-
}
80-
},
81-
{
82-
"id": "root/dir1/file2",
83-
"name": "file2",
84-
"parent": "root/dir1",
85-
"children": [],
86-
"scanData": {
87-
"path": "root/dir1/file2"
88-
}
89-
}
90-
],
91-
"scanData": {
92-
"path": "root/dir1/file1"
93-
}
94-
}
95-
],
96-
"scanData": {
97-
"path": "root"
98-
}
99-
}
100-
101-
it("should return the node view format", function () {
102-
var json = JSON.parse(fs.readFileSync(__dirname + "/data/scandata.json", "utf8"));
103-
var scandata = new ScanData(json);
104-
assert.deepEqual(scandata.nodeViewData[0], expectedNodeViewData);
105-
})
106-
});
107-
10821
describe("getComponentDataFormat", function () {
10922
var expectedComponent = [
11023
{
@@ -255,78 +168,159 @@ describe("testSavingAndLoading", function () {
255168
})
256169
});
257170

258-
describe("checkToDejaCodeFormat", function () {
259-
var savedComponentFormat = [
260-
{
261-
files: [{path: 'samples/nexB'}],
262-
review_status: 'original',
263-
name: 'scancode',
264-
version: '1.0',
265-
licenses: [
171+
describe("checkAboutCodeDB", function() {
172+
const scanCodeJSONResults = {
173+
"files": [
174+
{
175+
"path": "samples/README",
176+
"type": "file",
177+
"name": "README",
178+
"extension": "",
179+
"date": "2017-04-08",
180+
"size": 236,
181+
"sha1": "2e07e32c52d607204fad196052d70e3d18fb8636",
182+
"md5": "effc6856ef85a9250fb1a470792b3f38",
183+
"files_count": 1,
184+
"mime_type": "text/plain",
185+
"file_type": "ASCII text",
186+
"programming_language": "text",
187+
"is_binary": false,
188+
"is_text": true,
189+
"is_archive": false,
190+
"is_media": false,
191+
"is_source": false,
192+
"is_script": false,
193+
"licenses": [
266194
{
267-
"key": "nexb proprietary",
268-
"short_name": "nexB Proprietary"
195+
"key": "jboss-eula",
196+
"score": 100,
197+
"short_name": "JBoss EULA",
198+
"category": "Proprietary Free",
199+
"owner": "JBoss Community",
200+
"homepage_url": "",
201+
"text_url": "http://repository.jboss.org/licenses/jbossorg-eula.txt",
202+
"dejacode_url": "https://enterprise.dejacode.com/urn/urn:dje:license:jboss-eula",
203+
"spdx_license_key": "",
204+
"spdx_url": "",
205+
"start_line": 3,
206+
"end_line": 108,
207+
"matched_rule": {
208+
"identifier": "jboss-eula.LICENSE",
209+
"license_choice": false,
210+
"licenses": [
211+
"jboss-eula"
212+
]
213+
}
214+
}
215+
],
216+
"copyrights": [
217+
{
218+
"statements": [
219+
"Copyright (c) 1991, 1999 Free Software Foundation, Inc."
220+
],
221+
"holders": [
222+
"Free Software Foundation, Inc."
223+
],
224+
"authors": [],
225+
"start_line": 4,
226+
"end_line": 7
269227
},
270228
{
271-
"short_name": "ZLIB License",
272-
"key": "zlib license"
229+
"statements": [
230+
"copyrighted by the Free Software Foundation"
231+
],
232+
"holders": [
233+
"Free Software Foundation"
234+
],
235+
"authors": [],
236+
"start_line": 426,
237+
"end_line": 433
273238
}
274-
],
275-
copyrights: [ 'Copyright (c) 2016 nexB, Inc.' ],
276-
party: { name: 'nexB' },
277-
programming_language: 'Python',
278-
homepage_url: 'www.dejacode.com',
279-
notes: '',
280-
license_expression: "nexb proprietary and zlib license"
281-
},
282-
{
283-
files: [{path: 'samples/jquery-1.7.2.js'}],
284-
review_status: 'analyzed',
285-
name: 'jQuery',
286-
version: '1.7.2',
287-
licenses: [
239+
],
240+
"packages": [
241+
{
242+
"type": "plain tarball",
243+
"name": null,
244+
"version": null,
245+
"primary_language": null,
246+
"packaging": "archive",
247+
"summary": null,
248+
"description": null,
249+
"payload_type": null,
250+
"authors": [],
251+
"maintainers": [],
252+
"contributors": [],
253+
"owners": [],
254+
"packagers": [],
255+
"distributors": [],
256+
"vendors": [],
257+
"keywords": [],
258+
"keywords_doc_url": null,
259+
"metafile_locations": [],
260+
"metafile_urls": [],
261+
"homepage_url": null,
262+
"notes": null,
263+
"download_urls": [],
264+
"download_sha1": null,
265+
"download_sha256": null,
266+
"download_md5": null,
267+
"bug_tracking_url": null,
268+
"support_contacts": [],
269+
"code_view_url": null,
270+
"vcs_tool": null,
271+
"vcs_repository": null,
272+
"vcs_revision": null,
273+
"copyright_top_level": null,
274+
"copyrights": [],
275+
"asserted_licenses": [],
276+
"legal_file_locations": [],
277+
"license_expression": null,
278+
"license_texts": [],
279+
"notice_texts": [],
280+
"dependencies": {},
281+
"related_packages": []
282+
}
283+
],
284+
"emails": [
285+
{
286+
"email": "[email protected]",
287+
"start_line": 29,
288+
"end_line": 29
289+
}
290+
],
291+
"urls": [
288292
{
289-
"key": "mit",
290-
"short_name": "MIT License"
293+
"url": "http://zlib.net/zlib-1.2.8.tar.gz",
294+
"start_line": 3,
295+
"end_line": 3
291296
},
292297
{
293-
"short_name": "GPL 2.0",
294-
"key": "gpl-2.0"
298+
"url": "http://master.dl.sourceforge.net/project/javagroups/JGroups/2.10.0.GA/JGroups-2.10.0.GA.src.zip",
299+
"start_line": 4,
300+
"end_line": 4
295301
}
296-
],
297-
copyrights: [ 'Copyright 2011, John Resig' ],
298-
party: { name: 'jQuery Project' },
299-
programming_language: 'JavaScript',
300-
homepage_url: 'http://jquery.com/',
301-
license_expression: "mit or gpl-2.0",
302-
notes: 'Dual licensed under the MIT or GPL Version 2 licenses.'
303-
}
304-
];
302+
]
303+
}]
304+
};
305305

306-
var expectedDejaCodeFormat = [
307-
{
308-
name: 'scancode',
309-
version: '1.0',
310-
license_expression: 'nexb proprietary and zlib license',
311-
owner: 'nexB',
312-
copyright: 'Copyright (c) 2016 nexB, Inc.',
313-
primary_language: 'Python',
314-
homepage_url: 'www.dejacode.com',
315-
reference_notes: ''
316-
},
317-
{
318-
name: 'jQuery',
319-
version: '1.7.2',
320-
license_expression: 'mit or gpl-2.0',
321-
owner: 'jQuery Project',
322-
copyright: 'Copyright 2011, John Resig',
323-
primary_language: 'JavaScript',
324-
homepage_url: 'http://jquery.com/',
325-
reference_notes: 'Dual licensed under the MIT or GPL Version 2 licenses.'
326-
}
327-
];
306+
it("should add rows to database", function () {
307+
let aboutCodeDB = new AboutCodeDB();
328308

329-
it("should return the JSON format DejaCode expects", function () {
330-
assert.deepEqual(exportToDejaCode.toDejaCodeFormat(savedComponentFormat), expectedDejaCodeFormat);
331-
})
309+
return aboutCodeDB.db
310+
.then(() => aboutCodeDB.File.count())
311+
.then((rowCount) => assert.strictEqual(rowCount, 0))
312+
.then(() => aboutCodeDB.addRows(scanCodeJSONResults))
313+
.then(() => aboutCodeDB.File.count())
314+
.then((rowCount) => assert.strictEqual(rowCount, 1))
315+
.then(() => aboutCodeDB.License.count())
316+
.then((licenseCount) => assert.strictEqual(licenseCount,1))
317+
.then(() => aboutCodeDB.Copyright.count())
318+
.then((copyrightCount) => assert.strictEqual(copyrightCount, 2))
319+
.then(() => aboutCodeDB.Package.count())
320+
.then((packageCount) => assert.strictEqual(packageCount, 1))
321+
.then(() => aboutCodeDB.Email.count())
322+
.then((emailCount) => assert.strictEqual(emailCount, 1))
323+
.then(() => aboutCodeDB.Url.count())
324+
.then((urlCount) => assert.strictEqual(urlCount, 2))
325+
});
332326
});

0 commit comments

Comments
 (0)