@@ -53,6 +53,7 @@ describe('PostMigrate', () => {
5353 tooling : {
5454 executeAnonymous : sandbox . stub ( ) ,
5555 } ,
56+ query : sandbox . stub ( ) ,
5657 } as unknown as Connection ;
5758
5859 // Mock logger
@@ -92,6 +93,10 @@ describe('PostMigrate', () => {
9293 . withArgs ( 'errorRevertingExperienceBundleMetadataAPI' )
9394 . returns ( 'Error reverting Experience Bundle Metadata API' ) ;
9495 getMessageStub . withArgs ( 'errorDeployingComponents' ) . returns ( 'Error deploying components' ) ;
96+ // New messages referenced by implementation
97+ getMessageStub . withArgs ( 'checkingStandardDesignerStatus' , [ testNamespace ] ) . returns ( 'Checking designer status' ) ;
98+ getMessageStub . withArgs ( 'standardDesignerAlreadyEnabled' , [ testNamespace ] ) . returns ( 'Designer already enabled' ) ;
99+ getMessageStub . withArgs ( 'skipStandardRuntimeDueToFailure' ) . returns ( 'Skip runtime due to failure' ) ;
95100
96101 // Mock Logger static methods
97102 sandbox . stub ( Logger , 'logVerbose' ) ;
@@ -156,7 +161,7 @@ describe('PostMigrate', () => {
156161 expect ( deployerStub . called ) . to . be . false ;
157162 } ) ;
158163
159- xit ( 'should handle deployment errors gracefully' , ( ) => {
164+ it ( 'should handle deployment errors gracefully' , ( ) => {
160165 // Arrange
161166 const error = new Error ( 'Deployment failed' ) ;
162167 const deployerStub = sandbox . stub ( Deployer . prototype , 'deploy' ) . throws ( error ) ;
@@ -229,7 +234,10 @@ describe('PostMigrate', () => {
229234 const logVerboseStub = Logger . logVerbose as sinon . SinonStub ;
230235
231236 // Act
232- const result = await postMigrate . setDesignersToUseStandardDataModel ( namespaceToModify , userActionMessage ) ;
237+ const result = await postMigrate . enableDesignersToUseStandardDataModelIfNeeded (
238+ namespaceToModify ,
239+ userActionMessage
240+ ) ;
233241
234242 // Assert
235243 expect ( anonymousApexRunnerStub . calledOnce ) . to . be . true ;
@@ -239,7 +247,8 @@ describe('PostMigrate', () => {
239247 ) ;
240248 expect ( logVerboseStub . calledWith ( 'Setting designers to standard model...' ) ) . to . be . true ;
241249 expect ( logVerboseStub . calledWith ( 'Designers set to standard model' ) ) . to . be . true ;
242- expect ( result ) . to . deep . equal ( userActionMessage ) ;
250+ expect ( result ) . to . equal ( true ) ;
251+ expect ( userActionMessage ) . to . deep . equal ( [ ] ) ;
243252 } ) ;
244253
245254 it ( 'should handle unsuccessful anonymous apex execution' , async ( ) => {
@@ -258,12 +267,16 @@ describe('PostMigrate', () => {
258267 const anonymousApexRunnerStub = sandbox . stub ( AnonymousApexRunner , 'run' ) . resolves ( mockResult ) ;
259268
260269 // Act
261- const result = await postMigrate . setDesignersToUseStandardDataModel ( namespaceToModify , userActionMessage ) ;
270+ const result = await postMigrate . enableDesignersToUseStandardDataModelIfNeeded (
271+ namespaceToModify ,
272+ userActionMessage
273+ ) ;
262274
263275 // Assert
264276 expect ( anonymousApexRunnerStub . calledOnce ) . to . be . true ;
265277 expect ( logErrorStub . called ) . to . be . true ;
266- expect ( result ) . to . include ( 'Please manually switch designer to standard data model' ) ;
278+ expect ( result ) . to . equal ( false ) ;
279+ expect ( userActionMessage ) . to . include ( 'Please manually switch designer to standard data model' ) ;
267280 } ) ;
268281
269282 it ( 'should handle exceptions during execution' , async ( ) => {
@@ -274,12 +287,78 @@ describe('PostMigrate', () => {
274287 const anonymousApexRunnerStub = sandbox . stub ( AnonymousApexRunner , 'run' ) . rejects ( error ) ;
275288
276289 // Act
277- const result = await postMigrate . setDesignersToUseStandardDataModel ( namespaceToModify , userActionMessage ) ;
290+ const result = await postMigrate . enableDesignersToUseStandardDataModelIfNeeded (
291+ namespaceToModify ,
292+ userActionMessage
293+ ) ;
278294
279295 // Assert
280296 expect ( anonymousApexRunnerStub . calledOnce ) . to . be . true ;
281297 expect ( logErrorStub . called ) . to . be . true ;
282- expect ( result ) . to . include ( 'Please manually switch designer to standard data model' ) ;
298+ expect ( result ) . to . equal ( false ) ;
299+ expect ( userActionMessage ) . to . include ( 'Please manually switch designer to standard data model' ) ;
300+ } ) ;
301+
302+ it ( 'should return true when standard designer already enabled and skip Apex' , async ( ) => {
303+ // Arrange
304+ const namespaceToModify = 'test_namespace' ;
305+ const userActionMessage : string [ ] = [ ] ;
306+ // Stub SOQL query to indicate designer already enabled for this namespace
307+ ( connection . query as unknown as sinon . SinonStub ) . resolves ( {
308+ totalSize : 2 ,
309+ records : [
310+ { DeveloperName : 'TheFirstInstalledOmniPackage' , Value : namespaceToModify } ,
311+ { DeveloperName : 'InstalledIndustryPackage' , Value : 'other' } ,
312+ ] ,
313+ } ) ;
314+ const anonymousApexRunnerStub = sandbox . stub ( AnonymousApexRunner , 'run' ) ;
315+
316+ // Act
317+ const result = await ( postMigrate as any ) . enableDesignersToUseStandardDataModelIfNeeded (
318+ namespaceToModify ,
319+ userActionMessage
320+ ) ;
321+
322+ // Assert
323+ expect ( result ) . to . equal ( true ) ;
324+ expect ( anonymousApexRunnerStub . called ) . to . be . false ;
325+ expect ( userActionMessage ) . to . deep . equal ( [ ] ) ;
326+ } ) ;
327+ } ) ;
328+
329+ describe ( 'executeTasks' , ( ) => {
330+ it ( 'should enable runtime when designer step succeeds' , async ( ) => {
331+ // Arrange
332+ const enableDesignerStub = sandbox
333+ . stub ( postMigrate as any , 'enableDesignersToUseStandardDataModelIfNeeded' )
334+ . resolves ( true ) ;
335+ const enableRuntimeSpy = sandbox . stub ( postMigrate as any , 'enableStandardRuntimeIfNeeded' ) . resolves ( ) ;
336+ const actionItems : string [ ] = [ ] ;
337+
338+ // Act
339+ const res = await ( postMigrate as any ) . executeTasks ( testNamespace , actionItems ) ;
340+
341+ // Assert
342+ expect ( enableDesignerStub . calledOnce ) . to . be . true ;
343+ expect ( enableRuntimeSpy . calledOnce ) . to . be . true ;
344+ expect ( res ) . to . equal ( actionItems ) ;
345+ } ) ;
346+
347+ it ( 'should not enable runtime when designer step fails' , async ( ) => {
348+ // Arrange
349+ const enableDesignerStub = sandbox
350+ . stub ( postMigrate as any , 'enableDesignersToUseStandardDataModelIfNeeded' )
351+ . resolves ( false ) ;
352+ const enableRuntimeSpy = sandbox . stub ( postMigrate as any , 'enableStandardRuntimeIfNeeded' ) . resolves ( ) ;
353+ const actionItems : string [ ] = [ ] ;
354+
355+ // Act
356+ const res = await ( postMigrate as any ) . executeTasks ( testNamespace , actionItems ) ;
357+
358+ // Assert
359+ expect ( enableDesignerStub . calledOnce ) . to . be . true ;
360+ expect ( enableRuntimeSpy . called ) . to . be . false ;
361+ expect ( res ) . to . equal ( actionItems ) ;
283362 } ) ;
284363 } ) ;
285364
@@ -465,7 +544,7 @@ describe('PostMigrate', () => {
465544
466545 // Act
467546 postMigrate . deploy ( ) ;
468- await postMigrate . setDesignersToUseStandardDataModel ( 'test_namespace' , [ ] ) ;
547+ await ( postMigrate as any ) . enableDesignersToUseStandardDataModelIfNeeded ( 'test_namespace' , [ ] ) ;
469548 await postMigrate . restoreExperienceAPIMetadataSettings ( { value : true } , [ ] ) ;
470549
471550 // Assert
@@ -500,7 +579,7 @@ describe('PostMigrate', () => {
500579
501580 // Act
502581 postMigrateNoDeploy . deploy ( ) ;
503- await postMigrateNoDeploy . setDesignersToUseStandardDataModel ( 'test_namespace' , [ ] ) ;
582+ await ( postMigrateNoDeploy as any ) . enableDesignersToUseStandardDataModelIfNeeded ( 'test_namespace' , [ ] ) ;
504583
505584 // Assert
506585 expect ( deployerStub . called ) . to . be . false ;
0 commit comments