@@ -26,7 +26,7 @@ let inputHelper: any
26
26
27
27
// Mock @actions /core
28
28
let inputs = { } as any
29
- const mockCore = jest . genMockFromModule ( '@actions/core' ) as any
29
+ const mockCore : any = jest . genMockFromModule ( '@actions/core' )
30
30
mockCore . getInput = ( name : string , options ?: InputOptions ) => {
31
31
const val = inputs [ name ] || ''
32
32
if ( options && options . required && ! val ) {
@@ -36,7 +36,7 @@ mockCore.getInput = (name: string, options?: InputOptions) => {
36
36
}
37
37
38
38
// Mock @actions /github
39
- const mockGitHub = jest . genMockFromModule ( '@actions/github' ) as any
39
+ const mockGitHub : any = jest . genMockFromModule ( '@actions/github' )
40
40
mockGitHub . context = { }
41
41
42
42
describe ( 'input-helper tests' , ( ) => {
@@ -46,7 +46,7 @@ describe('input-helper tests', () => {
46
46
jest . setMock ( '@actions/github' , mockGitHub )
47
47
48
48
// Now import
49
- inputHelper = require ( '../lib /input-helper' )
49
+ inputHelper = require ( '../src /input-helper' )
50
50
} )
51
51
52
52
beforeEach ( ( ) => {
@@ -73,25 +73,6 @@ describe('input-helper tests', () => {
73
73
} ) . toThrow ( 'Input required and not supplied: error' )
74
74
} )
75
75
76
- it ( 'requires event' , ( ) => {
77
- inputs . pattern = 'some-pattern'
78
- inputs . error = 'some-error'
79
- expect ( ( ) => {
80
- const checkerArguments : ICheckerArguments = inputHelper . getInputs ( )
81
- } ) . toThrow ( 'Event "undefined" is not supported.' )
82
- } )
83
-
84
- it ( 'requires valid event' , ( ) => {
85
- mockGitHub . context = {
86
- eventName : 'some-event'
87
- }
88
- inputs . pattern = 'some-pattern'
89
- inputs . error = 'some-error'
90
- expect ( ( ) => {
91
- const checkerArguments : ICheckerArguments = inputHelper . getInputs ( )
92
- } ) . toThrow ( 'Event "some-event" is not supported.' )
93
- } )
94
-
95
76
it ( 'sets flags' , ( ) => {
96
77
mockGitHub . context = {
97
78
eventName : 'pull_request' ,
@@ -109,23 +90,6 @@ describe('input-helper tests', () => {
109
90
expect ( checkerArguments . flags ) . toBe ( 'abcdefgh' )
110
91
} )
111
92
112
- it ( 'requires pull_request payload' , ( ) => {
113
- mockGitHub . context = {
114
- eventName : 'pull_request' ,
115
- payload : {
116
- pull_request : {
117
- title : '' ,
118
- body : ''
119
- }
120
- }
121
- }
122
- inputs . pattern = 'some-pattern'
123
- inputs . error = 'some-error'
124
- expect ( ( ) => {
125
- const checkerArguments : ICheckerArguments = inputHelper . getInputs ( )
126
- } ) . toThrow ( 'No pull_request found in the payload.' )
127
- } )
128
-
129
93
it ( 'sets correct pull_request title payload' , ( ) => {
130
94
mockGitHub . context = {
131
95
eventName : 'pull_request' ,
@@ -142,8 +106,6 @@ describe('input-helper tests', () => {
142
106
expect ( checkerArguments ) . toBeTruthy ( )
143
107
expect ( checkerArguments . pattern ) . toBe ( 'some-pattern' )
144
108
expect ( checkerArguments . error ) . toBe ( 'some-error' )
145
- expect ( checkerArguments . messages ) . toBeTruthy ( )
146
- expect ( checkerArguments . messages [ 0 ] ) . toBe ( 'some-title' )
147
109
} )
148
110
149
111
it ( 'sets correct pull_request title and body payload' , ( ) => {
@@ -162,34 +124,6 @@ describe('input-helper tests', () => {
162
124
expect ( checkerArguments ) . toBeTruthy ( )
163
125
expect ( checkerArguments . pattern ) . toBe ( 'some-pattern' )
164
126
expect ( checkerArguments . error ) . toBe ( 'some-error' )
165
- expect ( checkerArguments . messages ) . toBeTruthy ( )
166
- expect ( checkerArguments . messages [ 0 ] ) . toBe ( 'some-title\n\nsome-body' )
167
- } )
168
-
169
- it ( 'requires push payload' , ( ) => {
170
- mockGitHub . context = {
171
- eventName : 'push' ,
172
- payload : { }
173
- }
174
- inputs . pattern = 'some-pattern'
175
- inputs . error = 'some-error'
176
- expect ( ( ) => {
177
- const checkerArguments : ICheckerArguments = inputHelper . getInputs ( )
178
- } ) . toThrow ( 'No commits found in the payload.' )
179
- } )
180
-
181
- it ( 'requires push payload commits' , ( ) => {
182
- mockGitHub . context = {
183
- eventName : 'push' ,
184
- payload : {
185
- commits : { }
186
- }
187
- }
188
- inputs . pattern = 'some-pattern'
189
- inputs . error = 'some-error'
190
- expect ( ( ) => {
191
- const checkerArguments : ICheckerArguments = inputHelper . getInputs ( )
192
- } ) . toThrow ( 'No commits found in the payload.' )
193
127
} )
194
128
195
129
it ( 'sets correct single push payload' , ( ) => {
@@ -209,8 +143,6 @@ describe('input-helper tests', () => {
209
143
expect ( checkerArguments ) . toBeTruthy ( )
210
144
expect ( checkerArguments . pattern ) . toBe ( 'some-pattern' )
211
145
expect ( checkerArguments . error ) . toBe ( 'some-error' )
212
- expect ( checkerArguments . messages ) . toBeTruthy ( )
213
- expect ( checkerArguments . messages [ 0 ] ) . toBe ( 'some-message' )
214
146
} )
215
147
216
148
it ( 'sets correct multiple push payload' , ( ) => {
@@ -233,8 +165,76 @@ describe('input-helper tests', () => {
233
165
expect ( checkerArguments ) . toBeTruthy ( )
234
166
expect ( checkerArguments . pattern ) . toBe ( 'some-pattern' )
235
167
expect ( checkerArguments . error ) . toBe ( 'some-error' )
236
- expect ( checkerArguments . messages ) . toBeTruthy ( )
237
- expect ( checkerArguments . messages [ 0 ] ) . toBe ( 'some-message' )
238
- expect ( checkerArguments . messages [ 1 ] ) . toBe ( 'other-message' )
168
+ } )
169
+
170
+ it ( 'requires pattern' , async ( ) => {
171
+ const checkerArguments : ICheckerArguments = {
172
+ pattern : '' ,
173
+ flags : '' ,
174
+ error : ''
175
+ }
176
+
177
+ expect ( ( ) => {
178
+ inputHelper . checkArgs ( checkerArguments )
179
+ } ) . toThrow ( 'PATTERN not defined.' )
180
+ } )
181
+
182
+ it ( 'requires valid flags' , async ( ) => {
183
+ const checkerArguments : ICheckerArguments = {
184
+ pattern : 'some-pattern' ,
185
+ flags : 'abcdefgh' ,
186
+ error : ''
187
+ }
188
+ expect ( ( ) => {
189
+ inputHelper . checkArgs ( checkerArguments )
190
+ } ) . toThrow ( 'FLAGS contains invalid characters "abcdefh".' )
191
+ } )
192
+
193
+ it ( 'requires valid error message' , async ( ) => {
194
+ const checkerArguments : ICheckerArguments = {
195
+ pattern : 'some-pattern' ,
196
+ flags : 'g' ,
197
+ error : ''
198
+ }
199
+ expect ( ( ) => {
200
+ inputHelper . checkArgs ( checkerArguments )
201
+ } ) . toThrow ( 'ERROR not defined.' )
202
+ } )
203
+
204
+ it ( 'should throw error message on genOutput' , async ( ) => {
205
+ expect ( ( ) => {
206
+ inputHelper . genOutput ( )
207
+ } ) . toThrow ( "Cannot read properties of undefined (reading 'map')" )
208
+ } )
209
+
210
+ it ( 'should return error message on genOutput' , async ( ) => {
211
+ const attributes = {
212
+ commitInfos : [
213
+ {
214
+ sha : 'aaaaaaa1111' ,
215
+ message : 'message1'
216
+ } ,
217
+ {
218
+ sha : 'bbbbbbb2222' ,
219
+ message : 'message2'
220
+ }
221
+ ] ,
222
+ preErrorMsg : 'i am a preErrorMessage' ,
223
+ postErrorMSG : 'i am a posterrormessage'
224
+ }
225
+ const expected : any = inputHelper . genOutput (
226
+ attributes . commitInfos ,
227
+ attributes . preErrorMsg ,
228
+ attributes . postErrorMSG
229
+ )
230
+
231
+ expect ( expected ) . toMatchInlineSnapshot ( `
232
+ "i am a preErrorMessage
233
+
234
+ aaaaaaa1111 message1
235
+ bbbbbbb2222 message2
236
+
237
+ i am a posterrormessage"
238
+ ` )
239
239
} )
240
240
} )
0 commit comments