@squiz/dxp-cli-next 5.28.0-develop.1 → 5.28.0-develop.2
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.
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const commander_1 = require("commander");
|
|
16
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
17
|
const ora_1 = __importDefault(require("ora"));
|
|
18
|
-
const fs_1 = __importDefault(require("fs"));
|
|
19
18
|
const utils_1 = require("../utils");
|
|
20
19
|
const createMigrationCommand = () => {
|
|
21
20
|
const createCommand = new commander_1.Command('create')
|
|
@@ -25,28 +24,16 @@ const createMigrationCommand = () => {
|
|
|
25
24
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.PREVIEW_ASSET_ID))
|
|
26
25
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MATRIX_URL))
|
|
27
26
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.TENANT, false))
|
|
28
|
-
.argument('<exportPath>', 'Path to the export folder (e.g., ./export)')
|
|
29
27
|
.configureOutput({
|
|
30
28
|
outputError(str, write) {
|
|
31
29
|
write(chalk_1.default.red(str));
|
|
32
30
|
},
|
|
33
31
|
})
|
|
34
|
-
.action((
|
|
32
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
33
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(createCommand);
|
|
36
|
-
let spinner = (0, ora_1.default)('
|
|
34
|
+
let spinner = (0, ora_1.default)('Creating migration').start();
|
|
37
35
|
try {
|
|
38
|
-
// Validate export folder structure
|
|
39
|
-
(0, utils_1.validateExportFolder)(exportPath);
|
|
40
|
-
spinner.succeed('Export folder structure validated');
|
|
41
|
-
// Create tar file
|
|
42
|
-
spinner = (0, ora_1.default)('Creating tar file from export folder').start();
|
|
43
|
-
const tarFilePath = yield (0, utils_1.createTarFile)(exportPath);
|
|
44
|
-
if (!tarFilePath) {
|
|
45
|
-
throw new Error('Tar file creation failed');
|
|
46
|
-
}
|
|
47
|
-
spinner.succeed(`Tar file created: ${tarFilePath}`);
|
|
48
36
|
// Create migration
|
|
49
|
-
spinner = (0, ora_1.default)('Creating migration').start();
|
|
50
37
|
const response = yield (0, utils_1.createMigration)(options);
|
|
51
38
|
if (!response) {
|
|
52
39
|
throw new Error('Migration creation failed');
|
|
@@ -54,14 +41,6 @@ const createMigrationCommand = () => {
|
|
|
54
41
|
spinner.succeed('Migration created successfully');
|
|
55
42
|
// Upload file to S3
|
|
56
43
|
spinner = (0, ora_1.default)('Uploading file to S3').start();
|
|
57
|
-
const uploadUrl = response.uploadUrl;
|
|
58
|
-
const s3Url = yield (0, utils_1.uploadFileToS3)(uploadUrl, tarFilePath, options.tenant);
|
|
59
|
-
if (!s3Url) {
|
|
60
|
-
throw new Error('File upload failed');
|
|
61
|
-
}
|
|
62
|
-
spinner.succeed('File uploaded to S3');
|
|
63
|
-
// Clean up tar file
|
|
64
|
-
fs_1.default.unlinkSync(tarFilePath);
|
|
65
44
|
spinner.succeed(`Successfully created migration: ${JSON.stringify({
|
|
66
45
|
migrationId: response.assetMigration.migrationId,
|
|
67
46
|
assetId: response.assetMigration.assetId,
|
|
@@ -38,17 +38,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
38
38
|
const nock_1 = __importDefault(require("nock"));
|
|
39
39
|
const create_1 = __importDefault(require("./create"));
|
|
40
40
|
const utils = __importStar(require("../utils/common"));
|
|
41
|
-
const ApplicationStore = __importStar(require("../../ApplicationStore"));
|
|
42
|
-
const fs_1 = __importDefault(require("fs"));
|
|
43
41
|
const createMigration = __importStar(require("../utils/createMigration"));
|
|
44
42
|
jest.mock('../utils/common');
|
|
45
43
|
jest.mock('../utils/createMigration');
|
|
46
|
-
jest.mock('../../ApplicationStore');
|
|
47
|
-
jest.mock('fs');
|
|
48
44
|
const mockUtils = utils;
|
|
49
45
|
const mockCreateMigration = createMigration;
|
|
50
|
-
const mockApplicationStore = ApplicationStore;
|
|
51
|
-
const mockFs = fs_1.default;
|
|
52
46
|
describe('createMigrationCommand', () => {
|
|
53
47
|
let logSpy;
|
|
54
48
|
let mockCreateMigrationResponse;
|
|
@@ -57,12 +51,7 @@ describe('createMigrationCommand', () => {
|
|
|
57
51
|
jest.clearAllMocks();
|
|
58
52
|
jest.resetAllMocks();
|
|
59
53
|
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
60
|
-
mockApplicationStore.getApplicationFile.mockResolvedValue('session-cookie');
|
|
61
54
|
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue(undefined);
|
|
62
|
-
mockCreateMigration.validateExportFolder.mockImplementation(() => { });
|
|
63
|
-
mockCreateMigration.createTarFile.mockResolvedValue('/path/to/export_123.tar.gz');
|
|
64
|
-
mockUtils.uploadFileToS3.mockResolvedValue('https://s3.amazonaws.com/uploaded-file');
|
|
65
|
-
mockFs.unlinkSync.mockImplementation(() => { });
|
|
66
55
|
mockCreateMigrationResponse = {
|
|
67
56
|
assetMigration: {
|
|
68
57
|
migrationId: 'migration-123',
|
|
@@ -95,23 +84,14 @@ describe('createMigrationCommand', () => {
|
|
|
95
84
|
'preview-456',
|
|
96
85
|
'--matrix-url',
|
|
97
86
|
'https://matrix.example.com',
|
|
98
|
-
'/path/to/export',
|
|
99
87
|
]);
|
|
100
88
|
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
101
|
-
expect(mockCreateMigration.validateExportFolder).toHaveBeenCalledWith('/path/to/export');
|
|
102
|
-
expect(mockCreateMigration.createTarFile).toHaveBeenCalledWith('/path/to/export');
|
|
103
89
|
expect(mockCreateMigration.createMigration).toHaveBeenCalledWith({
|
|
104
90
|
assetId: 'asset-123',
|
|
105
91
|
previewAssetId: 'preview-456',
|
|
106
92
|
matrixUrl: 'https://matrix.example.com',
|
|
107
93
|
});
|
|
108
|
-
expect(mockUtils.uploadFileToS3).toHaveBeenCalledWith('https://upload.s3.amazonaws.com', '/path/to/export_123.tar.gz', undefined);
|
|
109
|
-
expect(mockFs.unlinkSync).toHaveBeenCalledWith('/path/to/export_123.tar.gz');
|
|
110
|
-
expect(mockCreateMigration.validateExportFolder).toHaveBeenCalledTimes(1);
|
|
111
|
-
expect(mockCreateMigration.createTarFile).toHaveBeenCalledTimes(1);
|
|
112
94
|
expect(mockCreateMigration.createMigration).toHaveBeenCalledTimes(1);
|
|
113
|
-
expect(mockUtils.uploadFileToS3).toHaveBeenCalledTimes(1);
|
|
114
|
-
expect(mockFs.unlinkSync).toHaveBeenCalledTimes(1);
|
|
115
95
|
expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
|
|
116
96
|
}));
|
|
117
97
|
it('should create migration with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -127,7 +107,6 @@ describe('createMigrationCommand', () => {
|
|
|
127
107
|
'https://matrix.example.com',
|
|
128
108
|
'--tenant',
|
|
129
109
|
'test-tenant',
|
|
130
|
-
'/path/to/export',
|
|
131
110
|
]);
|
|
132
111
|
expect(mockCreateMigration.createMigration).toHaveBeenCalledWith({
|
|
133
112
|
assetId: 'asset-123',
|
|
@@ -135,7 +114,6 @@ describe('createMigrationCommand', () => {
|
|
|
135
114
|
matrixUrl: 'https://matrix.example.com',
|
|
136
115
|
tenant: 'test-tenant',
|
|
137
116
|
});
|
|
138
|
-
expect(mockUtils.uploadFileToS3).toHaveBeenCalledWith('https://upload.s3.amazonaws.com', '/path/to/export_123.tar.gz', 'test-tenant');
|
|
139
117
|
}));
|
|
140
118
|
it('should create migration with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
119
|
const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
|
|
@@ -152,7 +130,6 @@ describe('createMigrationCommand', () => {
|
|
|
152
130
|
'https://matrix.example.com',
|
|
153
131
|
'--overrideUrl',
|
|
154
132
|
'https://custom.migration.url',
|
|
155
|
-
'/path/to/export',
|
|
156
133
|
]);
|
|
157
134
|
expect(mockCreateMigration.createMigration).toHaveBeenCalledWith({
|
|
158
135
|
assetId: 'asset-123',
|
|
@@ -164,46 +141,9 @@ describe('createMigrationCommand', () => {
|
|
|
164
141
|
}));
|
|
165
142
|
});
|
|
166
143
|
describe('error scenarios', () => {
|
|
167
|
-
it('should handle validation error for export folder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
168
|
-
const validationError = new Error('Export folder does not exist');
|
|
169
|
-
mockCreateMigration.validateExportFolder.mockImplementation(() => {
|
|
170
|
-
throw validationError;
|
|
171
|
-
});
|
|
172
|
-
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
173
|
-
const program = (0, create_1.default)();
|
|
174
|
-
yield program.parseAsync([
|
|
175
|
-
'node',
|
|
176
|
-
'dxp-cli',
|
|
177
|
-
'--asset-id',
|
|
178
|
-
'asset-123',
|
|
179
|
-
'--preview-asset-id',
|
|
180
|
-
'preview-456',
|
|
181
|
-
'--matrix-url',
|
|
182
|
-
'https://matrix.example.com',
|
|
183
|
-
'/invalid/path',
|
|
184
|
-
]);
|
|
185
|
-
expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, validationError);
|
|
186
|
-
expect(mockCreateMigration.createTarFile).not.toHaveBeenCalled();
|
|
187
|
-
}));
|
|
188
|
-
it('should handle tar file creation failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
189
|
-
mockCreateMigration.createTarFile.mockResolvedValue(null);
|
|
190
|
-
const program = (0, create_1.default)();
|
|
191
|
-
yield program.parseAsync([
|
|
192
|
-
'node',
|
|
193
|
-
'dxp-cli',
|
|
194
|
-
'--asset-id',
|
|
195
|
-
'asset-123',
|
|
196
|
-
'--preview-asset-id',
|
|
197
|
-
'preview-456',
|
|
198
|
-
'--matrix-url',
|
|
199
|
-
'https://matrix.example.com',
|
|
200
|
-
'/path/to/export',
|
|
201
|
-
]);
|
|
202
|
-
expect(mockCreateMigration.createMigration).not.toHaveBeenCalled();
|
|
203
|
-
expect(mockUtils.uploadFileToS3).not.toHaveBeenCalled();
|
|
204
|
-
}));
|
|
205
144
|
it('should handle migration creation failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
206
145
|
mockCreateMigration.createMigration.mockResolvedValue(null);
|
|
146
|
+
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
207
147
|
const program = (0, create_1.default)();
|
|
208
148
|
yield program.parseAsync([
|
|
209
149
|
'node',
|
|
@@ -214,26 +154,8 @@ describe('createMigrationCommand', () => {
|
|
|
214
154
|
'preview-456',
|
|
215
155
|
'--matrix-url',
|
|
216
156
|
'https://matrix.example.com',
|
|
217
|
-
'/path/to/export',
|
|
218
|
-
]);
|
|
219
|
-
expect(mockUtils.uploadFileToS3).not.toHaveBeenCalled();
|
|
220
|
-
expect(mockFs.unlinkSync).not.toHaveBeenCalled();
|
|
221
|
-
}));
|
|
222
|
-
it('should handle S3 upload failure', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
-
mockUtils.uploadFileToS3.mockResolvedValue(null);
|
|
224
|
-
const program = (0, create_1.default)();
|
|
225
|
-
yield program.parseAsync([
|
|
226
|
-
'node',
|
|
227
|
-
'dxp-cli',
|
|
228
|
-
'--asset-id',
|
|
229
|
-
'asset-123',
|
|
230
|
-
'--preview-asset-id',
|
|
231
|
-
'preview-456',
|
|
232
|
-
'--matrix-url',
|
|
233
|
-
'https://matrix.example.com',
|
|
234
|
-
'/path/to/export',
|
|
235
157
|
]);
|
|
236
|
-
expect(
|
|
158
|
+
expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, new Error('Migration creation failed'));
|
|
237
159
|
}));
|
|
238
160
|
it('should handle migration API error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
239
161
|
const apiError = new Error('Migration API failed');
|
|
@@ -249,7 +171,6 @@ describe('createMigrationCommand', () => {
|
|
|
249
171
|
'preview-456',
|
|
250
172
|
'--matrix-url',
|
|
251
173
|
'https://matrix.example.com',
|
|
252
|
-
'/path/to/export',
|
|
253
174
|
]);
|
|
254
175
|
expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, apiError);
|
|
255
176
|
}));
|
|
@@ -268,9 +189,8 @@ describe('createMigrationCommand', () => {
|
|
|
268
189
|
'preview-456',
|
|
269
190
|
'--matrix-url',
|
|
270
191
|
'https://matrix.example.com',
|
|
271
|
-
'/path/to/export',
|
|
272
192
|
])).rejects.toThrow('Not logged in');
|
|
273
|
-
expect(mockCreateMigration.
|
|
193
|
+
expect(mockCreateMigration.createMigration).not.toHaveBeenCalled();
|
|
274
194
|
}));
|
|
275
195
|
});
|
|
276
196
|
describe('required options validation', () => {
|
|
@@ -284,7 +204,6 @@ describe('createMigrationCommand', () => {
|
|
|
284
204
|
'preview-456',
|
|
285
205
|
'--matrix-url',
|
|
286
206
|
'https://matrix.example.com',
|
|
287
|
-
'/path/to/export',
|
|
288
207
|
]);
|
|
289
208
|
}).toThrow();
|
|
290
209
|
});
|
|
@@ -298,7 +217,6 @@ describe('createMigrationCommand', () => {
|
|
|
298
217
|
'asset-123',
|
|
299
218
|
'--matrix-url',
|
|
300
219
|
'https://matrix.example.com',
|
|
301
|
-
'/path/to/export',
|
|
302
220
|
]);
|
|
303
221
|
}).toThrow();
|
|
304
222
|
});
|
|
@@ -312,22 +230,6 @@ describe('createMigrationCommand', () => {
|
|
|
312
230
|
'asset-123',
|
|
313
231
|
'--preview-asset-id',
|
|
314
232
|
'preview-456',
|
|
315
|
-
'/path/to/export',
|
|
316
|
-
]);
|
|
317
|
-
}).toThrow();
|
|
318
|
-
});
|
|
319
|
-
it('should require exportPath argument', () => {
|
|
320
|
-
const program = (0, create_1.default)().exitOverride();
|
|
321
|
-
expect(() => {
|
|
322
|
-
program.parse([
|
|
323
|
-
'node',
|
|
324
|
-
'dxp-cli',
|
|
325
|
-
'--asset-id',
|
|
326
|
-
'asset-123',
|
|
327
|
-
'--preview-asset-id',
|
|
328
|
-
'preview-456',
|
|
329
|
-
'--matrix-url',
|
|
330
|
-
'https://matrix.example.com',
|
|
331
233
|
]);
|
|
332
234
|
}).toThrow();
|
|
333
235
|
});
|
|
@@ -351,7 +253,6 @@ describe('createMigrationCommand', () => {
|
|
|
351
253
|
'https://matrix.example.com',
|
|
352
254
|
'--tenant',
|
|
353
255
|
'test-tenant',
|
|
354
|
-
'/path/to/export',
|
|
355
256
|
]);
|
|
356
257
|
const opts = program.opts();
|
|
357
258
|
expect(opts.assetId).toBe('asset-123');
|
|
@@ -372,13 +273,8 @@ describe('createMigrationCommand', () => {
|
|
|
372
273
|
'preview-456',
|
|
373
274
|
'--matrix-url',
|
|
374
275
|
'https://matrix.example.com',
|
|
375
|
-
'/path/to/export',
|
|
376
276
|
]);
|
|
377
|
-
expect(mockCreateMigration.validateExportFolder).toHaveBeenCalledWith('/path/to/export');
|
|
378
|
-
expect(mockCreateMigration.createTarFile).toHaveBeenCalledWith('/path/to/export');
|
|
379
277
|
expect(mockCreateMigration.createMigration).toHaveBeenCalled();
|
|
380
|
-
expect(mockUtils.uploadFileToS3).toHaveBeenCalled();
|
|
381
|
-
expect(mockFs.unlinkSync).toHaveBeenCalled();
|
|
382
278
|
}));
|
|
383
279
|
});
|
|
384
280
|
});
|