|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import { CloneHandler } from '../../../src/core/util/clone-handler'; |
3 | 3 | import { CloneConfig } from '../../../src/types/clone-config'; |
| 4 | +import { STRUCTURE_LIST } from '../../../src/utils/constants'; |
4 | 5 | import sinon from 'sinon'; |
5 | 6 | import inquirer from 'inquirer'; |
6 | 7 |
|
@@ -137,6 +138,94 @@ describe('CloneHandler - Commands', () => { |
137 | 138 | expect(cmdArgs).to.include('-a'); |
138 | 139 | expect(cmdArgs).to.include('source-alias'); |
139 | 140 | }); |
| 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 | + }); |
140 | 229 | }); |
141 | 230 |
|
142 | 231 | describe('cmdImport', () => { |
|
0 commit comments