11import { expect } from 'chai' ;
22import { CloneHandler } from '../../../src/core/util/clone-handler' ;
33import { CloneConfig } from '../../../src/types/clone-config' ;
4+ import { STRUCTURE_LIST } from '../../../src/utils/constants' ;
45import sinon from 'sinon' ;
56import inquirer from 'inquirer' ;
67
@@ -137,6 +138,94 @@ describe('CloneHandler - Commands', () => {
137138 expect ( cmdArgs ) . to . include ( '-a' ) ;
138139 expect ( cmdArgs ) . to . include ( 'source-alias' ) ;
139140 } ) ;
141+
142+ it ( 'should set filteredModules for structure-only export without assets (AM 2.0 needs full export)' , async ( ) => {
143+ const exportCmdStub = {
144+ run : sandbox . stub ( ) . returns ( Promise . resolve ( ) ) ,
145+ } ;
146+ sandbox . stub ( require ( '@contentstack/cli-cm-export' ) , 'default' ) . value ( exportCmdStub ) ;
147+
148+ await handler . cmdExport ( ) ;
149+
150+ expect ( fsStub . writeFileSync . calledOnce ) . to . be . true ;
151+ const written = JSON . parse ( fsStub . writeFileSync . firstCall . args [ 1 ] as string ) ;
152+ expect ( written . filteredModules ) . to . deep . equal ( [ 'stack' , ...STRUCTURE_LIST ] ) ;
153+ expect ( written . filteredModules ) . to . not . include ( 'assets' ) ;
154+ expect ( written . filteredModules ) . to . not . include ( 'entries' ) ;
155+ } ) ;
156+
157+ it ( 'should not set filteredModules for full clone so default export includes assets' , async ( ) => {
158+ const config : CloneConfig = {
159+ cloneContext : {
160+ command : 'test' ,
161+ module : 'clone' ,
162+ email : 'test@example.com' ,
163+ } ,
164+ source_stack : 'test-key' ,
165+ cloneType : 'b' ,
166+ } ;
167+ handler = new CloneHandler ( config ) ;
168+ const exportCmdStub = {
169+ run : sandbox . stub ( ) . returns ( Promise . resolve ( ) ) ,
170+ } ;
171+ sandbox . stub ( require ( '@contentstack/cli-cm-export' ) , 'default' ) . value ( exportCmdStub ) ;
172+
173+ await handler . cmdExport ( ) ;
174+
175+ expect ( fsStub . writeFileSync . calledOnce ) . to . be . true ;
176+ const written = JSON . parse ( fsStub . writeFileSync . firstCall . args [ 1 ] as string ) ;
177+ expect ( written ) . to . not . have . property ( 'filteredModules' ) ;
178+ } ) ;
179+
180+ it ( 'should preserve region.assetManagementUrl in serialized export config for AM 2.0 export' , async ( ) => {
181+ const amUrl = 'https://asset-management.example.com' ;
182+ const config : CloneConfig = {
183+ cloneContext : {
184+ command : 'test' ,
185+ module : 'clone' ,
186+ email : 'test@example.com' ,
187+ } ,
188+ source_stack : 'test-key' ,
189+ cloneType : 'b' ,
190+ region : { assetManagementUrl : amUrl } ,
191+ } ;
192+ handler = new CloneHandler ( config ) ;
193+ const exportCmdStub = {
194+ run : sandbox . stub ( ) . returns ( Promise . resolve ( ) ) ,
195+ } ;
196+ sandbox . stub ( require ( '@contentstack/cli-cm-export' ) , 'default' ) . value ( exportCmdStub ) ;
197+
198+ await handler . cmdExport ( ) ;
199+
200+ const written = JSON . parse ( fsStub . writeFileSync . firstCall . args [ 1 ] as string ) ;
201+ expect ( written . region ) . to . be . an ( 'object' ) ;
202+ expect ( written . region . assetManagementUrl ) . to . equal ( amUrl ) ;
203+ } ) ;
204+
205+ it ( 'should merge export.region.assetManagementUrl from external export config' , async ( ) => {
206+ const amUrl = 'https://asset-management-merged.example.com' ;
207+ const config : CloneConfig = {
208+ cloneContext : {
209+ command : 'test' ,
210+ module : 'clone' ,
211+ email : 'test@example.com' ,
212+ } ,
213+ source_stack : 'test-key' ,
214+ cloneType : 'b' ,
215+ export : { region : { assetManagementUrl : amUrl } } ,
216+ } ;
217+ handler = new CloneHandler ( config ) ;
218+ const exportCmdStub = {
219+ run : sandbox . stub ( ) . returns ( Promise . resolve ( ) ) ,
220+ } ;
221+ sandbox . stub ( require ( '@contentstack/cli-cm-export' ) , 'default' ) . value ( exportCmdStub ) ;
222+
223+ await handler . cmdExport ( ) ;
224+
225+ const written = JSON . parse ( fsStub . writeFileSync . firstCall . args [ 1 ] as string ) ;
226+ expect ( written . region . assetManagementUrl ) . to . equal ( amUrl ) ;
227+ expect ( written ) . to . not . have . property ( 'export' ) ;
228+ } ) ;
140229 } ) ;
141230
142231 describe ( 'cmdImport' , ( ) => {
@@ -398,7 +487,7 @@ describe('CloneHandler - Commands', () => {
398487 // Mock configHandler FIRST before creating handler - following import plugin pattern
399488 const configHandler = require ( '@contentstack/cli-utilities' ) . configHandler ;
400489 configHandlerGetStub = sandbox . stub ( configHandler , 'get' ) . returns ( undefined ) ;
401-
490+
402491 // Stub ora spinner - following import plugin pattern
403492 const oraModule = require ( 'ora' ) ;
404493 const mockSpinner = {
@@ -412,7 +501,7 @@ describe('CloneHandler - Commands', () => {
412501 writable : true ,
413502 configurable : true ,
414503 } ) ;
415-
504+
416505 const config : CloneConfig = {
417506 cloneContext : {
418507 command : 'test' ,
0 commit comments