@@ -40,6 +40,8 @@ describe('Configurations Controller', () => {
4040 getSlackRoles : ( ) => { } ,
4141 getEnabledSandboxAudits : ( ) => [ ] ,
4242 getSandboxAuditConfig : ( ) => null ,
43+ getSandboxAudits : ( ) => null ,
44+ setSandboxAudits : ( ) => { } ,
4345 } ,
4446 {
4547 getVersion : ( ) => 2 ,
@@ -89,6 +91,13 @@ describe('Configurations Controller', () => {
8991 if ( auditType === 'meta-tags' ) return { expire : '15' } ;
9092 return null ;
9193 } ,
94+ getSandboxAudits : ( ) => ( {
95+ enabledAudits : {
96+ cwv : { expire : '10' } ,
97+ 'meta-tags' : { expire : '15' } ,
98+ } ,
99+ } ) ,
100+ setSandboxAudits : ( ) => { } ,
92101 state : {
93102 sandboxAudits : {
94103 enabledAudits : {
@@ -264,6 +273,8 @@ describe('Configurations Controller', () => {
264273 mockConfig = {
265274 state : { } ,
266275 updateSandboxAuditConfig : sandbox . stub ( ) ,
276+ getSandboxAudits : sandbox . stub ( ) . returns ( { enabledAudits : { } } ) ,
277+ setSandboxAudits : sandbox . stub ( ) ,
267278 save : sandbox . stub ( ) . resolves ( mockConfig ) ,
268279 } ;
269280
@@ -384,27 +395,28 @@ describe('Configurations Controller', () => {
384395 expect ( error . message ) . to . include ( 'Error updating sandbox configuration: Save failed' ) ;
385396 } ) ;
386397
387- it ( 'should handle configuration with undefined state ' , async ( ) => {
398+ it ( 'should handle configuration with null sandbox audits ' , async ( ) => {
388399 context . attributes . authInfo . withProfile ( { is_admin : true } ) ;
389400
390- // Create a config without state property to test our fix
391- const configWithoutState = {
401+ // Create a config with null sandbox audits to test our fix
402+ const configWithNullSandboxAudits = {
392403 updateSandboxAuditConfig : sandbox . stub ( ) ,
404+ getSandboxAudits : sandbox . stub ( ) . returns ( null ) ,
405+ setSandboxAudits : sandbox . stub ( ) ,
393406 save : sandbox . stub ( ) . resolves ( ) ,
394407 } ;
395- mockDataAccess . Configuration . findLatest . resolves ( configWithoutState ) ;
408+ mockDataAccess . Configuration . findLatest . resolves ( configWithNullSandboxAudits ) ;
396409 configurationsController = ConfigurationsController ( context ) ;
397410
398411 const result = await configurationsController . updateSandboxConfig ( {
399412 data : { sandboxConfigs : { cwv : { expire : '10' } } } ,
400413 } ) ;
401414 const response = await result . json ( ) ;
402415
403- // Should initialize state and succeed
416+ // Should succeed with null sandbox audits
404417 expect ( result . status ) . to . equal ( 200 ) ;
405- expect ( configWithoutState . state ) . to . deep . equal ( { } ) ;
406- expect ( configWithoutState . updateSandboxAuditConfig ) . to . have . been . calledWith ( 'cwv' , { expire : '10' } ) ;
407- expect ( configWithoutState . save ) . to . have . been . called ;
418+ expect ( configWithNullSandboxAudits . updateSandboxAuditConfig ) . to . have . been . calledWith ( 'cwv' , { expire : '10' } ) ;
419+ expect ( configWithNullSandboxAudits . save ) . to . have . been . called ;
408420 expect ( response . message ) . to . equal ( 'Sandbox configurations updated successfully' ) ;
409421 } ) ;
410422 } ) ;
0 commit comments