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'
34import * as github from '@actions/github'
45import * as core from '@actions/core'
56
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' )
99
1010class NotFoundError extends Error {
1111 constructor ( message ) {
@@ -24,8 +24,7 @@ class WildError extends Error {
2424var context
2525var octokit
2626beforeEach ( ( ) => {
27- jest . clearAllMocks ( )
28- jest . spyOn ( core , 'info' ) . mockImplementation ( ( ) => { } )
27+ vi . clearAllMocks ( )
2928 process . env . INPUT_ADMINS_PAT = 'faketoken'
3029 process . env . INPUT_ADMINS =
3130 'MoNaLiSa,@lisamona,octoawesome/octo-awEsome-team,bad$user'
@@ -35,24 +34,24 @@ beforeEach(() => {
3534 }
3635
3736 octokit = {
38- request : jest . fn ( ) . mockReturnValueOnce ( {
37+ request : vi . fn ( ) . mockReturnValueOnce ( {
3938 status : 204
4039 } ) ,
4140 rest : {
4241 orgs : {
43- get : jest . fn ( ) . mockReturnValueOnce ( {
42+ get : vi . fn ( ) . mockReturnValueOnce ( {
4443 data : { id : '12345' }
4544 } )
4645 } ,
4746 teams : {
48- getByName : jest . fn ( ) . mockReturnValueOnce ( {
47+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
4948 data : { id : '567890' }
5049 } )
5150 }
5251 }
5352 }
5453
55- jest . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
54+ vi . spyOn ( github , 'getOctokit' ) . mockImplementation ( ( ) => {
5655 return octokit
5756 } )
5857} )
@@ -117,11 +116,11 @@ test('runs isAdmin checks for an org team and finds a valid user', async () => {
117116
118117// This only handles the global failure case of any 404 in the admin.js file
119118test ( '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 ( ( ) => {
121120 return {
122121 rest : {
123122 orgs : {
124- get : jest
123+ get : vi
125124 . fn ( )
126125 . mockRejectedValueOnce (
127126 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 () =
139138
140139// This only handles the global failure case of any 404 in the admin.js file
141140test ( '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 ( ( ) => {
143142 return {
144143 rest : {
145144 orgs : {
146- get : jest . fn ( ) . mockReturnValueOnce ( {
145+ get : vi . fn ( ) . mockReturnValueOnce ( {
147146 data : { id : '12345' }
148147 } )
149148 } ,
150149 teams : {
151- getByName : jest
150+ getByName : vi
152151 . fn ( )
153152 . mockRejectedValueOnce (
154153 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 ()
166165
167166// 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
168167test ( '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 ( ( ) => {
170169 return {
171- request : jest
170+ request : vi
172171 . fn ( )
173172 . mockRejectedValueOnce ( new NotFoundError ( 'Reference does not exist' ) ) ,
174173 rest : {
175174 orgs : {
176- get : jest . fn ( ) . mockReturnValueOnce ( {
175+ get : vi . fn ( ) . mockReturnValueOnce ( {
177176 data : { id : '12345' }
178177 } )
179178 } ,
180179 teams : {
181- getByName : jest . fn ( ) . mockReturnValueOnce ( {
180+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
182181 data : { id : '567890' }
183182 } )
184183 }
@@ -193,19 +192,19 @@ test('runs isAdmin checks for an org team and does not find the user in the team
193192} )
194193
195194test ( '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 ( ( ) => {
197196 return {
198- request : jest . fn ( ) . mockReturnValueOnce ( {
197+ request : vi . fn ( ) . mockReturnValueOnce ( {
199198 status : 500
200199 } ) ,
201200 rest : {
202201 orgs : {
203- get : jest . fn ( ) . mockReturnValueOnce ( {
202+ get : vi . fn ( ) . mockReturnValueOnce ( {
204203 data : { id : '12345' }
205204 } )
206205 } ,
207206 teams : {
208- getByName : jest . fn ( ) . mockReturnValueOnce ( {
207+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
209208 data : { id : '567890' }
210209 } )
211210 }
@@ -221,19 +220,19 @@ test('runs isAdmin checks for an org team and an unexpected status code is recei
221220} )
222221
223222test ( '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 ( ( ) => {
225224 return {
226- request : jest
225+ request : vi
227226 . fn ( )
228227 . mockRejectedValueOnce ( new WildError ( 'something went boom' ) ) ,
229228 rest : {
230229 orgs : {
231- get : jest . fn ( ) . mockReturnValueOnce ( {
230+ get : vi . fn ( ) . mockReturnValueOnce ( {
232231 data : { id : '12345' }
233232 } )
234233 } ,
235234 teams : {
236- getByName : jest . fn ( ) . mockReturnValueOnce ( {
235+ getByName : vi . fn ( ) . mockReturnValueOnce ( {
237236 data : { id : '567890' }
238237 } )
239238 }
0 commit comments