@@ -36,6 +36,9 @@ describe('index', function () {
3636 beforeEach ( ( ) => {
3737 githubMock = {
3838 authenticate : sinon . stub ( ) ,
39+ pullRequests : {
40+ getAll : sinon . stub ( )
41+ } ,
3942 repos : {
4043 createHook : sinon . stub ( ) ,
4144 createStatus : sinon . stub ( ) ,
@@ -1319,4 +1322,67 @@ jobs:
13191322 } ) ;
13201323 } ) ;
13211324 } ) ;
1325+
1326+ describe ( '_getOpenedPRs' , ( ) => {
1327+ const scmUri = 'github.com:111:branchName' ;
1328+ const config = {
1329+ scmUri,
1330+ token : 'token'
1331+ } ;
1332+
1333+ beforeEach ( ( ) => {
1334+ githubMock . repos . getById . yieldsAsync ( null , {
1335+ full_name : 'repoOwner/repoName'
1336+ } ) ;
1337+ } ) ;
1338+
1339+ it ( 'returns a list of opened pull requests' , ( ) => {
1340+ githubMock . pullRequests . getAll . yieldsAsync ( null , [
1341+ { number : 1 } ,
1342+ { number : 2 }
1343+ ] ) ;
1344+
1345+ return scm . _getOpenedPRs ( config ) . then ( ( data ) => {
1346+ assert . deepEqual ( data , [
1347+ {
1348+ name : 'PR-1' ,
1349+ ref : 'pull/1/merge'
1350+ } ,
1351+ {
1352+ name : 'PR-2' ,
1353+ ref : 'pull/2/merge'
1354+ }
1355+ ] ) ;
1356+
1357+ assert . calledWith ( githubMock . repos . getById , { id : '111' } ) ;
1358+ assert . calledWith ( githubMock . pullRequests . getAll , {
1359+ owner : 'repoOwner' ,
1360+ repo : 'repoName' ,
1361+ state : 'open'
1362+ } ) ;
1363+ } ) ;
1364+ } ) ;
1365+
1366+ it ( 'rejects when failing to lookup the SCM URI information' , ( ) => {
1367+ const testError = new Error ( 'testError' ) ;
1368+
1369+ githubMock . repos . getById . yieldsAsync ( testError ) ;
1370+
1371+ return scm . _getOpenedPRs ( config ) . then ( assert . fail , ( err ) => {
1372+ assert . instanceOf ( err , Error ) ;
1373+ assert . strictEqual ( testError . message , err . message ) ;
1374+ } ) ;
1375+ } ) ;
1376+
1377+ it ( 'rejects when failing to fetch opened pull requests' , ( ) => {
1378+ const testError = new Error ( 'testError' ) ;
1379+
1380+ githubMock . pullRequests . getAll . yieldsAsync ( testError ) ;
1381+
1382+ return scm . _getOpenedPRs ( config ) . then ( assert . fail , ( err ) => {
1383+ assert . instanceOf ( err , Error ) ;
1384+ assert . strictEqual ( testError . message , err . message ) ;
1385+ } ) ;
1386+ } ) ;
1387+ } ) ;
13221388} ) ;
0 commit comments