@@ -27,6 +27,9 @@ const issues_complete: jest.SpiedFunction<
2727const issues_generateMessage : jest . SpiedFunction <
2828 typeof import ( '../src/github/issues.js' ) . generateMessage
2929> = jest . fn ( )
30+ const issues_parse : jest . SpiedFunction <
31+ typeof import ( '../src/github/issues.js' ) . parse
32+ > = jest . fn ( )
3033const repos_exists : jest . SpiedFunction <
3134 typeof import ( '../src/github/repos.js' ) . exists
3235> = jest . fn ( )
@@ -68,7 +71,8 @@ jest.unstable_mockModule('../src/github/issues.js', () => {
6871 return {
6972 addLabels : issues_addLabels ,
7073 complete : issues_complete ,
71- generateMessage : issues_generateMessage
74+ generateMessage : issues_generateMessage ,
75+ parse : issues_parse
7276 }
7377} )
7478jest . unstable_mockModule ( '../src/github/repos.js' , ( ) => {
@@ -238,9 +242,7 @@ describe('actions', () => {
238242 }
239243 ]
240244 } ,
241- {
242- issue : { state : 'open' , number : 1 }
243- } as any
245+ { state : 'open' , number : 1 } as any
244246 )
245247
246248 expect ( repos_deleteRepositories ) . toHaveBeenCalled ( )
@@ -269,9 +271,7 @@ describe('actions', () => {
269271 }
270272 ]
271273 } ,
272- {
273- issue : { state : 'closed' , number : 1 }
274- } as any
274+ { state : 'closed' , number : 1 } as any
275275 )
276276
277277 expect ( repos_deleteRepositories ) . toHaveBeenCalled ( )
@@ -282,6 +282,42 @@ describe('actions', () => {
282282 } )
283283 } )
284284
285+ describe ( 'expire()' , ( ) => {
286+ it ( 'Expires an Open Class' , async ( ) => {
287+ mocktokit . paginate . mockResolvedValue ( [
288+ {
289+ state : 'open' ,
290+ number : 1
291+ }
292+ ] )
293+ issues_parse . mockReturnValue ( {
294+ action : AllowedIssueAction . CREATE ,
295+ customerName : 'Nick Testing Industries' ,
296+ customerAbbr : 'NA1' ,
297+ startDate : new Date ( 2023 , 10 , 17 ) ,
298+ endDate : new Date ( 2023 , 10 , 20 ) ,
299+ administrators : [
300+ {
301+ handle : 'ncalteen' ,
302+ email : 'ncalteen@github.com'
303+ }
304+ ] ,
305+ attendees : [
306+ {
307+ handle : 'ncalteen-testuser' ,
308+ email : 'ncalteen+testing@github.com'
309+ }
310+ ]
311+ } )
312+
313+ await actions . expire ( )
314+
315+ expect ( repos_deleteRepositories ) . toHaveBeenCalled ( )
316+ expect ( users_removeUsers ) . toHaveBeenCalled ( )
317+ expect ( teams_deleteTeam ) . toHaveBeenCalled ( )
318+ } )
319+ } )
320+
285321 describe ( 'addAdmin()' , ( ) => {
286322 it ( 'Throws on Invalid Format' , async ( ) => {
287323 try {
@@ -359,6 +395,48 @@ describe('actions', () => {
359395 expect ( teams_addUser ) . toHaveBeenCalled ( )
360396 expect ( issues_complete ) . toHaveBeenCalled ( )
361397 } )
398+
399+ it ( 'Throws on Invalid Admin' , async ( ) => {
400+ mocktokit . graphql . mockResolvedValue ( {
401+ user : {
402+ isEmployee : false ,
403+ email : 'fakeuser@notgithub.com'
404+ }
405+ } )
406+
407+ try {
408+ await actions . addAdmin (
409+ {
410+ action : AllowedIssueAction . CREATE ,
411+ customerName : 'Nick Testing Industries' ,
412+ customerAbbr : 'NA1' ,
413+ startDate : new Date ( 2024 , 10 , 17 ) ,
414+ endDate : new Date ( 2024 , 10 , 20 ) ,
415+ administrators : [
416+ {
417+ handle : 'ncalteen' ,
418+ email : 'ncalteen@github.com'
419+ }
420+ ] ,
421+ attendees : [
422+ {
423+ handle : 'ncalteen-testuser' ,
424+ email : 'ncalteen+testing@github.com'
425+ }
426+ ]
427+ } ,
428+ {
429+ issue : { number : 1 } ,
430+ comment : {
431+ body : '.add-admin fakeuser,fakeuser@notgithub.com'
432+ }
433+ } as any
434+ )
435+ } catch ( error : any ) {
436+ // eslint-disable-next-line jest/no-conditional-expect
437+ expect ( error . message ) . toBe ( 'Admins Must be GitHub/Microsoft Employees' )
438+ }
439+ } )
362440 } )
363441
364442 describe ( 'addUser()' , ( ) => {
@@ -434,4 +512,43 @@ describe('actions', () => {
434512 expect ( issues_complete ) . toHaveBeenCalled ( )
435513 } )
436514 } )
515+
516+ describe ( 'removeAdmin()' , ( ) => {
517+ it ( 'Throws on Invalid Format' , async ( ) => {
518+ try {
519+ await actions . removeAdmin (
520+ {
521+ action : AllowedIssueAction . CREATE ,
522+ customerName : 'Nick Testing Industries' ,
523+ customerAbbr : 'NA1' ,
524+ startDate : new Date ( 2024 , 10 , 17 ) ,
525+ endDate : new Date ( 2024 , 10 , 20 ) ,
526+ administrators : [
527+ {
528+ handle : 'ncalteen' ,
529+ email : 'ncalteen@github.com'
530+ }
531+ ] ,
532+ attendees : [
533+ {
534+ handle : 'ncalteen-testuser' ,
535+ email : 'ncalteen+testing@github.com'
536+ }
537+ ]
538+ } ,
539+ {
540+ issue : { number : 1 } ,
541+ comment : {
542+ body : '.remove-admin invalid format'
543+ }
544+ } as any
545+ )
546+ } catch ( error : any ) {
547+ // eslint-disable-next-line jest/no-conditional-expect
548+ expect ( error . message ) . toBe (
549+ 'Invalid Format! Try `.remove-admin handle,email`'
550+ )
551+ }
552+ } )
553+ } )
437554} )
0 commit comments