11import { run } from '../src/main' ;
22import * as core from '@actions/core' ;
3+ // @ts -ignore
4+ import { mockInputs } from './mock-inputs' ;
35
46function mockCurrentVersion ( version : string ) {
57 jest . spyOn ( global , 'fetch' ) . mockResolvedValue ( {
@@ -9,32 +11,6 @@ function mockCurrentVersion(version: string) {
911 ok : true
1012 } as any as Promise < Response > ) ;
1113}
12-
13- function mockInputs (
14- majorVersion : string ,
15- minorVersion : string ,
16- publishBeta : string
17- ) {
18- jest . spyOn ( core , 'getInput' ) . mockImplementation ( ( name : string ) => {
19- if ( name === 'org' ) {
20- return 'org' ;
21- }
22- if ( name === 'packageName' ) {
23- return 'packageName' ;
24- }
25- if ( name === 'minorVersion' ) {
26- return minorVersion ;
27- }
28- if ( name === 'majorVersion' ) {
29- return majorVersion ;
30- }
31- if ( name === 'publishBeta' ) {
32- return publishBeta ;
33- }
34- throw new Error ( `Unexpected input ${ name } ` ) ;
35- } ) ;
36- }
37-
3814afterEach ( ( ) => {
3915 jest . restoreAllMocks ( ) ;
4016} ) ;
@@ -50,13 +26,49 @@ describe('get current version', () => {
5026 process . env = OLD_ENV ; // Restore old environment
5127 } ) ;
5228
53- it ( 'should throw if no token is given' , async ( ) => {
54- process . env = { ...OLD_ENV , ...{ GITHUB_TOKEN : undefined } } ;
55- jest . spyOn ( core , 'setFailed' ) ;
56- await run ( ) ;
57- expect ( core . setFailed ) . toHaveBeenCalledWith (
58- 'GITHUB_TOKEN not set, please set the GITHUB_TOKEN environment variable to secrets.GITHUB_TOKEN'
59- ) ;
29+ describe ( 'inputs should be validated' , ( ) => {
30+ it ( 'should throw if no token is given' , async ( ) => {
31+ process . env = { ...OLD_ENV , ...{ GITHUB_TOKEN : undefined } } ;
32+ jest . spyOn ( core , 'setFailed' ) ;
33+ await run ( ) ;
34+ expect ( core . setFailed ) . toHaveBeenCalledWith (
35+ 'GITHUB_TOKEN not set, please set the GITHUB_TOKEN environment variable to secrets.GITHUB_TOKEN'
36+ ) ;
37+ } ) ;
38+
39+ it ( 'should throw if no org is given' , async ( ) => {
40+ mockInputs ( '1' , '0' , 'false' , '' ) ;
41+ jest . spyOn ( core , 'setFailed' ) ;
42+ await run ( ) ;
43+ expect ( core . setFailed ) . toHaveBeenCalledWith ( 'Input org is not set' ) ;
44+ } ) ;
45+
46+ it ( 'should throw if no package name is given' , async ( ) => {
47+ mockInputs ( '1' , '0' , 'false' , 'org' , '' ) ;
48+ jest . spyOn ( core , 'setFailed' ) ;
49+ await run ( ) ;
50+ expect ( core . setFailed ) . toHaveBeenCalledWith (
51+ 'Input packageName is not set'
52+ ) ;
53+ } ) ;
54+
55+ it ( 'should throw if no major version is given' , async ( ) => {
56+ mockInputs ( '' , '0' , 'false' ) ;
57+ jest . spyOn ( core , 'setFailed' ) ;
58+ await run ( ) ;
59+ expect ( core . setFailed ) . toHaveBeenCalledWith (
60+ 'Input majorVersion is not set'
61+ ) ;
62+ } ) ;
63+
64+ it ( 'should throw if no minor version is given' , async ( ) => {
65+ mockInputs ( '1' , '' , 'false' ) ;
66+ jest . spyOn ( core , 'setFailed' ) ;
67+ await run ( ) ;
68+ expect ( core . setFailed ) . toHaveBeenCalledWith (
69+ 'Input minorVersion is not set'
70+ ) ;
71+ } ) ;
6072 } ) ;
6173
6274 describe ( 'when current version is empty' , ( ) => {
0 commit comments