1
- import { isAdmin } from '../../src/functions/admin'
2
- import { COLORS } from '../../src/functions/colors'
1
+ import { isAdmin } from '../../src/functions/admin.js'
2
+ import { vi , expect , test , beforeEach } from 'vitest'
3
+ import { COLORS } from '../../src/functions/colors.js'
3
4
import * as github from '@actions/github'
4
5
import * as core from '@actions/core'
5
6
6
- const debugMock = jest . spyOn ( core , 'debug' ) . mockImplementation ( ( ) => { } )
7
- const warningMock = jest . spyOn ( core , 'warning' ) . mockImplementation ( ( ) => { } )
8
- // const infoMock = jest.spyOn(core, 'info').mockImplementation(() => {})
7
+ const debugMock = vi . spyOn ( core , 'debug' )
8
+ const warningMock = vi . spyOn ( core , 'warning' )
9
9
10
10
class NotFoundError extends Error {
11
11
constructor ( message ) {
@@ -24,8 +24,7 @@ class WildError extends Error {
24
24
var context
25
25
var octokit
26
26
beforeEach ( ( ) => {
27
- jest . clearAllMocks ( )
28
- jest . spyOn ( core , 'info' ) . mockImplementation ( ( ) => { } )
27
+ vi . clearAllMocks ( )
29
28
process . env . INPUT_ADMINS_PAT = 'faketoken'
30
29
process . env . INPUT_ADMINS =
31
30
'MoNaLiSa,@lisamona,octoawesome/octo-awEsome-team,bad$user'
@@ -35,24 +34,24 @@ beforeEach(() => {
35
34
}
36
35
37
36
octokit = {
38
- request : jest . fn ( ) . mockReturnValueOnce ( {
37
+ request : vi . fn ( ) . mockReturnValueOnce ( {
39
38
status : 204
40
39
} ) ,
41
40
rest : {
42
41
orgs : {
43
- get : jest . fn ( ) . mockReturnValueOnce ( {
42
+ get : vi . fn ( ) . mockReturnValueOnce ( {
44
43
data : { id : '12345' }
45
44
} )
46
45
} ,
47
46
teams : {
48
- getByName : jest . fn ( ) . mockReturnValueOnce ( {
47
+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
49
48
data : { id : '567890' }
50
49
} )
51
50
}
52
51
}
53
52
}
54
53
55
- jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
54
+ vi . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
56
55
return octokit
57
56
} )
58
57
} )
@@ -117,11 +116,11 @@ test('runs isAdmin checks for an org team and finds a valid user', async () => {
117
116
118
117
// This only handles the global failure case of any 404 in the admin.js file
119
118
test ( 'runs isAdmin checks for an org team and does not find the org' , async ( ) => {
120
- jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
119
+ vi . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
121
120
return {
122
121
rest : {
123
122
orgs : {
124
- get : jest
123
+ get : vi
125
124
. fn ( )
126
125
. mockRejectedValueOnce (
127
126
new NotFoundError ( 'Reference does not exist' )
@@ -139,16 +138,16 @@ test('runs isAdmin checks for an org team and does not find the org', async () =
139
138
140
139
// This only handles the global failure case of any 404 in the admin.js file
141
140
test ( 'runs isAdmin checks for an org team and does not find the team' , async ( ) => {
142
- jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
141
+ vi . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
143
142
return {
144
143
rest : {
145
144
orgs : {
146
- get : jest . fn ( ) . mockReturnValueOnce ( {
145
+ get : vi . fn ( ) . mockReturnValueOnce ( {
147
146
data : { id : '12345' }
148
147
} )
149
148
} ,
150
149
teams : {
151
- getByName : jest
150
+ getByName : vi
152
151
. fn ( )
153
152
. mockRejectedValueOnce (
154
153
new NotFoundError ( 'Reference does not exist' )
@@ -166,19 +165,19 @@ test('runs isAdmin checks for an org team and does not find the team', async ()
166
165
167
166
// This test correctly tests if a user is a member of a team or not. If they are in a team a 204 is returned. If they are not a 404 is returned like in this test example
168
167
test ( 'runs isAdmin checks for an org team and does not find the user in the team' , async ( ) => {
169
- jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
168
+ vi . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
170
169
return {
171
- request : jest
170
+ request : vi
172
171
. fn ( )
173
172
. mockRejectedValueOnce ( new NotFoundError ( 'Reference does not exist' ) ) ,
174
173
rest : {
175
174
orgs : {
176
- get : jest . fn ( ) . mockReturnValueOnce ( {
175
+ get : vi . fn ( ) . mockReturnValueOnce ( {
177
176
data : { id : '12345' }
178
177
} )
179
178
} ,
180
179
teams : {
181
- getByName : jest . fn ( ) . mockReturnValueOnce ( {
180
+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
182
181
data : { id : '567890' }
183
182
} )
184
183
}
@@ -193,19 +192,19 @@ test('runs isAdmin checks for an org team and does not find the user in the team
193
192
} )
194
193
195
194
test ( 'runs isAdmin checks for an org team and an unexpected status code is received from the request method with octokit' , async ( ) => {
196
- jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
195
+ vi . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
197
196
return {
198
- request : jest . fn ( ) . mockReturnValueOnce ( {
197
+ request : vi . fn ( ) . mockReturnValueOnce ( {
199
198
status : 500
200
199
} ) ,
201
200
rest : {
202
201
orgs : {
203
- get : jest . fn ( ) . mockReturnValueOnce ( {
202
+ get : vi . fn ( ) . mockReturnValueOnce ( {
204
203
data : { id : '12345' }
205
204
} )
206
205
} ,
207
206
teams : {
208
- getByName : jest . fn ( ) . mockReturnValueOnce ( {
207
+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
209
208
data : { id : '567890' }
210
209
} )
211
210
}
@@ -221,19 +220,19 @@ test('runs isAdmin checks for an org team and an unexpected status code is recei
221
220
} )
222
221
223
222
test ( 'runs isAdmin checks for an org team and an unexpected error is thrown from any API call' , async ( ) => {
224
- jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
223
+ vi . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
225
224
return {
226
- request : jest
225
+ request : vi
227
226
. fn ( )
228
227
. mockRejectedValueOnce ( new WildError ( 'something went boom' ) ) ,
229
228
rest : {
230
229
orgs : {
231
- get : jest . fn ( ) . mockReturnValueOnce ( {
230
+ get : vi . fn ( ) . mockReturnValueOnce ( {
232
231
data : { id : '12345' }
233
232
} )
234
233
} ,
235
234
teams : {
236
- getByName : jest . fn ( ) . mockReturnValueOnce ( {
235
+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
237
236
data : { id : '567890' }
238
237
} )
239
238
}
0 commit comments