33const MetadataGenerator = require ( '../../lib/metadata_gen' ) ;
44const {
55 fixAndRefPR,
6+ selfRefPR,
7+ duplicateRefPR,
68 fixCrossPR,
79 backportPR,
810 allGreenReviewers
911} = require ( '../fixtures/data' ) ;
1012
1113const assert = require ( 'assert' ) ;
14+
1215const data = {
1316 owner : 'nodejs' ,
1417 repo : 'node' ,
1518 pr : fixAndRefPR ,
1619 reviewers : allGreenReviewers
1720} ;
18- const crossData = Object . assign ( { } , data , { pr : fixCrossPR } ) ;
21+ const expected = `PR-URL: https://github.com/nodejs/node/pull/16438
22+ Fixes: https://github.com/nodejs/node/issues/16437
23+ Refs: https://github.com/nodejs/node/pull/15148
24+ Reviewed-By: Foo User <foo@example.com>
25+ Reviewed-By: Quux User <quux@example.com>
26+ Reviewed-By: Baz User <baz@example.com>
27+ Reviewed-By: Bar User <bar@example.com>
28+ ` ;
29+
1930const backportArgv = {
2031 argv : {
2132 owner : 'nodejs' ,
@@ -29,36 +40,55 @@ const backportArgv = {
2940 backport : true
3041 }
3142} ;
32-
3343const backportData = Object . assign ( { } , data , { pr : backportPR } , backportArgv ) ;
44+ const backportExpected = `PR-URL: https://github.com/nodejs/node/pull/29995
45+ Backport-PR-URL: https://github.com/nodejs/node/pull/30072
46+ Fixes: https://github.com/nodejs/build/issues/1961
47+ Refs: https://github.com/nodejs/node/commit/53ca0b9ae145c430842bf78e553e3b6cbd2823aa#commitcomment-35494896
48+ ` ;
3449
35- const expected = `PR-URL: https://github.com/nodejs/node/pull/16438
36- Fixes: https://github.com/nodejs/node/issues/16437
37- Refs: https://github.com/nodejs/node/pull/15148
50+ const selfRefData = Object . assign ( { } , data , { pr : selfRefPR } ) ;
51+ const selfRefExpected = `PR-URL: https://github.com/nodejs/node/pull/16438
3852Reviewed-By: Foo User <foo@example.com>
3953Reviewed-By: Quux User <quux@example.com>
4054Reviewed-By: Baz User <baz@example.com>
4155Reviewed-By: Bar User <bar@example.com>
4256` ;
57+
58+ const duplicateRefData = Object . assign ( { } , data , { pr : duplicateRefPR } ) ;
59+ const duplicateRefExpected = `PR-URL: https://github.com/nodejs/node/pull/16438
60+ Refs: https://github.com/nodejs/node/pull/16439
61+ Reviewed-By: Foo User <foo@example.com>
62+ Reviewed-By: Quux User <quux@example.com>
63+ Reviewed-By: Baz User <baz@example.com>
64+ Reviewed-By: Bar User <bar@example.com>
65+ ` ;
66+
67+ const crossData = Object . assign ( { } , data , { pr : fixCrossPR } ) ;
4368const crossExpected = `PR-URL: https://github.com/nodejs/node/pull/16438
4469Fixes: https://github.com/joyeecheung/node-core-utils/issues/123
4570Reviewed-By: Foo User <foo@example.com>
4671Reviewed-By: Quux User <quux@example.com>
4772Reviewed-By: Baz User <baz@example.com>
4873Reviewed-By: Bar User <bar@example.com>
4974` ;
50- const backportExpected = `PR-URL: https://github.com/nodejs/node/pull/29995
51- Backport-PR-URL: https://github.com/nodejs/node/pull/30072
52- Fixes: https://github.com/nodejs/build/issues/1961
53- Refs: https://github.com/nodejs/node/commit/53ca0b9ae145c430842bf78e553e3b6cbd2823aa#commitcomment-35494896
54- ` ;
5575
5676describe ( 'MetadataGenerator' , ( ) => {
5777 it ( 'should generate metadata properly' , ( ) => {
5878 const results = new MetadataGenerator ( data ) . getMetadata ( ) ;
5979 assert . strictEqual ( expected , results ) ;
6080 } ) ;
6181
82+ it ( 'should prevent duplicate references' , ( ) => {
83+ const results = new MetadataGenerator ( duplicateRefData ) . getMetadata ( ) ;
84+ assert . strictEqual ( duplicateRefExpected , results ) ;
85+ } ) ;
86+
87+ it ( 'should prevent self-referential references' , ( ) => {
88+ const results = new MetadataGenerator ( selfRefData ) . getMetadata ( ) ;
89+ assert . strictEqual ( selfRefExpected , results ) ;
90+ } ) ;
91+
6292 it ( 'should handle cross-owner and cross-repo fixes properly' , ( ) => {
6393 const results = new MetadataGenerator ( crossData ) . getMetadata ( ) ;
6494 assert . strictEqual ( crossExpected , results ) ;
0 commit comments