@@ -498,4 +498,91 @@ repository:
498498 handleResultsSpy . mockRestore ( )
499499 } )
500500 } )
501+
502+ describe ( 'updateRepos - archived repo skipping' , ( ) => {
503+ const Archive = require ( '../../../lib/plugins/archive' )
504+
505+ let settings
506+ let mockRepoSync
507+ let originalRepoPlugin
508+
509+ beforeEach ( ( ) => {
510+ // Preserve the original RepoPlugin so it can be restored after each test
511+ originalRepoPlugin = Settings . PLUGINS . repository
512+
513+ // Replace RepoPlugin with a mock constructor whose sync() we can assert on
514+ mockRepoSync = jest . fn ( ) . mockResolvedValue ( [ ] )
515+ Settings . PLUGINS . repository = jest . fn ( ) . mockImplementation ( ( ) => ( {
516+ sync : mockRepoSync
517+ } ) )
518+
519+ // Build a Settings instance that will enter the `if (repoConfig)` branch:
520+ // config.repository must be defined so repoConfig is truthy
521+ settings = new Settings (
522+ false ,
523+ stubContext ,
524+ { owner : 'test-org' , repo : 'test-repo' } ,
525+ { repository : { name : 'test-repo' } } ,
526+ 'main'
527+ )
528+
529+ // Pre-set subOrgConfigs so updateRepos() does not call the async getSubOrgConfigs()
530+ settings . subOrgConfigs = { }
531+
532+ // Pre-set repoConfigs so getRepoOverrideConfig() does not throw on undefined
533+ settings . repoConfigs = { }
534+ } )
535+
536+ afterEach ( ( ) => {
537+ // Restore the real RepoPlugin and all prototype spies
538+ Settings . PLUGINS . repository = originalRepoPlugin
539+ jest . restoreAllMocks ( )
540+ } )
541+
542+ it ( 'updateRepos when repo is already archived and not being unarchived does not call RepoPlugin sync' , async ( ) => {
543+ // Arrange
544+ jest . spyOn ( Archive . prototype , 'getState' ) . mockResolvedValue ( {
545+ isArchived : true ,
546+ shouldArchive : false ,
547+ shouldUnarchive : false
548+ } )
549+
550+ // Act
551+ await settings . updateRepos ( { owner : 'test-org' , repo : 'test-repo' } )
552+
553+ // Assert
554+ expect ( mockRepoSync ) . not . toHaveBeenCalled ( )
555+ } )
556+
557+ it ( 'updateRepos when repo is archived but is being unarchived calls RepoPlugin sync' , async ( ) => {
558+ // Arrange
559+ jest . spyOn ( Archive . prototype , 'getState' ) . mockResolvedValue ( {
560+ isArchived : true ,
561+ shouldArchive : false ,
562+ shouldUnarchive : true
563+ } )
564+ jest . spyOn ( Archive . prototype , 'sync' ) . mockResolvedValue ( [ ] )
565+
566+ // Act
567+ await settings . updateRepos ( { owner : 'test-org' , repo : 'test-repo' } )
568+
569+ // Assert
570+ expect ( mockRepoSync ) . toHaveBeenCalledTimes ( 1 )
571+ } )
572+
573+ it ( 'updateRepos when repo is not archived calls RepoPlugin sync' , async ( ) => {
574+ // Arrange
575+ jest . spyOn ( Archive . prototype , 'getState' ) . mockResolvedValue ( {
576+ isArchived : false ,
577+ shouldArchive : false ,
578+ shouldUnarchive : false
579+ } )
580+
581+ // Act
582+ await settings . updateRepos ( { owner : 'test-org' , repo : 'test-repo' } )
583+
584+ // Assert
585+ expect ( mockRepoSync ) . toHaveBeenCalledTimes ( 1 )
586+ } )
587+ } ) // updateRepos - archived repo skipping
501588} ) // Settings Tests
0 commit comments