1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ // @ts -nocheck
1
3
import * as action from '../src/action'
2
4
import * as core from '@actions/core'
3
5
import * as github from '@actions/github'
@@ -6,6 +8,19 @@ jest.mock('@actions/core')
6
8
jest . mock ( '@actions/github' )
7
9
8
10
describe ( 'Input validation' , function ( ) {
11
+ const eventName = 'pull_request'
12
+ const payload = {
13
+ pull_request : {
14
+ number : '45' ,
15
+ base : {
16
+ sha : 'guasft7asdtf78asfd87as6df7y2u3' ,
17
+ } ,
18
+ head : {
19
+ sha : 'aahsdflais76dfa78wrglghjkaghkj' ,
20
+ } ,
21
+ } ,
22
+ }
23
+
9
24
function getInput ( key : string ) : string | undefined {
10
25
switch ( key ) {
11
26
case 'paths' :
@@ -19,47 +34,44 @@ describe('Input validation', function () {
19
34
const listComments = jest . fn ( )
20
35
const updateComment = jest . fn ( )
21
36
22
- /* eslint-disable @typescript-eslint/ban-ts-comment */
23
- // @ts -ignore
24
37
core . getInput = jest . fn ( getInput )
25
- // @ts -ignore
26
38
github . getOctokit = jest . fn ( ( ) => {
27
39
return {
28
- repos : {
29
- compareCommits : jest . fn ( ( ) => {
30
- return {
31
- data : {
32
- files : [
33
- {
34
- filename : 'src/main/kotlin/com/madrapps/jacoco/Math.kt' ,
35
- blob_url :
36
- 'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt' ,
37
- } ,
38
- {
39
- filename :
40
- 'src/main/java/com/madrapps/jacoco/operation/StringOp.java' ,
41
- blob_url :
42
- 'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java' ,
43
- } ,
44
- ] ,
45
- } ,
46
- }
47
- } ) ,
48
- } ,
49
- issues : {
50
- createComment,
51
- listComments,
52
- updateComment,
40
+ rest : {
41
+ repos : {
42
+ compareCommits : jest . fn ( ( ) => {
43
+ return {
44
+ data : {
45
+ files : [
46
+ {
47
+ filename : 'src/main/kotlin/com/madrapps/jacoco/Math.kt' ,
48
+ blob_url :
49
+ 'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/kotlin/com/madrapps/jacoco/Math.kt' ,
50
+ } ,
51
+ {
52
+ filename :
53
+ 'src/main/java/com/madrapps/jacoco/operation/StringOp.java' ,
54
+ blob_url :
55
+ 'https://github.com/thsaravana/jacoco-playground/blob/77b14eb61efcd211ee93a7d8bac80cf292d207cc/src/main/java/com/madrapps/jacoco/operation/StringOp.java' ,
56
+ } ,
57
+ ] ,
58
+ } ,
59
+ }
60
+ } ) ,
61
+ } ,
62
+ issues : {
63
+ createComment,
64
+ listComments,
65
+ updateComment,
66
+ } ,
53
67
} ,
54
68
}
55
69
} )
56
- // @ts -ignore
57
70
core . setFailed = jest . fn ( c => {
58
71
fail ( c )
59
72
} )
60
73
61
74
it ( 'Fail if paths is not present' , async ( ) => {
62
- // @ts -ignore
63
75
core . getInput = jest . fn ( c => {
64
76
switch ( c ) {
65
77
case 'paths' :
@@ -70,15 +82,13 @@ describe('Input validation', function () {
70
82
} )
71
83
github . context . eventName = 'pull_request'
72
84
73
- // @ts -ignore
74
85
core . setFailed = jest . fn ( c => {
75
86
expect ( c ) . toEqual ( "'paths' is missing" )
76
87
} )
77
88
await action . action ( )
78
89
} )
79
90
80
91
it ( 'Fail if token is not present' , async ( ) => {
81
- // @ts -ignore
82
92
core . getInput = jest . fn ( c => {
83
93
switch ( c ) {
84
94
case 'token' :
@@ -88,10 +98,34 @@ describe('Input validation', function () {
88
98
}
89
99
} )
90
100
github . context . eventName = 'pull_request'
91
- // @ts -ignore
92
101
core . setFailed = jest . fn ( c => {
93
102
expect ( c ) . toEqual ( "'token' is missing" )
94
103
} )
95
104
await action . action ( )
96
105
} )
106
+
107
+ it ( 'Fail if comment-type is invalid' , async ( ) => {
108
+ core . getInput = jest . fn ( c => {
109
+ switch ( c ) {
110
+ case 'comment-type' :
111
+ return 'invalid'
112
+ default :
113
+ return getInput ( c )
114
+ }
115
+ } )
116
+ core . setFailed = jest . fn ( c => {
117
+ expect ( c ) . toEqual ( "'comment-type' invalid is invalid" )
118
+ } )
119
+ initContext ( eventName , payload )
120
+
121
+ await action . action ( )
122
+ } )
97
123
} )
124
+
125
+ function initContext ( eventName , payload ) : void {
126
+ const context = github . context
127
+ context . eventName = eventName
128
+ context . payload = payload
129
+ context . repo = 'jacoco-playground'
130
+ context . owner = 'madrapps'
131
+ }
0 commit comments