11import { expect } from 'chai' ;
22import * as sinon from 'sinon' ;
3- import { ux } from '@salesforce/command' ;
4- import OmniStudioBaseCommand from '../../basecommand' ;
5- import { LWCComponentMigrationTool , CustomLabelMigrationTool , ApexClassMigrationTool } from '../../../migration/interfaces' ;
6- import OmnistudioRelatedObjectMigrationFacade from '../../../path/to/OmnistudioRelatedObjectMigrationFacade' ; // Adjust import as necessary
7- import { DebugTimer , MigratedObject , MigratedRecordInfo } from '../../../utils' ;
8- import { MigrationResult , MigrationTool } from '../../../migration/interfaces' ;
3+ import { IConfig } from '@oclif/config' ;
4+ import OmnistudioRelatedObjectMigrationFacade from '../../../../src/commands/omnistudio/migration/OmnistudioRelatedObjectMigrationFacade' ; // Adjust import as necessary
5+ import {
6+ MigrationResult ,
7+ LWCComponentMigrationTool ,
8+ CustomLabelMigrationTool ,
9+ ApexClassMigrationTool ,
10+ UploadRecordResult ,
11+ MigratedObject ,
12+ } from '../../../../src/migration/interfaces' ;
13+
14+ // Define mock types for dependencies
15+ interface OrgConnection {
16+ getConnection : ( ) => {
17+ setApiVersion : sinon . SinonStub ;
18+ instanceUrl : string ;
19+ } ;
20+ }
21+
22+ interface Logger {
23+ error : sinon . SinonStub ;
24+ debug : sinon . SinonStub ;
25+ }
26+
27+ interface UX {
28+ log : sinon . SinonStub ;
29+ }
30+
31+ // Define a mock config object
32+ const mockConfig : IConfig = {
33+ root : '' ,
34+ userAgent : '' ,
35+ version : '1.0.0' ,
36+ // Add any other properties that might be needed
37+ } as unknown as IConfig ;
38+
39+ // Mock classes for Migration Tools
40+ class MockLWCComponentMigrationTool implements LWCComponentMigrationTool {
41+ public migrate = sinon . stub ( ) . resolves ( [ { name : 'LWC Component' , id : '001' } ] ) ;
42+ public truncate = sinon . stub ( ) . resolves ( ) ;
43+ public getName = sinon . stub ( ) . returns ( 'LWC Component' ) ;
44+ }
45+
46+ class MockCustomLabelMigrationTool implements CustomLabelMigrationTool {
47+ public migrate = sinon . stub ( ) . resolves ( [ { name : 'Custom Label' , id : '002' } ] ) ;
48+ public truncate = sinon . stub ( ) . resolves ( ) ;
49+ public getName = sinon . stub ( ) . returns ( 'Custom Label' ) ;
50+ }
51+
52+ class MockApexClassMigrationTool implements ApexClassMigrationTool {
53+ public migrate = sinon . stub ( ) . resolves ( [ { name : 'Apex Class' , id : '003' } ] ) ;
54+ public truncate = sinon . stub ( ) . resolves ( ) ;
55+ public getName = sinon . stub ( ) . returns ( 'Apex Class' ) ;
56+ }
957
1058describe ( 'OmnistudioRelatedObjectMigrationFacade' , function ( ) {
1159 let facade : OmnistudioRelatedObjectMigrationFacade ;
@@ -14,50 +62,50 @@ describe('OmnistudioRelatedObjectMigrationFacade', function () {
1462 beforeEach ( ( ) => {
1563 sandbox = sinon . createSandbox ( ) ;
1664
17- // Stub the necessary methods and objects
18- facade = new OmnistudioRelatedObjectMigrationFacade ( ) ;
65+ // Initialize facade with proper types
66+ facade = new OmnistudioRelatedObjectMigrationFacade ( [ ] , mockConfig ) ;
67+
68+ // Stub the 'org' property
1969 sandbox . stub ( facade , 'org' ) . value ( {
2070 getConnection : ( ) => ( {
21- setApiVersion : sinon . stub ( ) ,
22- instanceUrl : 'http://example.com'
23- } )
24- } ) ;
71+ setApiVersion : sinon . stub ( ) . resolves ( ) ,
72+ instanceUrl : 'http://example.com' ,
73+ } ) ,
74+ } as OrgConnection ) ;
2575
76+ // Stub the 'logger' property
2677 sandbox . stub ( facade , 'logger' ) . value ( {
27- error : sinon . stub ( ) ,
28- debug : sinon . stub ( )
29- } ) ;
30-
31- sandbox . stub ( facade , 'ux' ) . value ( ux ) ;
78+ error : sinon . stub ( ) . callsFake ( ( ) => { } ) , // No-op
79+ debug : sinon . stub ( ) . callsFake ( ( ) => { } ) , // No-op
80+ } as Logger ) ;
81+
82+ // Stub the 'ux' property
83+ sandbox . stub ( facade , 'ux' ) . value ( {
84+ log : sinon . stub ( ) . callsFake ( ( ) => { } ) , // No-op
85+ } as UX ) ;
3286 } ) ;
3387
3488 afterEach ( ( ) => {
3589 sandbox . restore ( ) ;
3690 } ) ;
3791
38- it ( 'should migrate all specified objects' , async function ( ) {
92+ it ( 'should migrate all specified objects successfully ' , async function ( ) {
3993 const migrationResult : MigrationResult = {
40- records : new Map ( ) ,
41- results : new Map ( )
94+ records : new Map < string , UploadRecordResult > ( ) , // Use specific type if known
95+ results : new Map < string , UploadRecordResult > ( ) ,
4296 } ;
4397
44- const lwcTool = sandbox . createStubInstance ( LWCComponentMigrationTool ) ;
45- const labelsTool = sandbox . createStubInstance ( CustomLabelMigrationTool ) ;
46- const apexTool = sandbox . createStubInstance ( ApexClassMigrationTool ) ;
98+ // Create instances of mock tools
99+ const lwcTool = new MockLWCComponentMigrationTool ( ) ;
100+ const labelsTool = new MockCustomLabelMigrationTool ( ) ;
101+ const apexTool = new MockApexClassMigrationTool ( ) ;
47102
48- lwcTool . migrate . resolves ( [ { name : 'LWC Component' , id : '001' } ] ) ;
49- labelsTool . migrate . resolves ( [ { name : 'Custom Label' , id : '002' } ] ) ;
50- apexTool . migrate . resolves ( [ { name : 'Apex Class' , id : '003' } ] ) ;
103+ // Stub the factory methods to return our mock tools
104+ sandbox . stub ( facade , 'createLWCComponentMigrationTool' ) . returns ( lwcTool ) ;
105+ sandbox . stub ( facade , 'createCustomLabelMigrationTool' ) . returns ( labelsTool ) ;
106+ sandbox . stub ( facade , 'createApexClassMigrationTool' ) . returns ( apexTool ) ;
51107
52- sandbox . stub ( facade , 'migrateAll' ) . resolves ( {
53- objectMigrationResults : [
54- { name : 'LWC Component' , data : [ ] } ,
55- { name : 'Custom Label' , data : [ ] } ,
56- { name : 'Apex Class' , data : [ ] }
57- ]
58- } ) ;
59-
60- await facade . migrateAll ( migrationResult , 'testNamespace' , [ 'lwc' , 'labels' , 'apex' ] ) ;
108+ const result = await facade . migrateAll ( migrationResult , 'testNamespace' , [ 'lwc' , 'labels' , 'apex' ] ) ;
61109
62110 expect ( lwcTool . migrate . calledOnce ) . to . be . true ;
63111 expect ( labelsTool . migrate . calledOnce ) . to . be . true ;
@@ -66,31 +114,33 @@ describe('OmnistudioRelatedObjectMigrationFacade', function () {
66114 // Assert that the migration results are processed correctly
67115 expect ( facade . logger . debug . calledOnce ) . to . be . true ;
68116 expect ( facade . ux . log . called ) . to . have . lengthOf ( 3 ) ; // Assuming each tool logs once
117+
118+ // Type assertion to avoid `any` issues
119+ const objectMigrationResults = result as { objectMigrationResults : MigratedObject [ ] } ;
120+ expect ( objectMigrationResults . objectMigrationResults ) . to . have . lengthOf ( 3 ) ; // Verify result count
69121 } ) ;
70122
71123 it ( 'should handle errors during migration' , async function ( ) {
72124 const migrationResult : MigrationResult = {
73- records : new Map ( ) ,
74- results : new Map ( )
125+ records : new Map < string , UploadRecordResult > ( ) , // Use specific type if known
126+ results : new Map < string , UploadRecordResult > ( ) ,
75127 } ;
76128
77- const lwcTool = sandbox . createStubInstance ( LWCComponentMigrationTool ) ;
78- const labelsTool = sandbox . createStubInstance ( CustomLabelMigrationTool ) ;
79- const apexTool = sandbox . createStubInstance ( ApexClassMigrationTool ) ;
129+ // Create instances of mock tools
130+ const lwcTool = new MockLWCComponentMigrationTool ( ) ;
131+ const labelsTool = new MockCustomLabelMigrationTool ( ) ;
132+ const apexTool = new MockApexClassMigrationTool ( ) ;
80133
81134 lwcTool . migrate . rejects ( new Error ( 'LWC migration error' ) ) ;
82135 labelsTool . migrate . resolves ( [ { name : 'Custom Label' , id : '002' } ] ) ;
83136 apexTool . migrate . resolves ( [ { name : 'Apex Class' , id : '003' } ] ) ;
84137
85- sandbox . stub ( facade , 'migrateAll' ) . resolves ( {
86- objectMigrationResults : [
87- { name : 'LWC Component' , data : [ ] , errors : [ 'LWC migration error' ] } ,
88- { name : 'Custom Label' , data : [ ] } ,
89- { name : 'Apex Class' , data : [ ] }
90- ]
91- } ) ;
138+ // Stub the factory methods to return our mock tools
139+ sandbox . stub ( facade , 'createLWCComponentMigrationTool' ) . returns ( lwcTool ) ;
140+ sandbox . stub ( facade , 'createCustomLabelMigrationTool' ) . returns ( labelsTool ) ;
141+ sandbox . stub ( facade , 'createApexClassMigrationTool' ) . returns ( apexTool ) ;
92142
93- await facade . migrateAll ( migrationResult , 'testNamespace' , [ 'lwc' , 'labels' , 'apex' ] ) ;
143+ const result = await facade . migrateAll ( migrationResult , 'testNamespace' , [ 'lwc' , 'labels' , 'apex' ] ) ;
94144
95145 expect ( lwcTool . migrate . calledOnce ) . to . be . true ;
96146 expect ( labelsTool . migrate . calledOnce ) . to . be . true ;
@@ -99,5 +149,9 @@ describe('OmnistudioRelatedObjectMigrationFacade', function () {
99149 // Check that the error was logged
100150 expect ( facade . logger . error . calledOnce ) . to . be . true ;
101151 expect ( facade . ux . log . called ) . to . have . lengthOf ( 3 ) ; // Assuming each tool logs once
152+
153+ // Type assertion to avoid `any` issues
154+ const objectMigrationResults = result as { objectMigrationResults : MigratedObject [ ] } ;
155+ expect ( objectMigrationResults . objectMigrationResults ) . to . be . an ( 'array' ) . that . has . lengthOf ( 3 ) ; // Verify result count
102156 } ) ;
103- } ) ;
157+ } ) ;
0 commit comments