@squiz/dxp-cli-next 5.26.0-develop.4 → 5.26.0-develop.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/migration/create/{createMigration.js → create.js} +5 -5
- package/lib/migration/create/{createMigration.spec.js → create.spec.js} +44 -41
- package/lib/migration/get/{getMigration.js → get.js} +4 -6
- package/lib/migration/get/{getMigration.spec.js → get.spec.js} +39 -30
- package/lib/migration/index.js +9 -7
- package/lib/migration/next/next.d.ts +3 -0
- package/lib/migration/next/next.js +46 -0
- package/lib/migration/next/next.spec.js +186 -0
- package/lib/migration/revert/revert.js +5 -6
- package/lib/migration/revert/revert.spec.js +10 -7
- package/lib/migration/settings/{setMigrationSettings.js → settings.js} +7 -8
- package/lib/migration/settings/{setMigrationSettings.spec.js → settings.spec.js} +34 -26
- package/lib/migration/types/common.types.d.ts +19 -0
- package/lib/migration/types/createMigration.types.d.ts +7 -0
- package/lib/migration/types/createMigration.types.js +2 -0
- package/lib/migration/types/getMigration.types.d.ts +5 -0
- package/lib/migration/types/getMigration.types.js +2 -0
- package/lib/migration/types/index.d.ts +6 -0
- package/lib/migration/types/index.js +22 -0
- package/lib/migration/types/nextStage.types.d.ts +6 -0
- package/lib/migration/types/nextStage.types.js +2 -0
- package/lib/migration/types/revert.types.d.ts +6 -0
- package/lib/migration/types/revert.types.js +2 -0
- package/lib/migration/types/settings.types.d.ts +10 -0
- package/lib/migration/types/settings.types.js +2 -0
- package/lib/migration/utils/common.d.ts +32 -0
- package/lib/migration/utils/common.js +129 -0
- package/lib/migration/utils/common.spec.d.ts +1 -0
- package/lib/migration/utils/common.spec.js +196 -0
- package/lib/migration/utils/createMigration.d.ts +9 -0
- package/lib/migration/utils/createMigration.js +122 -0
- package/lib/migration/utils/createMigration.spec.d.ts +1 -0
- package/lib/migration/utils/createMigration.spec.js +276 -0
- package/lib/migration/utils/getMigration.d.ts +2 -0
- package/lib/migration/utils/getMigration.js +41 -0
- package/lib/migration/utils/getMigration.spec.d.ts +1 -0
- package/lib/migration/utils/getMigration.spec.js +156 -0
- package/lib/migration/utils/index.d.ts +7 -0
- package/lib/migration/utils/index.js +23 -0
- package/lib/migration/utils/nextStage.d.ts +2 -0
- package/lib/migration/utils/nextStage.js +44 -0
- package/lib/migration/utils/nextStage.spec.d.ts +1 -0
- package/lib/migration/utils/nextStage.spec.js +151 -0
- package/lib/migration/utils/options.d.ts +12 -0
- package/lib/migration/utils/options.js +82 -0
- package/lib/migration/utils/options.spec.d.ts +1 -0
- package/lib/migration/utils/options.spec.js +115 -0
- package/lib/migration/utils/revertMigration.d.ts +2 -0
- package/lib/migration/utils/revertMigration.js +38 -0
- package/lib/migration/utils/revertMigration.spec.d.ts +1 -0
- package/lib/migration/utils/revertMigration.spec.js +95 -0
- package/lib/migration/utils/setMigrationSettings.d.ts +2 -0
- package/lib/migration/utils/setMigrationSettings.js +53 -0
- package/lib/migration/utils/setMigrationSettings.spec.d.ts +1 -0
- package/lib/migration/utils/setMigrationSettings.spec.js +156 -0
- package/package.json +1 -1
- package/lib/migration/types.d.ts +0 -54
- package/lib/migration/utils.d.ts +0 -15
- package/lib/migration/utils.js +0 -298
- package/lib/migration/utils.spec.js +0 -617
- /package/lib/migration/create/{createMigration.d.ts → create.d.ts} +0 -0
- /package/lib/migration/create/{createMigration.spec.d.ts → create.spec.d.ts} +0 -0
- /package/lib/migration/get/{getMigration.d.ts → get.d.ts} +0 -0
- /package/lib/migration/get/{getMigration.spec.d.ts → get.spec.d.ts} +0 -0
- /package/lib/migration/{settings/setMigrationSettings.spec.d.ts → next/next.spec.d.ts} +0 -0
- /package/lib/migration/settings/{setMigrationSettings.d.ts → settings.d.ts} +0 -0
- /package/lib/migration/{utils.spec.d.ts → settings/settings.spec.d.ts} +0 -0
- /package/lib/migration/{types.js → types/common.types.js} +0 -0
|
@@ -20,11 +20,11 @@ const utils_1 = require("../utils");
|
|
|
20
20
|
const createMigrationCommand = () => {
|
|
21
21
|
const createCommand = new commander_1.Command('create')
|
|
22
22
|
.name('create')
|
|
23
|
-
.description('Create a new migration using the AI Page
|
|
24
|
-
.addOption(
|
|
25
|
-
.addOption(
|
|
26
|
-
.addOption(
|
|
27
|
-
.addOption(
|
|
23
|
+
.description('Create a new migration using the AI Page Migration service')
|
|
24
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.ASSET_ID))
|
|
25
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.PREVIEW_ASSET_ID))
|
|
26
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MATRIX_URL))
|
|
27
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.TENANT, false))
|
|
28
28
|
.argument('<exportPath>', 'Path to the export folder (e.g., ./export)')
|
|
29
29
|
.configureOutput({
|
|
30
30
|
outputError(str, write) {
|
|
@@ -36,14 +36,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const nock_1 = __importDefault(require("nock"));
|
|
39
|
-
const
|
|
40
|
-
const utils = __importStar(require("../utils"));
|
|
39
|
+
const create_1 = __importDefault(require("./create"));
|
|
40
|
+
const utils = __importStar(require("../utils/common"));
|
|
41
41
|
const ApplicationStore = __importStar(require("../../ApplicationStore"));
|
|
42
42
|
const fs_1 = __importDefault(require("fs"));
|
|
43
|
-
|
|
43
|
+
const createMigration = __importStar(require("../utils/createMigration"));
|
|
44
|
+
jest.mock('../utils/common');
|
|
45
|
+
jest.mock('../utils/createMigration');
|
|
44
46
|
jest.mock('../../ApplicationStore');
|
|
45
47
|
jest.mock('fs');
|
|
46
48
|
const mockUtils = utils;
|
|
49
|
+
const mockCreateMigration = createMigration;
|
|
47
50
|
const mockApplicationStore = ApplicationStore;
|
|
48
51
|
const mockFs = fs_1.default;
|
|
49
52
|
describe('createMigrationCommand', () => {
|
|
@@ -56,8 +59,8 @@ describe('createMigrationCommand', () => {
|
|
|
56
59
|
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
57
60
|
mockApplicationStore.getApplicationFile.mockResolvedValue('session-cookie');
|
|
58
61
|
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue(undefined);
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
mockCreateMigration.validateExportFolder.mockImplementation(() => { });
|
|
63
|
+
mockCreateMigration.createTarFile.mockResolvedValue('/path/to/export_123.tar.gz');
|
|
61
64
|
mockUtils.uploadFileToS3.mockResolvedValue('https://s3.amazonaws.com/uploaded-file');
|
|
62
65
|
mockFs.unlinkSync.mockImplementation(() => { });
|
|
63
66
|
mockCreateMigrationResponse = {
|
|
@@ -75,14 +78,14 @@ describe('createMigrationCommand', () => {
|
|
|
75
78
|
},
|
|
76
79
|
uploadUrl: 'https://upload.s3.amazonaws.com',
|
|
77
80
|
};
|
|
78
|
-
|
|
81
|
+
mockCreateMigration.createMigration.mockResolvedValue(mockCreateMigrationResponse);
|
|
79
82
|
});
|
|
80
83
|
afterEach(() => {
|
|
81
84
|
logSpy.mockRestore();
|
|
82
85
|
});
|
|
83
86
|
describe('successful migration creation', () => {
|
|
84
87
|
it('should create migration successfully with all required options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
-
const program = (0,
|
|
88
|
+
const program = (0, create_1.default)();
|
|
86
89
|
yield program.parseAsync([
|
|
87
90
|
'node',
|
|
88
91
|
'dxp-cli',
|
|
@@ -95,24 +98,24 @@ describe('createMigrationCommand', () => {
|
|
|
95
98
|
'/path/to/export',
|
|
96
99
|
]);
|
|
97
100
|
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
98
|
-
expect(
|
|
99
|
-
expect(
|
|
100
|
-
expect(
|
|
101
|
+
expect(mockCreateMigration.validateExportFolder).toHaveBeenCalledWith('/path/to/export');
|
|
102
|
+
expect(mockCreateMigration.createTarFile).toHaveBeenCalledWith('/path/to/export');
|
|
103
|
+
expect(mockCreateMigration.createMigration).toHaveBeenCalledWith({
|
|
101
104
|
assetId: 'asset-123',
|
|
102
105
|
previewAssetId: 'preview-456',
|
|
103
106
|
matrixUrl: 'https://matrix.example.com',
|
|
104
107
|
});
|
|
105
108
|
expect(mockUtils.uploadFileToS3).toHaveBeenCalledWith('https://upload.s3.amazonaws.com', '/path/to/export_123.tar.gz', undefined);
|
|
106
109
|
expect(mockFs.unlinkSync).toHaveBeenCalledWith('/path/to/export_123.tar.gz');
|
|
107
|
-
expect(
|
|
108
|
-
expect(
|
|
109
|
-
expect(
|
|
110
|
+
expect(mockCreateMigration.validateExportFolder).toHaveBeenCalledTimes(1);
|
|
111
|
+
expect(mockCreateMigration.createTarFile).toHaveBeenCalledTimes(1);
|
|
112
|
+
expect(mockCreateMigration.createMigration).toHaveBeenCalledTimes(1);
|
|
110
113
|
expect(mockUtils.uploadFileToS3).toHaveBeenCalledTimes(1);
|
|
111
114
|
expect(mockFs.unlinkSync).toHaveBeenCalledTimes(1);
|
|
112
115
|
expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
|
|
113
116
|
}));
|
|
114
117
|
it('should create migration with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
-
const program = (0,
|
|
118
|
+
const program = (0, create_1.default)();
|
|
116
119
|
yield program.parseAsync([
|
|
117
120
|
'node',
|
|
118
121
|
'dxp-cli',
|
|
@@ -126,7 +129,7 @@ describe('createMigrationCommand', () => {
|
|
|
126
129
|
'test-tenant',
|
|
127
130
|
'/path/to/export',
|
|
128
131
|
]);
|
|
129
|
-
expect(
|
|
132
|
+
expect(mockCreateMigration.createMigration).toHaveBeenCalledWith({
|
|
130
133
|
assetId: 'asset-123',
|
|
131
134
|
previewAssetId: 'preview-456',
|
|
132
135
|
matrixUrl: 'https://matrix.example.com',
|
|
@@ -137,7 +140,7 @@ describe('createMigrationCommand', () => {
|
|
|
137
140
|
it('should create migration with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
141
|
const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
|
|
139
142
|
process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
|
|
140
|
-
const program = (0,
|
|
143
|
+
const program = (0, create_1.default)();
|
|
141
144
|
yield program.parseAsync([
|
|
142
145
|
'node',
|
|
143
146
|
'dxp-cli',
|
|
@@ -151,7 +154,7 @@ describe('createMigrationCommand', () => {
|
|
|
151
154
|
'https://custom.migration.url',
|
|
152
155
|
'/path/to/export',
|
|
153
156
|
]);
|
|
154
|
-
expect(
|
|
157
|
+
expect(mockCreateMigration.createMigration).toHaveBeenCalledWith({
|
|
155
158
|
assetId: 'asset-123',
|
|
156
159
|
previewAssetId: 'preview-456',
|
|
157
160
|
matrixUrl: 'https://matrix.example.com',
|
|
@@ -163,11 +166,11 @@ describe('createMigrationCommand', () => {
|
|
|
163
166
|
describe('error scenarios', () => {
|
|
164
167
|
it('should handle validation error for export folder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
168
|
const validationError = new Error('Export folder does not exist');
|
|
166
|
-
|
|
169
|
+
mockCreateMigration.validateExportFolder.mockImplementation(() => {
|
|
167
170
|
throw validationError;
|
|
168
171
|
});
|
|
169
172
|
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
170
|
-
const program = (0,
|
|
173
|
+
const program = (0, create_1.default)();
|
|
171
174
|
yield program.parseAsync([
|
|
172
175
|
'node',
|
|
173
176
|
'dxp-cli',
|
|
@@ -180,11 +183,11 @@ describe('createMigrationCommand', () => {
|
|
|
180
183
|
'/invalid/path',
|
|
181
184
|
]);
|
|
182
185
|
expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, validationError);
|
|
183
|
-
expect(
|
|
186
|
+
expect(mockCreateMigration.createTarFile).not.toHaveBeenCalled();
|
|
184
187
|
}));
|
|
185
188
|
it('should handle tar file creation failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
186
|
-
|
|
187
|
-
const program = (0,
|
|
189
|
+
mockCreateMigration.createTarFile.mockResolvedValue(null);
|
|
190
|
+
const program = (0, create_1.default)();
|
|
188
191
|
yield program.parseAsync([
|
|
189
192
|
'node',
|
|
190
193
|
'dxp-cli',
|
|
@@ -196,12 +199,12 @@ describe('createMigrationCommand', () => {
|
|
|
196
199
|
'https://matrix.example.com',
|
|
197
200
|
'/path/to/export',
|
|
198
201
|
]);
|
|
199
|
-
expect(
|
|
202
|
+
expect(mockCreateMigration.createMigration).not.toHaveBeenCalled();
|
|
200
203
|
expect(mockUtils.uploadFileToS3).not.toHaveBeenCalled();
|
|
201
204
|
}));
|
|
202
205
|
it('should handle migration creation failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
203
|
-
|
|
204
|
-
const program = (0,
|
|
206
|
+
mockCreateMigration.createMigration.mockResolvedValue(null);
|
|
207
|
+
const program = (0, create_1.default)();
|
|
205
208
|
yield program.parseAsync([
|
|
206
209
|
'node',
|
|
207
210
|
'dxp-cli',
|
|
@@ -218,7 +221,7 @@ describe('createMigrationCommand', () => {
|
|
|
218
221
|
}));
|
|
219
222
|
it('should handle S3 upload failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
220
223
|
mockUtils.uploadFileToS3.mockResolvedValue(null);
|
|
221
|
-
const program = (0,
|
|
224
|
+
const program = (0, create_1.default)();
|
|
222
225
|
yield program.parseAsync([
|
|
223
226
|
'node',
|
|
224
227
|
'dxp-cli',
|
|
@@ -234,9 +237,9 @@ describe('createMigrationCommand', () => {
|
|
|
234
237
|
}));
|
|
235
238
|
it('should handle migration API error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
236
239
|
const apiError = new Error('Migration API failed');
|
|
237
|
-
|
|
240
|
+
mockCreateMigration.createMigration.mockRejectedValue(apiError);
|
|
238
241
|
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
239
|
-
const program = (0,
|
|
242
|
+
const program = (0, create_1.default)();
|
|
240
243
|
yield program.parseAsync([
|
|
241
244
|
'node',
|
|
242
245
|
'dxp-cli',
|
|
@@ -255,7 +258,7 @@ describe('createMigrationCommand', () => {
|
|
|
255
258
|
mockUtils.throwErrorIfNotLoggedIn.mockImplementation(() => {
|
|
256
259
|
throw loginError;
|
|
257
260
|
});
|
|
258
|
-
const program = (0,
|
|
261
|
+
const program = (0, create_1.default)();
|
|
259
262
|
yield expect(program.parseAsync([
|
|
260
263
|
'node',
|
|
261
264
|
'dxp-cli',
|
|
@@ -267,12 +270,12 @@ describe('createMigrationCommand', () => {
|
|
|
267
270
|
'https://matrix.example.com',
|
|
268
271
|
'/path/to/export',
|
|
269
272
|
])).rejects.toThrow('Not logged in');
|
|
270
|
-
expect(
|
|
273
|
+
expect(mockCreateMigration.validateExportFolder).not.toHaveBeenCalled();
|
|
271
274
|
}));
|
|
272
275
|
});
|
|
273
276
|
describe('required options validation', () => {
|
|
274
277
|
it('should require assetid option', () => {
|
|
275
|
-
const program = (0,
|
|
278
|
+
const program = (0, create_1.default)().exitOverride();
|
|
276
279
|
expect(() => {
|
|
277
280
|
program.parse([
|
|
278
281
|
'node',
|
|
@@ -286,7 +289,7 @@ describe('createMigrationCommand', () => {
|
|
|
286
289
|
}).toThrow();
|
|
287
290
|
});
|
|
288
291
|
it('should require previewAssetid option', () => {
|
|
289
|
-
const program = (0,
|
|
292
|
+
const program = (0, create_1.default)().exitOverride();
|
|
290
293
|
expect(() => {
|
|
291
294
|
program.parse([
|
|
292
295
|
'node',
|
|
@@ -300,7 +303,7 @@ describe('createMigrationCommand', () => {
|
|
|
300
303
|
}).toThrow();
|
|
301
304
|
});
|
|
302
305
|
it('should require matrixUrl option', () => {
|
|
303
|
-
const program = (0,
|
|
306
|
+
const program = (0, create_1.default)().exitOverride();
|
|
304
307
|
expect(() => {
|
|
305
308
|
program.parse([
|
|
306
309
|
'node',
|
|
@@ -314,7 +317,7 @@ describe('createMigrationCommand', () => {
|
|
|
314
317
|
}).toThrow();
|
|
315
318
|
});
|
|
316
319
|
it('should require exportPath argument', () => {
|
|
317
|
-
const program = (0,
|
|
320
|
+
const program = (0, create_1.default)().exitOverride();
|
|
318
321
|
expect(() => {
|
|
319
322
|
program.parse([
|
|
320
323
|
'node',
|
|
@@ -331,12 +334,12 @@ describe('createMigrationCommand', () => {
|
|
|
331
334
|
});
|
|
332
335
|
describe('command configuration', () => {
|
|
333
336
|
it('should have correct command name and description', () => {
|
|
334
|
-
const program = (0,
|
|
337
|
+
const program = (0, create_1.default)();
|
|
335
338
|
expect(program.name()).toBe('create');
|
|
336
|
-
expect(program.description()).toBe('Create a new migration using the AI Page
|
|
339
|
+
expect(program.description()).toBe('Create a new migration using the AI Page Migration service');
|
|
337
340
|
});
|
|
338
341
|
it('should parse options correctly', () => {
|
|
339
|
-
const program = (0,
|
|
342
|
+
const program = (0, create_1.default)();
|
|
340
343
|
program.parse([
|
|
341
344
|
'node',
|
|
342
345
|
'dxp-cli',
|
|
@@ -359,7 +362,7 @@ describe('createMigrationCommand', () => {
|
|
|
359
362
|
});
|
|
360
363
|
describe('spinner and output behavior', () => {
|
|
361
364
|
it('should display appropriate spinner messages during execution', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
362
|
-
const program = (0,
|
|
365
|
+
const program = (0, create_1.default)();
|
|
363
366
|
yield program.parseAsync([
|
|
364
367
|
'node',
|
|
365
368
|
'dxp-cli',
|
|
@@ -371,9 +374,9 @@ describe('createMigrationCommand', () => {
|
|
|
371
374
|
'https://matrix.example.com',
|
|
372
375
|
'/path/to/export',
|
|
373
376
|
]);
|
|
374
|
-
expect(
|
|
375
|
-
expect(
|
|
376
|
-
expect(
|
|
377
|
+
expect(mockCreateMigration.validateExportFolder).toHaveBeenCalledWith('/path/to/export');
|
|
378
|
+
expect(mockCreateMigration.createTarFile).toHaveBeenCalledWith('/path/to/export');
|
|
379
|
+
expect(mockCreateMigration.createMigration).toHaveBeenCalled();
|
|
377
380
|
expect(mockUtils.uploadFileToS3).toHaveBeenCalled();
|
|
378
381
|
expect(mockFs.unlinkSync).toHaveBeenCalled();
|
|
379
382
|
}));
|
|
@@ -20,9 +20,9 @@ const getMigrationCommand = () => {
|
|
|
20
20
|
const getCommand = new commander_1.Command('get')
|
|
21
21
|
.name('get')
|
|
22
22
|
.description('Get a migration using the AI Page migration service')
|
|
23
|
-
.addOption(
|
|
24
|
-
.addOption(
|
|
25
|
-
.addOption(
|
|
23
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MIGRATION_ID))
|
|
24
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.ASSET_ID, false))
|
|
25
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.TENANT, false))
|
|
26
26
|
.configureOutput({
|
|
27
27
|
outputError(str, write) {
|
|
28
28
|
write(chalk_1.default.red(str));
|
|
@@ -40,9 +40,7 @@ const getMigrationCommand = () => {
|
|
|
40
40
|
(0, utils_1.handleCommandError)(getCommand, error);
|
|
41
41
|
}
|
|
42
42
|
}));
|
|
43
|
-
|
|
44
|
-
getCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire migration url with a custom value'));
|
|
45
|
-
}
|
|
43
|
+
(0, utils_1.addOverrideUrlOption)(getCommand);
|
|
46
44
|
return getCommand;
|
|
47
45
|
};
|
|
48
46
|
exports.default = getMigrationCommand;
|
|
@@ -36,12 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const nock_1 = __importDefault(require("nock"));
|
|
39
|
-
const
|
|
40
|
-
const utils = __importStar(require("../utils"));
|
|
39
|
+
const get_1 = __importDefault(require("./get"));
|
|
40
|
+
const utils = __importStar(require("../utils/common"));
|
|
41
41
|
const ApplicationStore = __importStar(require("../../ApplicationStore"));
|
|
42
|
-
|
|
42
|
+
const getMigration = __importStar(require("../utils/getMigration"));
|
|
43
|
+
jest.mock('../utils/common');
|
|
44
|
+
jest.mock('../utils/getMigration');
|
|
43
45
|
jest.mock('../../ApplicationStore');
|
|
44
46
|
const mockUtils = utils;
|
|
47
|
+
const mockGetMigration = getMigration;
|
|
45
48
|
const mockApplicationStore = ApplicationStore;
|
|
46
49
|
describe('getMigrationCommand', () => {
|
|
47
50
|
let logSpy;
|
|
@@ -56,20 +59,26 @@ describe('getMigrationCommand', () => {
|
|
|
56
59
|
mockGetMigrationResponse = {
|
|
57
60
|
migrationId: 'migration-123',
|
|
58
61
|
assetId: 'asset-456',
|
|
62
|
+
xmlFilePath: 'https://download.example.com/xml.zip',
|
|
63
|
+
matrixUrl: 'https://matrix.example.com',
|
|
64
|
+
previewAssetId: 'preview-789',
|
|
65
|
+
created: 1718230800,
|
|
66
|
+
updated: 1718230800,
|
|
67
|
+
migrationIdAssetId: 'migration-123-asset-456',
|
|
59
68
|
stage: 'completed',
|
|
60
69
|
status: 'success',
|
|
61
|
-
|
|
70
|
+
stageDetails: 'Migration completed successfully',
|
|
62
71
|
previewPageAssetId: 'preview-789',
|
|
63
|
-
|
|
72
|
+
componentsTarDownloadUrl: 'https://download.example.com/components.zip',
|
|
64
73
|
};
|
|
65
|
-
|
|
74
|
+
mockGetMigration.getMigration.mockResolvedValue(mockGetMigrationResponse);
|
|
66
75
|
});
|
|
67
76
|
afterEach(() => {
|
|
68
77
|
logSpy.mockRestore();
|
|
69
78
|
});
|
|
70
79
|
describe('successful migration retrieval', () => {
|
|
71
80
|
it('should get migration successfully with required options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
-
const program = (0,
|
|
81
|
+
const program = (0, get_1.default)();
|
|
73
82
|
yield program.parseAsync([
|
|
74
83
|
'node',
|
|
75
84
|
'dxp-cli',
|
|
@@ -79,15 +88,15 @@ describe('getMigrationCommand', () => {
|
|
|
79
88
|
'asset-456',
|
|
80
89
|
]);
|
|
81
90
|
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
82
|
-
expect(
|
|
91
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalledWith({
|
|
83
92
|
migrationId: 'migration-123',
|
|
84
93
|
assetId: 'asset-456',
|
|
85
94
|
});
|
|
86
|
-
expect(
|
|
95
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalledTimes(1);
|
|
87
96
|
expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
|
|
88
97
|
}));
|
|
89
98
|
it('should get migration with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
-
const program = (0,
|
|
99
|
+
const program = (0, get_1.default)();
|
|
91
100
|
yield program.parseAsync([
|
|
92
101
|
'node',
|
|
93
102
|
'dxp-cli',
|
|
@@ -98,7 +107,7 @@ describe('getMigrationCommand', () => {
|
|
|
98
107
|
'--tenant',
|
|
99
108
|
'test-tenant',
|
|
100
109
|
]);
|
|
101
|
-
expect(
|
|
110
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalledWith({
|
|
102
111
|
migrationId: 'migration-123',
|
|
103
112
|
assetId: 'asset-456',
|
|
104
113
|
tenant: 'test-tenant',
|
|
@@ -107,7 +116,7 @@ describe('getMigrationCommand', () => {
|
|
|
107
116
|
it('should get migration with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
117
|
const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
|
|
109
118
|
process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
|
|
110
|
-
const program = (0,
|
|
119
|
+
const program = (0, get_1.default)();
|
|
111
120
|
yield program.parseAsync([
|
|
112
121
|
'node',
|
|
113
122
|
'dxp-cli',
|
|
@@ -118,7 +127,7 @@ describe('getMigrationCommand', () => {
|
|
|
118
127
|
'--overrideUrl',
|
|
119
128
|
'https://custom.migration.url',
|
|
120
129
|
]);
|
|
121
|
-
expect(
|
|
130
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalledWith({
|
|
122
131
|
migrationId: 'migration-123',
|
|
123
132
|
assetId: 'asset-456',
|
|
124
133
|
overrideUrl: 'https://custom.migration.url',
|
|
@@ -126,14 +135,14 @@ describe('getMigrationCommand', () => {
|
|
|
126
135
|
process.env.ENABLE_OVERRIDE_MIGRATION_URL = originalEnv;
|
|
127
136
|
}));
|
|
128
137
|
it('should get migration without asset-id option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
-
const program = (0,
|
|
138
|
+
const program = (0, get_1.default)();
|
|
130
139
|
yield program.parseAsync([
|
|
131
140
|
'node',
|
|
132
141
|
'dxp-cli',
|
|
133
142
|
'--migration-id',
|
|
134
143
|
'migration-123',
|
|
135
144
|
]);
|
|
136
|
-
expect(
|
|
145
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalledWith({
|
|
137
146
|
migrationId: 'migration-123',
|
|
138
147
|
});
|
|
139
148
|
}));
|
|
@@ -141,9 +150,9 @@ describe('getMigrationCommand', () => {
|
|
|
141
150
|
describe('error scenarios', () => {
|
|
142
151
|
it('should handle getMigration API error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
152
|
const apiError = new Error('Migration not found');
|
|
144
|
-
|
|
153
|
+
mockGetMigration.getMigration.mockRejectedValue(apiError);
|
|
145
154
|
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
146
|
-
const program = (0,
|
|
155
|
+
const program = (0, get_1.default)();
|
|
147
156
|
yield program.parseAsync([
|
|
148
157
|
'node',
|
|
149
158
|
'dxp-cli',
|
|
@@ -156,9 +165,9 @@ describe('getMigrationCommand', () => {
|
|
|
156
165
|
}));
|
|
157
166
|
it('should handle network error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
158
167
|
const networkError = new Error('Network connection failed');
|
|
159
|
-
|
|
168
|
+
mockGetMigration.getMigration.mockRejectedValue(networkError);
|
|
160
169
|
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
161
|
-
const program = (0,
|
|
170
|
+
const program = (0, get_1.default)();
|
|
162
171
|
yield program.parseAsync([
|
|
163
172
|
'node',
|
|
164
173
|
'dxp-cli',
|
|
@@ -172,13 +181,13 @@ describe('getMigrationCommand', () => {
|
|
|
172
181
|
});
|
|
173
182
|
describe('required options validation', () => {
|
|
174
183
|
it('should require migration-id option', () => {
|
|
175
|
-
const program = (0,
|
|
184
|
+
const program = (0, get_1.default)().exitOverride();
|
|
176
185
|
expect(() => {
|
|
177
186
|
program.parse(['node', 'dxp-cli', '--asset-id', 'asset-456']);
|
|
178
187
|
}).toThrow();
|
|
179
188
|
});
|
|
180
189
|
it('should not require asset-id option', () => {
|
|
181
|
-
const program = (0,
|
|
190
|
+
const program = (0, get_1.default)().exitOverride();
|
|
182
191
|
expect(() => {
|
|
183
192
|
program.parse(['node', 'dxp-cli', '--migration-id', 'migration-123']);
|
|
184
193
|
}).not.toThrow();
|
|
@@ -186,12 +195,12 @@ describe('getMigrationCommand', () => {
|
|
|
186
195
|
});
|
|
187
196
|
describe('command configuration', () => {
|
|
188
197
|
it('should have correct command name and description', () => {
|
|
189
|
-
const program = (0,
|
|
198
|
+
const program = (0, get_1.default)();
|
|
190
199
|
expect(program.name()).toBe('get');
|
|
191
200
|
expect(program.description()).toBe('Get a migration using the AI Page migration service');
|
|
192
201
|
});
|
|
193
202
|
it('should parse options correctly', () => {
|
|
194
|
-
const program = (0,
|
|
203
|
+
const program = (0, get_1.default)();
|
|
195
204
|
program.parse([
|
|
196
205
|
'node',
|
|
197
206
|
'dxp-cli',
|
|
@@ -208,7 +217,7 @@ describe('getMigrationCommand', () => {
|
|
|
208
217
|
expect(opts.tenant).toBe('test-tenant');
|
|
209
218
|
});
|
|
210
219
|
it('should parse options with kebab-case to camelCase conversion', () => {
|
|
211
|
-
const program = (0,
|
|
220
|
+
const program = (0, get_1.default)();
|
|
212
221
|
program.parse([
|
|
213
222
|
'node',
|
|
214
223
|
'dxp-cli',
|
|
@@ -224,7 +233,7 @@ describe('getMigrationCommand', () => {
|
|
|
224
233
|
});
|
|
225
234
|
describe('spinner and output behavior', () => {
|
|
226
235
|
it('should display appropriate spinner messages during execution', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
227
|
-
const program = (0,
|
|
236
|
+
const program = (0, get_1.default)();
|
|
228
237
|
yield program.parseAsync([
|
|
229
238
|
'node',
|
|
230
239
|
'dxp-cli',
|
|
@@ -234,10 +243,10 @@ describe('getMigrationCommand', () => {
|
|
|
234
243
|
'asset-456',
|
|
235
244
|
]);
|
|
236
245
|
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
237
|
-
expect(
|
|
246
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalled();
|
|
238
247
|
}));
|
|
239
248
|
it('should format output correctly', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
240
|
-
const program = (0,
|
|
249
|
+
const program = (0, get_1.default)();
|
|
241
250
|
yield program.parseAsync([
|
|
242
251
|
'node',
|
|
243
252
|
'dxp-cli',
|
|
@@ -246,7 +255,7 @@ describe('getMigrationCommand', () => {
|
|
|
246
255
|
'--asset-id',
|
|
247
256
|
'asset-456',
|
|
248
257
|
]);
|
|
249
|
-
expect(
|
|
258
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalledWith({
|
|
250
259
|
migrationId: 'migration-123',
|
|
251
260
|
assetId: 'asset-456',
|
|
252
261
|
});
|
|
@@ -256,7 +265,7 @@ describe('getMigrationCommand', () => {
|
|
|
256
265
|
it('should work with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
266
|
const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
|
|
258
267
|
process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
|
|
259
|
-
const program = (0,
|
|
268
|
+
const program = (0, get_1.default)();
|
|
260
269
|
yield program.parseAsync([
|
|
261
270
|
'node',
|
|
262
271
|
'dxp-cli',
|
|
@@ -267,7 +276,7 @@ describe('getMigrationCommand', () => {
|
|
|
267
276
|
'--overrideUrl',
|
|
268
277
|
'https://custom.migration.url',
|
|
269
278
|
]);
|
|
270
|
-
expect(
|
|
279
|
+
expect(mockGetMigration.getMigration).toHaveBeenCalledWith({
|
|
271
280
|
migrationId: 'migration-123',
|
|
272
281
|
assetId: 'asset-456',
|
|
273
282
|
overrideUrl: 'https://custom.migration.url',
|
package/lib/migration/index.js
CHANGED
|
@@ -4,15 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const commander_1 = require("commander");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const create_1 = __importDefault(require("./create/create"));
|
|
8
|
+
const get_1 = __importDefault(require("./get/get"));
|
|
9
|
+
const next_1 = __importDefault(require("./next/next"));
|
|
10
|
+
const settings_1 = __importDefault(require("./settings/settings"));
|
|
9
11
|
const revert_1 = __importDefault(require("./revert/revert"));
|
|
10
|
-
const setMigrationSettings_1 = __importDefault(require("./settings/setMigrationSettings"));
|
|
11
12
|
const migrationCommand = new commander_1.Command('migration');
|
|
12
13
|
migrationCommand
|
|
13
14
|
.description('AI Page Migration Service Commands')
|
|
14
|
-
.addCommand((0,
|
|
15
|
-
.addCommand((0,
|
|
16
|
-
.addCommand((0,
|
|
17
|
-
.addCommand((0,
|
|
15
|
+
.addCommand((0, create_1.default)())
|
|
16
|
+
.addCommand((0, get_1.default)())
|
|
17
|
+
.addCommand((0, next_1.default)())
|
|
18
|
+
.addCommand((0, settings_1.default)())
|
|
19
|
+
.addCommand((0, revert_1.default)());
|
|
18
20
|
exports.default = migrationCommand;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const commander_1 = require("commander");
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const ora_1 = __importDefault(require("ora"));
|
|
18
|
+
const utils_1 = require("../utils");
|
|
19
|
+
const nextStageCommand = () => {
|
|
20
|
+
const nextCommand = new commander_1.Command('next')
|
|
21
|
+
.name('next')
|
|
22
|
+
.description('Triggers the next step of the migration, which will be decided based on the current asset migration stage and status')
|
|
23
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MIGRATION_ID))
|
|
24
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.ASSET_ID))
|
|
25
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.TENANT, false))
|
|
26
|
+
.configureOutput({
|
|
27
|
+
outputError(str, write) {
|
|
28
|
+
write(chalk_1.default.red(str));
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(nextCommand);
|
|
33
|
+
const spinner = (0, ora_1.default)('Starting next stage').start();
|
|
34
|
+
try {
|
|
35
|
+
const response = yield (0, utils_1.nextStage)(options);
|
|
36
|
+
spinner.succeed(response.message);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
spinner.fail();
|
|
40
|
+
(0, utils_1.handleCommandError)(nextCommand, error);
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
(0, utils_1.addOverrideUrlOption)(nextCommand);
|
|
44
|
+
return nextCommand;
|
|
45
|
+
};
|
|
46
|
+
exports.default = nextStageCommand;
|