Skip to content

Commit

Permalink
Merge branch 'kaklakariada/issue577' into kaklakariada/issue578
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Jun 3, 2024
2 parents 7f3681b + a1988cf commit c00d7f5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ private List<License> moduleLicenses(final String moduleName) {
}

private String getUrl(final String moduleName) {
return this.additionalInfo.getJsonObject(moduleName).getString("resolved");
return Optional.ofNullable(this.additionalInfo.getJsonObject(moduleName)) //
.filter(object -> object.containsKey("resolved")) //
.map(object -> object.getString("resolved")) //
.orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ void getDependencies() {
));
}

@Test
void getDependenciesMissingUrl() {
when(this.npmServices.listDependencies(any())).thenReturn(json(TestData.DEPENDENCIES_MISSING_URL));
when(this.npmServices.getLicenses(any())).thenReturn(json(TestData.LICENSES));

final NpmDependencies testee = new NpmDependencies(this.npmServices, TestData.samplePackageJson());
assertThat(testee.getDependencies(), containsInAnyOrder( //
dependency(Type.DEV, "changed-plugin", "1.2.0", "CP"), //
dependency(Type.DEV, "new-plugin", "1.3.0", "NP"), //
dependency(Type.COMPILE, "changed-compile", "2.2.0", "CC"), //
ProjectDependency.builder() //
.type(Type.COMPILE)//
.name("new-compile") //
.websiteUrl(null) //
.licenses(List.of(new License("NC" + "-License", "https://" + "new-compile"))) //
.build() //
));
}

private ProjectDependency dependency(final Type type, final String name, final String version,
final String license) {
return ProjectDependency.builder() //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ class TestData {
" }", //
"}");

static final String DEPENDENCIES_MISSING_URL = jsonString("{", //
" 'name': 'module-name',", //
" 'version': '2.0.0',", //
" 'dependencies': {", //
" 'changed-plugin': {", //
" 'version': '1.2.0',", //
" 'resolved': 'https://changed-plugin/-/1.2.0.tgz'", //
" },", //
" 'new-plugin': {", //
" 'version': '1.3.0',", //
" 'resolved': 'https://new-plugin/-/1.3.0.tgz'", //
" },", //
" 'changed-compile': {", //
" 'version': '2.2.0',", //
" 'resolved': 'https://changed-compile/-/2.2.0.tgz'", //
" },", //
" 'new-compile': {", //
" 'version': '2.3.0'", //
" }", //
" }", //
"}");

static String jsonString(final String... s) {
return String.join("\n", s).replace('\'', '"');
}
Expand Down

0 comments on commit c00d7f5

Please sign in to comment.