1- import { describe , it , before } from 'node:test' ;
1+ import { describe , it , before , afterEach } from 'node:test' ;
22import assert from 'assert' ;
33
44import sinon from 'sinon' ;
99 CI_CRUMB_URL ,
1010 CI_PR_URL
1111} from '../../lib/ci/run_ci.js' ;
12+ import PRChecker from '../../lib/pr_checker.js' ;
1213
1314import TestCLI from '../fixtures/test_cli.js' ;
1415
@@ -51,7 +52,7 @@ describe('Jenkins', () => {
5152 . returns ( Promise . resolve ( { crumb } ) )
5253 } ;
5354
54- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid ) ;
55+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , true ) ;
5556 assert . strictEqual ( await jobRunner . start ( ) , false ) ;
5657 } ) ;
5758
@@ -61,7 +62,7 @@ describe('Jenkins', () => {
6162 json : sinon . stub ( ) . throws ( )
6263 } ;
6364
64- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid ) ;
65+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , true ) ;
6566 assert . strictEqual ( await jobRunner . start ( ) , false ) ;
6667 } ) ;
6768
@@ -89,7 +90,7 @@ describe('Jenkins', () => {
8990 json : sinon . stub ( ) . withArgs ( CI_CRUMB_URL )
9091 . returns ( Promise . resolve ( { crumb } ) )
9192 } ;
92- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid ) ;
93+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , true ) ;
9394 assert . ok ( await jobRunner . start ( ) ) ;
9495 } ) ;
9596
@@ -108,7 +109,48 @@ describe('Jenkins', () => {
108109 json : sinon . stub ( ) . withArgs ( CI_CRUMB_URL )
109110 . returns ( Promise . resolve ( { crumb } ) )
110111 } ;
111- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid ) ;
112+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , true ) ;
112113 assert . strictEqual ( await jobRunner . start ( ) , false ) ;
113114 } ) ;
115+
116+ describe ( 'without --certify-safe flag' , { concurrency : false } , ( ) => {
117+ afterEach ( ( ) => {
118+ sinon . restore ( ) ;
119+ } ) ;
120+ for ( const certifySafe of [ true , false ] ) {
121+ it ( `should return ${ certifySafe } if PR checker reports it as ${
122+ certifySafe ? '' : 'potentially un'
123+ } safe`, async ( ) => {
124+ const cli = new TestCLI ( ) ;
125+
126+ sinon . replace ( PRChecker . prototype , 'checkCommitsAfterReview' ,
127+ sinon . fake . returns ( certifySafe ) ) ;
128+
129+ const request = {
130+ gql : sinon . stub ( ) . returns ( {
131+ repository : {
132+ pullRequest : {
133+ labels : {
134+ nodes : [ ]
135+ }
136+ }
137+ }
138+ } ) ,
139+ fetch : sinon . stub ( )
140+ . callsFake ( ( url , { method, headers, body } ) => {
141+ assert . strictEqual ( url , CI_PR_URL ) ;
142+ assert . strictEqual ( method , 'POST' ) ;
143+ assert . deepStrictEqual ( headers , { 'Jenkins-Crumb' : crumb } ) ;
144+ assert . ok ( body . _validated ) ;
145+ return Promise . resolve ( { status : 201 } ) ;
146+ } ) ,
147+ json : sinon . stub ( ) . withArgs ( CI_CRUMB_URL )
148+ . returns ( Promise . resolve ( { crumb } ) )
149+ } ;
150+
151+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , false ) ;
152+ assert . strictEqual ( await jobRunner . start ( ) , certifySafe ) ;
153+ } ) ;
154+ }
155+ } ) ;
114156} ) ;
0 commit comments