From 55a05d198281fae0f06aa08a833d352dee84664b Mon Sep 17 00:00:00 2001 From: naman-contentstack Date: Tue, 7 Apr 2026 14:53:07 +0530 Subject: [PATCH] chore: add test cases in Clone for AM --- .../lib/util/clone-handler.commands.test.ts | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts b/packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts index 12b75558..489c99af 100644 --- a/packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts +++ b/packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts @@ -1,6 +1,7 @@ import { expect } from 'chai'; import { CloneHandler } from '../../../src/core/util/clone-handler'; import { CloneConfig } from '../../../src/types/clone-config'; +import { STRUCTURE_LIST } from '../../../src/utils/constants'; import sinon from 'sinon'; import inquirer from 'inquirer'; @@ -137,6 +138,94 @@ describe('CloneHandler - Commands', () => { expect(cmdArgs).to.include('-a'); expect(cmdArgs).to.include('source-alias'); }); + + it('should set filteredModules for structure-only export without assets (AM 2.0 needs full export)', async () => { + const exportCmdStub = { + run: sandbox.stub().returns(Promise.resolve()), + }; + sandbox.stub(require('@contentstack/cli-cm-export'), 'default').value(exportCmdStub); + + await handler.cmdExport(); + + expect(fsStub.writeFileSync.calledOnce).to.be.true; + const written = JSON.parse(fsStub.writeFileSync.firstCall.args[1] as string); + expect(written.filteredModules).to.deep.equal(['stack', ...STRUCTURE_LIST]); + expect(written.filteredModules).to.not.include('assets'); + expect(written.filteredModules).to.not.include('entries'); + }); + + it('should not set filteredModules for full clone so default export includes assets', async () => { + const config: CloneConfig = { + cloneContext: { + command: 'test', + module: 'clone', + email: 'test@example.com', + }, + source_stack: 'test-key', + cloneType: 'b', + }; + handler = new CloneHandler(config); + const exportCmdStub = { + run: sandbox.stub().returns(Promise.resolve()), + }; + sandbox.stub(require('@contentstack/cli-cm-export'), 'default').value(exportCmdStub); + + await handler.cmdExport(); + + expect(fsStub.writeFileSync.calledOnce).to.be.true; + const written = JSON.parse(fsStub.writeFileSync.firstCall.args[1] as string); + expect(written).to.not.have.property('filteredModules'); + }); + + it('should preserve region.assetManagementUrl in serialized export config for AM 2.0 export', async () => { + const amUrl = 'https://asset-management.example.com'; + const config: CloneConfig = { + cloneContext: { + command: 'test', + module: 'clone', + email: 'test@example.com', + }, + source_stack: 'test-key', + cloneType: 'b', + region: { assetManagementUrl: amUrl }, + }; + handler = new CloneHandler(config); + const exportCmdStub = { + run: sandbox.stub().returns(Promise.resolve()), + }; + sandbox.stub(require('@contentstack/cli-cm-export'), 'default').value(exportCmdStub); + + await handler.cmdExport(); + + const written = JSON.parse(fsStub.writeFileSync.firstCall.args[1] as string); + expect(written.region).to.be.an('object'); + expect(written.region.assetManagementUrl).to.equal(amUrl); + }); + + it('should merge export.region.assetManagementUrl from external export config', async () => { + const amUrl = 'https://asset-management-merged.example.com'; + const config: CloneConfig = { + cloneContext: { + command: 'test', + module: 'clone', + email: 'test@example.com', + }, + source_stack: 'test-key', + cloneType: 'b', + export: { region: { assetManagementUrl: amUrl } }, + }; + handler = new CloneHandler(config); + const exportCmdStub = { + run: sandbox.stub().returns(Promise.resolve()), + }; + sandbox.stub(require('@contentstack/cli-cm-export'), 'default').value(exportCmdStub); + + await handler.cmdExport(); + + const written = JSON.parse(fsStub.writeFileSync.firstCall.args[1] as string); + expect(written.region.assetManagementUrl).to.equal(amUrl); + expect(written).to.not.have.property('export'); + }); }); describe('cmdImport', () => {