Skip to content

fix(vis-network): unit tests #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 47 additions & 16 deletions workspaces/vis-network/test/dataset-payload.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "abcde",
"rootDepencyName": "pkg1",
"rootDependencyName": "pkg1",
"highlighted": {
"contacts": [
{
Expand All @@ -11,7 +11,7 @@
"js-x-ray"
]
},
{
{
"name": "Rich Harris",
"email": "[email protected]",
"dependencies": [
Expand All @@ -34,6 +34,13 @@
},
"dependencies": {
"pkg2": {
"metadata": {
"author": {
"name": "john papa"
},
"maintainers": [],
"publishers": []
},
"versions": {
"1.0.3": {
"usedBy": {
Expand All @@ -51,17 +58,23 @@
".json"
]
},
"license": {
"uniqueLicenseIds": [
"Unlicense"
]
},
"licenses": [],
"uniqueLicenseIds": [
"Unlicense"
],
"name": "pkg2",
"version": "1.0.3"
}
}
},
"pkg3": {
"metadata": {
"author": {
"name": "john wick"
},
"maintainers": [],
"publishers": []
},
"versions": {
"3.4.0": {
"id": 4,
Expand All @@ -85,15 +98,21 @@
".json"
]
},
"license": {
"uniqueLicenseIds": [
"Licence1"
]
}
"licenses": [],
"uniqueLicenseIds": [
"Licence1"
]
}
}
},
"pkg1": {
"metadata": {
"author": {
"name": "john doe"
},
"maintainers": [],
"publishers": []
},
"versions": {
"3.0.0": {
"id": 0,
Expand All @@ -114,15 +133,27 @@
".json"
]
},
"license": "a string licence (should be unknown)",
"licenses": [
{
"licenses": {},
"spdx": {
"osi": true,
"fsf": true,
"fsfAndOsi": true,
"includesDeprecated": true
}
}
],
"uniqueLicenseIds": [],
"warnings": []
}
}
}
},
"version": "2.2.0",
"scannerVersion": "2.2.0",
"warnings": [
"warning_01",
"warning_02"
]
}
],
"vulnerabilityStrategy": "npm"
}
18 changes: 11 additions & 7 deletions workspaces/vis-network/test/dataset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import { getDataSetPayload } from "./dataset.fixture.js";

const dataSetPayload = await getDataSetPayload();

global.window = {
settings: {
config: {
showFriendlyDependencies: true
}
}
};

test("NodeSecureDataSet.init with given payload", async() => {
const nsDataSet = new NodeSecureDataSet();
await nsDataSet.init(dataSetPayload);
Expand Down Expand Up @@ -57,21 +65,17 @@ test("NodeSecureDataSet.isHighlighted", async() => {

test("NodeSecureDataSet.computeLicenses", () => {
const nsDataSet = new NodeSecureDataSet();
nsDataSet.computeLicense("MIT");
assert.equal(Object.keys(nsDataSet.licenses).length, 1, "should have 1 license");
assert.equal(nsDataSet.licenses.Unknown, 1, "should have 1 unknown license");

nsDataSet.computeLicense({ uniqueLicenseIds: ["MIT", "MIT", "RND"] });
nsDataSet.computeLicense(["MIT", "MIT", "RND"]);
assert.equal(Object.keys(nsDataSet.licenses).length, 3, "should have 3 licenses (MIT, RND & 1 unknown)");
assert.equal(nsDataSet.licenses.MIT, 2, "should have 2 MIT licenses");
});

test("NodeSecureDataSet.computeAuthors", () => {
const nsDataSet = new NodeSecureDataSet();
nsDataSet.computeAuthor({ name: "John Doe" });
nsDataSet.computeAuthor({ name: "John Doe" }, "[email protected]");
assert.equal(nsDataSet.authors.get("John Doe").packages.size, 1, "should have 1 author: John Doe");

nsDataSet.computeAuthor({ name: "John Doe" });
nsDataSet.computeAuthor({ name: "John Doe" }, "[email protected]");

assert.equal(nsDataSet.authors.size, 1, "should have 1 author: John Doe (after the 2nd contribution");
assert.equal(nsDataSet.authors.get("John Doe").packages.size, 2, "should have 1 author: John Doe (2nd time)");
Expand Down
Loading