@@ -117,6 +117,24 @@ suite('Factories.PackageUrlFactory', () => {
117117 assert . deepStrictEqual ( actual , expected )
118118 } )
119119
120+ test ( 'extRef empty url -> omit' , ( ) => {
121+ const component = new Models . Component (
122+ Enums . ComponentType . Library ,
123+ `name-${ salt } ` ,
124+ {
125+ externalReferences : new Models . ExternalReferenceRepository ( [
126+ new Models . ExternalReference ( '' , Enums . ExternalReferenceType . VCS ) ,
127+ new Models . ExternalReference ( '' , Enums . ExternalReferenceType . Distribution )
128+ ] )
129+ }
130+ )
131+ const expected = new PackageURL ( 'testing' , undefined , `name-${ salt } ` , undefined , { } , undefined )
132+
133+ const actual = sut . makeFromComponent ( component )
134+
135+ assert . deepStrictEqual ( actual , expected )
136+ } )
137+
120138 test ( 'hashes -> qualifiers.checksum' , ( ) => {
121139 const component = new Models . Component (
122140 Enums . ComponentType . Library ,
@@ -134,7 +152,7 @@ suite('Factories.PackageUrlFactory', () => {
134152 assert . deepStrictEqual ( actual , expected )
135153 } )
136154
137- test ( 'sorted' , ( ) => {
155+ test ( 'sorted hashes ' , ( ) => {
138156 const component = new Models . Component (
139157 Enums . ComponentType . Library ,
140158 'name' ,
@@ -164,5 +182,47 @@ suite('Factories.PackageUrlFactory', () => {
164182 assert . deepStrictEqual ( actual , expectedObject )
165183 assert . deepStrictEqual ( actual . toString ( ) , expectedString )
166184 } )
185+
186+ test ( 'sorted references' , ( ) => {
187+ const component1 = new Models . Component (
188+ Enums . ComponentType . Library ,
189+ 'name' ,
190+ {
191+ externalReferences : new Models . ExternalReferenceRepository ( [
192+ new Models . ExternalReference ( 'https://foo.bar/download-1' , Enums . ExternalReferenceType . Distribution ) ,
193+ new Models . ExternalReference ( 'git+https://foo.bar/repo.git' , Enums . ExternalReferenceType . VCS ) ,
194+ new Models . ExternalReference ( 'https://foo.bar/download-2' , Enums . ExternalReferenceType . Distribution )
195+ ] )
196+ }
197+ )
198+ const component2 = new Models . Component (
199+ Enums . ComponentType . Library ,
200+ 'name' ,
201+ {
202+ externalReferences : new Models . ExternalReferenceRepository ( [
203+ // different order of extRefs
204+ new Models . ExternalReference ( 'https://foo.bar/download-2' , Enums . ExternalReferenceType . Distribution ) ,
205+ new Models . ExternalReference ( 'git+https://foo.bar/repo.git' , Enums . ExternalReferenceType . VCS ) ,
206+ new Models . ExternalReference ( 'https://foo.bar/download-1' , Enums . ExternalReferenceType . Distribution )
207+ ] )
208+ }
209+ )
210+ const expectedObject = new PackageURL ( 'testing' , undefined , 'name' , undefined ,
211+ {
212+ // expect sorted hash list
213+ download_url : 'https://foo.bar/download-2' ,
214+ vcs_url : 'git+https://foo.bar/repo.git'
215+ } , undefined )
216+ // expect objet's keys in alphabetical oder, expect sorted hash list
217+ const expectedString = 'pkg:testing/name?download_url=https://foo.bar/download-2&vcs_url=git+https://foo.bar/repo.git'
218+
219+ const actual1 = sut . makeFromComponent ( component1 , true )
220+ const actual2 = sut . makeFromComponent ( component2 , true )
221+
222+ assert . deepStrictEqual ( actual1 , expectedObject )
223+ assert . deepStrictEqual ( actual1 . toString ( ) , expectedString )
224+ assert . deepStrictEqual ( actual2 , expectedObject )
225+ assert . deepStrictEqual ( actual2 . toString ( ) , expectedString )
226+ } )
167227 } )
168228} )
0 commit comments