Skip to content

Commit 55a05d1

Browse files
author
naman-contentstack
committed
chore: add test cases in Clone for AM
1 parent f498bd2 commit 55a05d1

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

packages/contentstack-clone/test/lib/util/clone-handler.commands.test.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from 'chai';
22
import { CloneHandler } from '../../../src/core/util/clone-handler';
33
import { CloneConfig } from '../../../src/types/clone-config';
4+
import { STRUCTURE_LIST } from '../../../src/utils/constants';
45
import sinon from 'sinon';
56
import 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', () => {

0 commit comments

Comments
 (0)