Skip to content

Commit 7ccaea7

Browse files
committed
#39: Added toJSTreeFormat test"
* Updated toJSTreeFormat to use un-flattened File table Signed-off-by: Jillian Daguil <[email protected]>
1 parent 0300046 commit 7ccaea7

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

assets/js/aboutCodeDB.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ class AboutCodeDB {
157157
toJSTreeFormat() {
158158
return this.db
159159
.then(() => {
160-
return this.FlattenedFile.findAll({
161-
attributes: ["path", "parent", "infos_file_name", "infos_type"]
160+
return this.File.findAll({
161+
attributes: ["path", "parent", "name", "type"]
162162
});
163163
})
164164
.then((files) => {
165165
return files.map((file) => {
166166
return {
167167
id: file.path,
168-
text: file.infos_file_name,
168+
text: file.name,
169169
parent: file.parent,
170-
type: file.infos_type
170+
type: file.type
171171
};
172172
});
173173
});

test/aboutCodeDB.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,31 @@ describe("checkAboutCodeDB", function() {
6666
})
6767
});
6868
});
69+
70+
describe("toJSTreeFormat", function() {
71+
it("should format ScanCode results to jsTree Format", function() {
72+
let aboutCodeDB = new AboutCodeDB();
73+
let expectedJSTreeFormat= [
74+
{
75+
id: 'samples/README',
76+
text: 'README',
77+
parent: 'samples',
78+
type: 'file'
79+
},
80+
{
81+
id: 'samples/JGroups/src',
82+
text: 'src',
83+
parent: 'samples/JGroups',
84+
type: 'directory'
85+
}
86+
];
87+
88+
return aboutCodeDB.db
89+
.then(() => aboutCodeDB.addRows(scanCodeJSONResults))
90+
.then(() => aboutCodeDB.toJSTreeFormat())
91+
.then((scanCodeJSONResults) => {
92+
assert.deepEqual(expectedJSTreeFormat, scanCodeJSONResults)
93+
})
94+
});
95+
});
6996
});

0 commit comments

Comments
 (0)