@@ -33,20 +33,29 @@ describe("logName", () => {
33
33
34
34
describe ( "githubInputs" , ( ) => {
35
35
const OLD_ENV = { ...process . env } ;
36
+ const { context : OLD_CONTEXT } = require ( "@actions/github" ) ;
37
+ const { payload : OLD_PAYLOAD , eventName : OLD_EVENT_NAME } = OLD_CONTEXT ;
36
38
afterEach ( ( ) => {
37
39
process . env = { ...OLD_ENV } ;
40
+ const { context } = require ( "@actions/github" ) ;
41
+ context . eventName = OLD_EVENT_NAME ;
42
+ context . payload = OLD_PAYLOAD ;
38
43
} ) ;
39
44
40
45
const projectName = "project_name" ;
41
46
const repoInfo = "owner/repo" ;
42
47
const sha = "1234abcd-12ab-34cd-56ef-1234567890ab" ;
48
+ const pullRequestSha = "181600acb3cfb803f4570d0018928be5d730c00d" ;
43
49
44
50
it ( "build basic parameters for codeBuild.startBuild" , ( ) => {
45
51
// This is how GITHUB injects its input values.
46
52
// It would be nice if there was an easy way to test this...
47
53
process . env [ `INPUT_PROJECT-NAME` ] = projectName ;
48
54
process . env [ `GITHUB_REPOSITORY` ] = repoInfo ;
49
55
process . env [ `GITHUB_SHA` ] = sha ;
56
+ // These tests run in pull requests
57
+ // so to tests things that are NOT pull request...
58
+ process . env [ `GITHUB_EVENT_NAME` ] = "not_pull_request" ;
50
59
const test = githubInputs ( ) ;
51
60
expect ( test ) . to . haveOwnProperty ( "projectName" ) . and . to . equal ( projectName ) ;
52
61
expect ( test ) . to . haveOwnProperty ( "sourceVersion" ) . and . to . equal ( sha ) ;
@@ -84,6 +93,44 @@ describe("githubInputs", () => {
84
93
. to . haveOwnProperty ( "envPassthrough" )
85
94
. and . to . deep . equal ( [ "one" , "two" , "three" , "four" ] ) ;
86
95
} ) ;
96
+
97
+ it ( "can handle pull requests" , ( ) => {
98
+ // This is how GITHUB injects its input values.
99
+ // It would be nice if there was an easy way to test this...
100
+ process . env [ `INPUT_PROJECT-NAME` ] = projectName ;
101
+ process . env [ `GITHUB_REPOSITORY` ] = repoInfo ;
102
+ process . env [ `GITHUB_SHA` ] = sha ;
103
+ process . env [ `GITHUB_EVENT_NAME` ] = "pull_request" ;
104
+ const { context } = require ( "@actions/github" ) ;
105
+ context . payload = { pull_request : { head : { sha : pullRequestSha } } } ;
106
+ const test = githubInputs ( ) ;
107
+ expect ( test ) . to . haveOwnProperty ( "projectName" ) . and . to . equal ( projectName ) ;
108
+ expect ( test )
109
+ . to . haveOwnProperty ( "sourceVersion" )
110
+ . and . to . equal ( pullRequestSha ) ;
111
+ expect ( test ) . to . haveOwnProperty ( "owner" ) . and . to . equal ( `owner` ) ;
112
+ expect ( test ) . to . haveOwnProperty ( "repo" ) . and . to . equal ( `repo` ) ;
113
+ expect ( test )
114
+ . to . haveOwnProperty ( "buildspecOverride" )
115
+ . and . to . equal ( undefined ) ;
116
+ expect ( test ) . to . haveOwnProperty ( "envPassthrough" ) . and . to . deep . equal ( [ ] ) ;
117
+ } ) ;
118
+
119
+ it ( "will not continue if there is no payload" , ( ) => {
120
+ // This is how GITHUB injects its input values.
121
+ // It would be nice if there was an easy way to test this...
122
+ process . env [ `INPUT_PROJECT-NAME` ] = projectName ;
123
+ process . env [ `GITHUB_REPOSITORY` ] = repoInfo ;
124
+ process . env [ `GITHUB_SHA` ] = sha ;
125
+ process . env [ `GITHUB_EVENT_NAME` ] = "pull_request" ;
126
+ // These tests run in pull requests
127
+ // so to tests things that are NOT pull request...
128
+ require ( "@actions/github" ) . context . payload = { } ;
129
+
130
+ expect ( ( ) => githubInputs ( ) ) . to . throw (
131
+ "No source version could be evaluated."
132
+ ) ;
133
+ } ) ;
87
134
} ) ;
88
135
89
136
describe ( "inputs2Parameters" , ( ) => {
0 commit comments