@@ -5,6 +5,19 @@ const core = require('@actions/core')
55const sinon = require ( 'sinon' )
66const { factory, GitHubRelease } = require ( 'release-please/build/src' )
77const { Node } = require ( 'release-please/build/src/releasers/node' )
8+ // As defined in action.yml
9+ const defaultInput = {
10+ fork : 'false' ,
11+ clean : 'true' ,
12+ 'bump-minor-pre-major' : 'false' ,
13+ path : '' ,
14+ 'monorepo-tags' : 'false' ,
15+ 'changelog-path' : '' ,
16+ 'changelog-types' : '' ,
17+ command : '' ,
18+ 'version-file' : '' ,
19+ 'default-branch' : ''
20+ }
821
922const sandbox = sinon . createSandbox ( )
1023process . env . GITHUB_REPOSITORY = 'google/cloud'
@@ -14,6 +27,47 @@ describe('release-please-action', () => {
1427 sandbox . restore ( )
1528 } )
1629
30+ const trueValue = [ 'true' , 'True' , 'TRUE' , 'yes' , 'Yes' , 'YES' , 'y' , 'Y' , 'on' , 'On' , 'ON' ]
31+ const falseValue = [ 'false' , 'False' , 'FALSE' , 'no' , 'No' , 'NO' , 'n' , 'N' , 'off' , 'Off' , 'OFF' ]
32+
33+ trueValue . forEach ( value => {
34+ it ( `get the boolean true with the input of '${ value } '` , ( ) => {
35+ const input = {
36+ fork : value
37+ }
38+ core . getInput = ( name ) => {
39+ return input [ name ] || defaultInput [ name ]
40+ }
41+ const actual = action . getBooleanInput ( 'fork' )
42+ assert . strictEqual ( actual , true )
43+ } )
44+ } )
45+
46+ falseValue . forEach ( value => {
47+ it ( `get the boolean with the input of '${ value } '` , ( ) => {
48+ const input = {
49+ fork : value
50+ }
51+ core . getInput = ( name ) => {
52+ return input [ name ] || defaultInput [ name ]
53+ }
54+ const actual = action . getBooleanInput ( 'fork' )
55+ assert . strictEqual ( actual , false )
56+ } )
57+ } )
58+
59+ it ( 'get an error when inputting the wrong boolean value' , ( ) => {
60+ const input = {
61+ fork : 'wrong'
62+ }
63+ core . getInput = ( name ) => {
64+ return input [ name ] || defaultInput [ name ]
65+ }
66+ assert . throws ( ( ) => {
67+ action . getBooleanInput ( 'fork' )
68+ } , { name : 'TypeError' , message : 'Wrong boolean value of the input \'fork\'' } )
69+ } )
70+
1771 it ( 'both opens PR to the default branch and tags GitHub releases by default' , async ( ) => {
1872 const output = { }
1973 core . setOutput = ( name , value ) => {
@@ -23,7 +77,7 @@ describe('release-please-action', () => {
2377 'release-type' : 'node'
2478 }
2579 core . getInput = ( name ) => {
26- return input [ name ]
80+ return input [ name ] || defaultInput [ name ]
2781 }
2882
2983 const runCommandStub = sandbox . stub ( factory , 'runCommand' )
@@ -61,7 +115,7 @@ describe('release-please-action', () => {
61115 'default-branch' : 'dev'
62116 }
63117 core . getInput = ( name ) => {
64- return input [ name ]
118+ return input [ name ] || defaultInput [ name ]
65119 }
66120
67121 const runCommandStub = sandbox . stub ( factory , 'runCommand' )
@@ -100,7 +154,7 @@ describe('release-please-action', () => {
100154 command : 'release-pr'
101155 }
102156 core . getInput = ( name ) => {
103- return input [ name ]
157+ return input [ name ] || defaultInput [ name ]
104158 }
105159
106160 const runCommandStub = sandbox . stub ( factory , 'runCommand' )
@@ -129,7 +183,7 @@ describe('release-please-action', () => {
129183 command : 'github-release'
130184 }
131185 core . getInput = ( name ) => {
132- return input [ name ]
186+ return input [ name ] || defaultInput [ name ]
133187 }
134188
135189 const runCommandStub = sandbox . stub ( factory , 'runCommand' )
@@ -170,7 +224,7 @@ describe('release-please-action', () => {
170224 command : 'github-release'
171225 }
172226 core . getInput = ( name ) => {
173- return input [ name ]
227+ return input [ name ] || defaultInput [ name ]
174228 }
175229
176230 const runCommandStub = sandbox . stub ( factory , 'runCommand' )
@@ -195,7 +249,7 @@ describe('release-please-action', () => {
195249 command : 'release-pr'
196250 }
197251 core . getInput = ( name ) => {
198- return input [ name ]
252+ return input [ name ] || defaultInput [ name ]
199253 }
200254
201255 const runCommandStub = sandbox . stub ( factory , 'runCommand' )
@@ -217,7 +271,7 @@ describe('release-please-action', () => {
217271 command : 'release-pr'
218272 }
219273 core . getInput = ( name ) => {
220- return input [ name ]
274+ return input [ name ] || defaultInput [ name ]
221275 }
222276
223277 const runCommandStub = sandbox . stub ( factory , 'runCommand' )
@@ -239,7 +293,7 @@ describe('release-please-action', () => {
239293 command : 'release-pr'
240294 }
241295 core . getInput = ( name ) => {
242- return input [ name ]
296+ return input [ name ] || defaultInput [ name ]
243297 }
244298 await action . main ( )
245299 assert . ok ( maybeReleasePR instanceof Node )
@@ -255,7 +309,7 @@ describe('release-please-action', () => {
255309 command : 'github-release'
256310 }
257311 core . getInput = ( name ) => {
258- return input [ name ]
312+ return input [ name ] || defaultInput [ name ]
259313 }
260314 await action . main ( )
261315 assert . ok ( maybeGitHubRelease instanceof GitHubRelease )
0 commit comments