@@ -13,7 +13,7 @@ import {randomUUID} from 'crypto'
1313import { Team , Privacy as TeamPrivacy } from '../../src/resources/team'
1414import { RepositoryBranchProtectionRule } from '../../src/resources/repository-branch-protection-rule'
1515import { toggleArchivedRepos } from '../../src/actions/shared/toggle-archived-repos'
16- import * as state from '../../src/terraform/state'
16+ import { State } from '../../src/terraform/state'
1717
1818test ( 'can retrieve resources from YAML schema' , async ( ) => {
1919 const config = Config . FromPath ( )
@@ -23,13 +23,13 @@ test('can retrieve resources from YAML schema', async () => {
2323 for ( const resourceClass of ResourceConstructors ) {
2424 const classResources = config . getResources ( resourceClass )
2525 expect ( classResources ) . toHaveLength (
26- global . ResourceCounts [ resourceClass . name ]
26+ global . ConfigResourceCounts [ resourceClass . name ]
2727 )
2828 resources . push ( ...classResources )
2929 }
3030
3131 expect ( resources ) . toHaveLength (
32- Object . values ( global . ResourceCounts ) . reduce (
32+ Object . values ( global . ConfigResourceCounts ) . reduce (
3333 ( a : number , b : number ) => a + b ,
3434 0
3535 )
@@ -58,7 +58,7 @@ test('can remove members', async () => {
5858 }
5959
6060 expect ( config . getAllResources ( ) ) . toHaveLength (
61- global . ResourcesCount - global . ResourceCounts [ Member . name ]
61+ global . ConfigResourcesCount - global . ConfigResourceCounts [ Member . name ]
6262 )
6363} )
6464
@@ -76,8 +76,8 @@ test('can remove repositories, including their sub-resources', async () => {
7676 }
7777
7878 const count =
79- global . ResourcesCount -
80- Object . entries ( global . ResourceCounts ) . reduce (
79+ global . ConfigResourcesCount -
80+ Object . entries ( global . ConfigResourceCounts ) . reduce (
8181 ( a : number , [ key , value ] ) =>
8282 key . startsWith ( Repository . name ) ? a + value : a ,
8383 0
@@ -98,12 +98,12 @@ test('can add members', async () => {
9898 config . addResource ( member )
9999 expect ( config . someResource ( member ) ) . toBeTruthy ( )
100100 expect ( config . getResources ( Member ) ) . toHaveLength (
101- global . ResourceCounts [ Member . name ] + index + 1
101+ global . ConfigResourceCounts [ Member . name ] + index + 1
102102 )
103103 }
104104
105105 expect ( config . getAllResources ( ) ) . toHaveLength (
106- global . ResourcesCount + members . length
106+ global . ConfigResourcesCount + members . length
107107 )
108108} )
109109
@@ -124,15 +124,15 @@ test('can add files, including their parent resources', async () => {
124124 }
125125
126126 const count =
127- global . ResourcesCount +
127+ global . ConfigResourcesCount +
128128 files . filter ( f => ! config . someResource ( f ) ) . length +
129129 repositories . filter ( r => ! config . someResource ( r ) ) . length
130130
131131 for ( const [ index , file ] of files . entries ( ) ) {
132132 config . addResource ( file )
133133 expect ( config . someResource ( file ) ) . toBeTruthy ( )
134134 expect ( config . getResources ( RepositoryFile ) ) . toHaveLength (
135- global . ResourceCounts [ RepositoryFile . name ] + index + 1
135+ global . ConfigResourceCounts [ RepositoryFile . name ] + index + 1
136136 )
137137 }
138138
@@ -365,7 +365,7 @@ repositories:
365365
366366test ( 'can add and remove resources through sync' , async ( ) => {
367367 const config = new Config ( '{}' )
368- let desiredResources : Resource [ ] = [ ]
368+ const desiredResources : Resource [ ] = [ ]
369369 let resources = config . getAllResources ( )
370370
371371 config . sync ( desiredResources )
@@ -389,41 +389,37 @@ test('can add and remove resources through sync', async () => {
389389} )
390390
391391test ( 'clears and re-adds repository fields when archiving/unarchiving' , async ( ) => {
392- let config = Config . FromPath ( )
393-
394- const unarchivedRepo = config . getResources ( Repository ) . find ( r => ! r . archived ) !
395-
396- expect ( unarchivedRepo . visibility ) . toBeDefined ( )
397-
398- unarchivedRepo . archived = true
399- config . addResource ( unarchivedRepo )
400-
401- await toggleArchivedRepos ( config )
392+ const config = Config . FromPath ( )
393+ const state = await State . New ( )
402394
403- const archivedRepo = config
395+ const archivedRepository = config
396+ . getResources ( Repository )
397+ . find ( r => r . archived ) !
398+ const unarchivedRepository = config
404399 . getResources ( Repository )
405- . find ( r => r . getStateAddress ( ) == unarchivedRepo . getStateAddress ( ) ) !
400+ . find ( r => ! r . archived ) !
406401
407- expect ( archivedRepo . archived ) . toBe ( true )
408- expect ( archivedRepo . visibility ) . not . toBeDefined ( )
402+ expect ( archivedRepository . archived ) . toBe ( true )
403+ expect ( archivedRepository . visibility ) . not . toBeDefined ( )
409404
410- archivedRepo . archived = false
411- config . addResource ( archivedRepo )
405+ expect ( unarchivedRepository . archived ) . toBe ( false )
406+ expect ( unarchivedRepository . visibility ) . toBeDefined ( )
412407
413- const newState = JSON . parse ( await state . loadState ( ) )
414- newState . values . root_module . resources . find (
415- ( r : any ) => r . address == unarchivedRepo . getStateAddress ( )
416- ) ! . values . archived = true
408+ archivedRepository . archived = false
409+ unarchivedRepository . archived = true
417410
418- const loadStateMock = jest . spyOn ( state , 'loadState' )
419- loadStateMock . mockImplementation ( async ( ) => JSON . stringify ( newState ) )
411+ config . addResource ( archivedRepository )
412+ config . addResource ( unarchivedRepository )
420413
421- await toggleArchivedRepos ( config )
414+ await toggleArchivedRepos ( state , config )
422415
423- const toggledRepo = config
424- . getResources ( Repository )
425- . find ( r => r . getStateAddress ( ) == unarchivedRepo . getStateAddress ( ) ) !
416+ const previouslyArchivedRepository = config . findResource ( archivedRepository ) !
417+ const previouslyUnarchivedRepository =
418+ config . findResource ( unarchivedRepository ) !
419+
420+ expect ( previouslyArchivedRepository . archived ) . toBe ( false )
421+ expect ( previouslyArchivedRepository . visibility ) . toBeDefined ( )
426422
427- expect ( toggledRepo . archived ) . toBe ( false )
428- expect ( toggledRepo . visibility ) . toBeDefined ( )
423+ expect ( previouslyUnarchivedRepository . archived ) . toBe ( true )
424+ expect ( previouslyUnarchivedRepository . visibility ) . not . toBeDefined ( )
429425} )
0 commit comments