@squiz/dxp-cli-next 5.26.0-develop.4 → 5.26.0
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
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
const nock_1 = __importDefault(require("nock"));
|
|
39
|
+
const next_1 = __importDefault(require("./next"));
|
|
40
|
+
const utils = __importStar(require("../utils/common"));
|
|
41
|
+
const ApplicationStore = __importStar(require("../../ApplicationStore"));
|
|
42
|
+
const nextStageModule = __importStar(require("../utils/nextStage"));
|
|
43
|
+
jest.mock('../utils/common');
|
|
44
|
+
jest.mock('../utils/nextStage');
|
|
45
|
+
jest.mock('../../ApplicationStore');
|
|
46
|
+
const mockUtils = utils;
|
|
47
|
+
const mockNextStage = nextStageModule;
|
|
48
|
+
const mockApplicationStore = ApplicationStore;
|
|
49
|
+
describe('nextStageCommand', () => {
|
|
50
|
+
let logSpy;
|
|
51
|
+
let mockNextStageResponse;
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
nock_1.default.cleanAll();
|
|
54
|
+
jest.clearAllMocks();
|
|
55
|
+
jest.resetAllMocks();
|
|
56
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
57
|
+
mockApplicationStore.getApplicationFile.mockResolvedValue('session-cookie');
|
|
58
|
+
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue(undefined);
|
|
59
|
+
mockNextStageResponse = {
|
|
60
|
+
message: 'Successfully started next stage',
|
|
61
|
+
};
|
|
62
|
+
mockNextStage.nextStage.mockResolvedValue(mockNextStageResponse);
|
|
63
|
+
});
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
logSpy.mockRestore();
|
|
66
|
+
});
|
|
67
|
+
describe('successful next stage execution', () => {
|
|
68
|
+
it('should execute next stage successfully with required options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
const program = (0, next_1.default)();
|
|
70
|
+
yield program.parseAsync([
|
|
71
|
+
'node',
|
|
72
|
+
'dxp-cli',
|
|
73
|
+
'next',
|
|
74
|
+
'--migration-id',
|
|
75
|
+
'migration-123',
|
|
76
|
+
'--asset-id',
|
|
77
|
+
'asset-456',
|
|
78
|
+
]);
|
|
79
|
+
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
80
|
+
expect(mockNextStage.nextStage).toHaveBeenCalledWith({
|
|
81
|
+
migrationId: 'migration-123',
|
|
82
|
+
assetId: 'asset-456',
|
|
83
|
+
});
|
|
84
|
+
expect(mockNextStage.nextStage).toHaveBeenCalledTimes(1);
|
|
85
|
+
expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
|
|
86
|
+
}));
|
|
87
|
+
it('should execute next stage with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const program = (0, next_1.default)();
|
|
89
|
+
yield program.parseAsync([
|
|
90
|
+
'node',
|
|
91
|
+
'dxp-cli',
|
|
92
|
+
'next',
|
|
93
|
+
'--migration-id',
|
|
94
|
+
'migration-123',
|
|
95
|
+
'--asset-id',
|
|
96
|
+
'asset-456',
|
|
97
|
+
'--tenant',
|
|
98
|
+
'test-tenant',
|
|
99
|
+
]);
|
|
100
|
+
expect(mockNextStage.nextStage).toHaveBeenCalledWith({
|
|
101
|
+
migrationId: 'migration-123',
|
|
102
|
+
assetId: 'asset-456',
|
|
103
|
+
tenant: 'test-tenant',
|
|
104
|
+
});
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
describe('error scenarios', () => {
|
|
108
|
+
it('should handle nextStage API error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const apiError = new Error('Failed to start next stage');
|
|
110
|
+
mockNextStage.nextStage.mockRejectedValue(apiError);
|
|
111
|
+
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
112
|
+
const program = (0, next_1.default)();
|
|
113
|
+
yield program.parseAsync([
|
|
114
|
+
'node',
|
|
115
|
+
'dxp-cli',
|
|
116
|
+
'next',
|
|
117
|
+
'--migration-id',
|
|
118
|
+
'migration-123',
|
|
119
|
+
'--asset-id',
|
|
120
|
+
'asset-456',
|
|
121
|
+
]);
|
|
122
|
+
expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, apiError);
|
|
123
|
+
}));
|
|
124
|
+
it('should handle network error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
const networkError = new Error('Network connection failed');
|
|
126
|
+
mockNextStage.nextStage.mockRejectedValue(networkError);
|
|
127
|
+
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
128
|
+
const program = (0, next_1.default)();
|
|
129
|
+
yield program.parseAsync([
|
|
130
|
+
'node',
|
|
131
|
+
'dxp-cli',
|
|
132
|
+
'next',
|
|
133
|
+
'--migration-id',
|
|
134
|
+
'migration-123',
|
|
135
|
+
'--asset-id',
|
|
136
|
+
'asset-456',
|
|
137
|
+
]);
|
|
138
|
+
expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, networkError);
|
|
139
|
+
}));
|
|
140
|
+
});
|
|
141
|
+
describe('required options validation', () => {
|
|
142
|
+
it('should require migration-id option', () => {
|
|
143
|
+
const program = (0, next_1.default)().exitOverride();
|
|
144
|
+
expect(() => {
|
|
145
|
+
program.parse(['node', 'dxp-cli', 'next', '--asset-id', 'asset-456']);
|
|
146
|
+
}).toThrow();
|
|
147
|
+
});
|
|
148
|
+
it('should require asset-id option', () => {
|
|
149
|
+
const program = (0, next_1.default)().exitOverride();
|
|
150
|
+
expect(() => {
|
|
151
|
+
program.parse([
|
|
152
|
+
'node',
|
|
153
|
+
'dxp-cli',
|
|
154
|
+
'next',
|
|
155
|
+
'--migration-id',
|
|
156
|
+
'migration-123',
|
|
157
|
+
]);
|
|
158
|
+
}).toThrow();
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('command configuration', () => {
|
|
162
|
+
it('should have correct command name and description', () => {
|
|
163
|
+
const program = (0, next_1.default)();
|
|
164
|
+
expect(program.name()).toBe('next');
|
|
165
|
+
expect(program.description()).toBe('Triggers the next step of the migration, which will be decided based on the current asset migration stage and status');
|
|
166
|
+
});
|
|
167
|
+
it('should parse options correctly', () => {
|
|
168
|
+
const program = (0, next_1.default)();
|
|
169
|
+
program.parse([
|
|
170
|
+
'node',
|
|
171
|
+
'dxp-cli',
|
|
172
|
+
'next',
|
|
173
|
+
'--migration-id',
|
|
174
|
+
'migration-123',
|
|
175
|
+
'--asset-id',
|
|
176
|
+
'asset-456',
|
|
177
|
+
'--tenant',
|
|
178
|
+
'test-tenant',
|
|
179
|
+
]);
|
|
180
|
+
const opts = program.opts();
|
|
181
|
+
expect(opts.migrationId).toBe('migration-123');
|
|
182
|
+
expect(opts.assetId).toBe('asset-456');
|
|
183
|
+
expect(opts.tenant).toBe('test-tenant');
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -16,13 +16,14 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
16
16
|
const commander_1 = require("commander");
|
|
17
17
|
const utils_1 = require("../utils");
|
|
18
18
|
const ora_1 = __importDefault(require("ora"));
|
|
19
|
+
const options_1 = require("../utils/options");
|
|
19
20
|
const revertMigrationCommand = () => {
|
|
20
21
|
const revertCommand = new commander_1.Command('revert')
|
|
21
22
|
.name('revert')
|
|
22
23
|
.description('Revert the current stage of a migration using the AI Page migration service')
|
|
23
|
-
.addOption(
|
|
24
|
-
.addOption(
|
|
25
|
-
.addOption(
|
|
24
|
+
.addOption((0, options_1.getParamOption)(options_1.OptionName.MIGRATION_ID))
|
|
25
|
+
.addOption((0, options_1.getParamOption)(options_1.OptionName.ASSET_ID, false))
|
|
26
|
+
.addOption((0, options_1.getParamOption)(options_1.OptionName.TENANT, false))
|
|
26
27
|
.configureOutput({
|
|
27
28
|
outputError(str, write) {
|
|
28
29
|
write(chalk_1.default.red(str));
|
|
@@ -40,9 +41,7 @@ const revertMigrationCommand = () => {
|
|
|
40
41
|
(0, utils_1.handleCommandError)(revertCommand, error);
|
|
41
42
|
}
|
|
42
43
|
}));
|
|
43
|
-
|
|
44
|
-
revertCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire migration url with a custom value'));
|
|
45
|
-
}
|
|
44
|
+
(0, options_1.addOverrideUrlOption)(revertCommand);
|
|
46
45
|
return revertCommand;
|
|
47
46
|
};
|
|
48
47
|
exports.default = revertMigrationCommand;
|
|
@@ -36,10 +36,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const revert_1 = __importDefault(require("./revert"));
|
|
39
|
-
const utils = __importStar(require("../utils"));
|
|
40
|
-
|
|
39
|
+
const utils = __importStar(require("../utils/common"));
|
|
40
|
+
const revertMigration = __importStar(require("../utils/revertMigration"));
|
|
41
|
+
jest.mock('../utils/common');
|
|
42
|
+
jest.mock('../utils/revertMigration');
|
|
41
43
|
jest.mock('../../ApplicationStore');
|
|
42
44
|
const mockUtils = utils;
|
|
45
|
+
const mockRevertMigration = revertMigration;
|
|
43
46
|
describe('revertMigrationCommand', () => {
|
|
44
47
|
beforeEach(() => {
|
|
45
48
|
jest.clearAllMocks();
|
|
@@ -76,7 +79,7 @@ describe('revertMigrationCommand', () => {
|
|
|
76
79
|
describe('command execution', () => {
|
|
77
80
|
it('should revert migration successfully with required options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
81
|
const mockResponse = { message: 'Migration reverted successfully' };
|
|
79
|
-
|
|
82
|
+
mockRevertMigration.revertMigration.mockResolvedValue(mockResponse);
|
|
80
83
|
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue();
|
|
81
84
|
const program = (0, revert_1.default)();
|
|
82
85
|
yield program.parseAsync([
|
|
@@ -90,7 +93,7 @@ describe('revertMigrationCommand', () => {
|
|
|
90
93
|
'asset-456',
|
|
91
94
|
]);
|
|
92
95
|
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
93
|
-
expect(
|
|
96
|
+
expect(mockRevertMigration.revertMigration).toHaveBeenCalledWith({
|
|
94
97
|
migrationId: 'migration-123',
|
|
95
98
|
assetId: 'asset-456',
|
|
96
99
|
});
|
|
@@ -98,7 +101,7 @@ describe('revertMigrationCommand', () => {
|
|
|
98
101
|
}));
|
|
99
102
|
it('should revert migration with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
103
|
const mockResponse = { message: 'Migration reverted successfully' };
|
|
101
|
-
|
|
104
|
+
mockRevertMigration.revertMigration.mockResolvedValue(mockResponse);
|
|
102
105
|
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue();
|
|
103
106
|
const program = (0, revert_1.default)();
|
|
104
107
|
yield program.parseAsync([
|
|
@@ -113,7 +116,7 @@ describe('revertMigrationCommand', () => {
|
|
|
113
116
|
'--tenant',
|
|
114
117
|
'test-tenant',
|
|
115
118
|
]);
|
|
116
|
-
expect(
|
|
119
|
+
expect(mockRevertMigration.revertMigration).toHaveBeenCalledWith({
|
|
117
120
|
migrationId: 'migration-123',
|
|
118
121
|
assetId: 'asset-456',
|
|
119
122
|
tenant: 'test-tenant',
|
|
@@ -121,7 +124,7 @@ describe('revertMigrationCommand', () => {
|
|
|
121
124
|
}));
|
|
122
125
|
it('should handle revert migration error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
126
|
const error = new Error('Revert failed');
|
|
124
|
-
|
|
127
|
+
mockRevertMigration.revertMigration.mockRejectedValue(error);
|
|
125
128
|
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue();
|
|
126
129
|
const program = (0, revert_1.default)();
|
|
127
130
|
yield program.parseAsync([
|
|
@@ -16,14 +16,15 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
16
16
|
const commander_1 = require("commander");
|
|
17
17
|
const utils_1 = require("../utils");
|
|
18
18
|
const ora_1 = __importDefault(require("ora"));
|
|
19
|
+
const options_1 = require("../utils/options");
|
|
19
20
|
const setMigrationSettingsCommand = () => {
|
|
20
21
|
const settingsCommand = new commander_1.Command('settings')
|
|
21
22
|
.name('settings')
|
|
22
23
|
.description('Set settings for the migration service')
|
|
23
|
-
.addOption(
|
|
24
|
-
.addOption(
|
|
25
|
-
.addOption(
|
|
26
|
-
.addOption(
|
|
24
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MATRIX_URL))
|
|
25
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MATRIX_IDENTIFIER))
|
|
26
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MATRIX_KEY))
|
|
27
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.TENANT, false))
|
|
27
28
|
.configureOutput({
|
|
28
29
|
outputError(str, write) {
|
|
29
30
|
write(chalk_1.default.red(str));
|
|
@@ -33,7 +34,7 @@ const setMigrationSettingsCommand = () => {
|
|
|
33
34
|
const spinner = (0, ora_1.default)('Setting migration configuration...').start();
|
|
34
35
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(settingsCommand);
|
|
35
36
|
try {
|
|
36
|
-
const response = yield (0, utils_1.
|
|
37
|
+
const response = yield (0, utils_1.setMigrationSettings)(options);
|
|
37
38
|
spinner.succeed(`Migration settings updated: ${JSON.stringify(response, null, 2)}`);
|
|
38
39
|
}
|
|
39
40
|
catch (error) {
|
|
@@ -41,9 +42,7 @@ const setMigrationSettingsCommand = () => {
|
|
|
41
42
|
(0, utils_1.handleCommandError)(settingsCommand, error);
|
|
42
43
|
}
|
|
43
44
|
}));
|
|
44
|
-
|
|
45
|
-
settingsCommand.addOption(new commander_1.Option('-ou, --overrideUrl <string>', 'Developer option to override the entire migration url with a custom value'));
|
|
46
|
-
}
|
|
45
|
+
(0, options_1.addOverrideUrlOption)(settingsCommand);
|
|
47
46
|
return settingsCommand;
|
|
48
47
|
};
|
|
49
48
|
exports.default = setMigrationSettingsCommand;
|
|
@@ -35,13 +35,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
38
|
+
const settings_1 = __importDefault(require("./settings"));
|
|
39
|
+
const Utils = __importStar(require("../utils/common"));
|
|
40
|
+
const setMigrationSettings = __importStar(require("../utils/setMigrationSettings"));
|
|
41
41
|
const ApplicationStore = __importStar(require("../../ApplicationStore"));
|
|
42
|
-
|
|
42
|
+
const nock_1 = __importDefault(require("nock"));
|
|
43
|
+
jest.mock('../../ApplicationConfig');
|
|
43
44
|
jest.mock('../../ApplicationStore');
|
|
44
|
-
|
|
45
|
+
jest.mock('../../ApiService');
|
|
46
|
+
jest.mock('../utils/common');
|
|
47
|
+
jest.mock('../utils/setMigrationSettings');
|
|
48
|
+
// Mock global fetch
|
|
49
|
+
const mockFetch = jest.fn();
|
|
50
|
+
global.fetch = mockFetch;
|
|
51
|
+
const mockSetMigrationSettings = setMigrationSettings;
|
|
52
|
+
const mockUtils = Utils;
|
|
45
53
|
const mockApplicationStore = ApplicationStore;
|
|
46
54
|
describe('setMigrationSettingsCommand', () => {
|
|
47
55
|
let logSpy;
|
|
@@ -58,14 +66,11 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
58
66
|
matrixIdentifier: '@user:matrix.example.com',
|
|
59
67
|
matrixKey: '***********123',
|
|
60
68
|
};
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
afterEach(() => {
|
|
64
|
-
logSpy.mockRestore();
|
|
69
|
+
mockSetMigrationSettings.setMigrationSettings.mockResolvedValue(mockSetMigrationSettingResponse);
|
|
65
70
|
});
|
|
66
71
|
describe('successful migration setting update', () => {
|
|
67
72
|
it('should set migration settings successfully with required options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
const program = (0,
|
|
73
|
+
const program = (0, settings_1.default)();
|
|
69
74
|
yield program.parseAsync([
|
|
70
75
|
'node',
|
|
71
76
|
'dxp-cli',
|
|
@@ -79,16 +84,16 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
79
84
|
'secret-key-123',
|
|
80
85
|
]);
|
|
81
86
|
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
82
|
-
expect(
|
|
87
|
+
expect(mockSetMigrationSettings.setMigrationSettings).toHaveBeenCalledWith({
|
|
83
88
|
matrixUrl: 'https://matrix.example.com',
|
|
84
89
|
matrixIdentifier: '@user:matrix.example.com',
|
|
85
90
|
matrixKey: 'secret-key-123',
|
|
86
91
|
});
|
|
87
|
-
expect(
|
|
92
|
+
expect(mockSetMigrationSettings.setMigrationSettings).toHaveBeenCalledTimes(1);
|
|
88
93
|
expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
|
|
89
94
|
}));
|
|
90
95
|
it('should set migration settings with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
-
const program = (0,
|
|
96
|
+
const program = (0, settings_1.default)();
|
|
92
97
|
yield program.parseAsync([
|
|
93
98
|
'node',
|
|
94
99
|
'dxp-cli',
|
|
@@ -103,7 +108,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
103
108
|
'--tenant',
|
|
104
109
|
'test-tenant',
|
|
105
110
|
]);
|
|
106
|
-
expect(
|
|
111
|
+
expect(mockSetMigrationSettings.setMigrationSettings).toHaveBeenCalledWith({
|
|
107
112
|
matrixUrl: 'https://matrix.example.com',
|
|
108
113
|
matrixIdentifier: '@user:matrix.example.com',
|
|
109
114
|
matrixKey: 'secret-key-123',
|
|
@@ -113,7 +118,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
113
118
|
it('should set migration settings with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
119
|
const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
|
|
115
120
|
process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
|
|
116
|
-
const program = (0,
|
|
121
|
+
const program = (0, settings_1.default)();
|
|
117
122
|
yield program.parseAsync([
|
|
118
123
|
'node',
|
|
119
124
|
'dxp-cli',
|
|
@@ -128,7 +133,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
128
133
|
'--overrideUrl',
|
|
129
134
|
'https://custom.migration.url',
|
|
130
135
|
]);
|
|
131
|
-
expect(
|
|
136
|
+
expect(mockSetMigrationSettings.setMigrationSettings).toHaveBeenCalledWith({
|
|
132
137
|
matrixUrl: 'https://matrix.example.com',
|
|
133
138
|
matrixIdentifier: '@user:matrix.example.com',
|
|
134
139
|
matrixKey: 'secret-key-123',
|
|
@@ -140,9 +145,9 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
140
145
|
describe('error scenarios', () => {
|
|
141
146
|
it('should handle setMigrationSetting API error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
147
|
const apiError = new Error('Settings update failed');
|
|
143
|
-
|
|
148
|
+
mockSetMigrationSettings.setMigrationSettings.mockRejectedValue(apiError);
|
|
144
149
|
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
145
|
-
const program = (0,
|
|
150
|
+
const program = (0, settings_1.default)();
|
|
146
151
|
yield program.parseAsync([
|
|
147
152
|
'node',
|
|
148
153
|
'dxp-cli',
|
|
@@ -159,9 +164,9 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
159
164
|
}));
|
|
160
165
|
it('should handle network error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
166
|
const networkError = new Error('Network connection failed');
|
|
162
|
-
|
|
167
|
+
mockSetMigrationSettings.setMigrationSettings.mockRejectedValue(networkError);
|
|
163
168
|
mockUtils.handleCommandError.mockImplementation(() => { });
|
|
164
|
-
const program = (0,
|
|
169
|
+
const program = (0, settings_1.default)();
|
|
165
170
|
yield program.parseAsync([
|
|
166
171
|
'node',
|
|
167
172
|
'dxp-cli',
|
|
@@ -179,7 +184,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
179
184
|
});
|
|
180
185
|
describe('required options validation', () => {
|
|
181
186
|
it('should require matrixUrl option', () => {
|
|
182
|
-
const program = (0,
|
|
187
|
+
const program = (0, settings_1.default)().exitOverride();
|
|
183
188
|
expect(() => {
|
|
184
189
|
program.parse([
|
|
185
190
|
'node',
|
|
@@ -194,7 +199,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
194
199
|
}).toThrow();
|
|
195
200
|
});
|
|
196
201
|
it('should require matrixIdentifier option', () => {
|
|
197
|
-
const program = (0,
|
|
202
|
+
const program = (0, settings_1.default)().exitOverride();
|
|
198
203
|
expect(() => {
|
|
199
204
|
program.parse([
|
|
200
205
|
'node',
|
|
@@ -209,7 +214,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
209
214
|
}).toThrow();
|
|
210
215
|
});
|
|
211
216
|
it('should require matrixKey option', () => {
|
|
212
|
-
const program = (0,
|
|
217
|
+
const program = (0, settings_1.default)().exitOverride();
|
|
213
218
|
expect(() => {
|
|
214
219
|
program.parse([
|
|
215
220
|
'node',
|
|
@@ -226,12 +231,12 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
226
231
|
});
|
|
227
232
|
describe('command configuration', () => {
|
|
228
233
|
it('should have correct command name and description', () => {
|
|
229
|
-
const program = (0,
|
|
234
|
+
const program = (0, settings_1.default)();
|
|
230
235
|
expect(program.name()).toBe('settings');
|
|
231
236
|
expect(program.description()).toBe('Set settings for the migration service');
|
|
232
237
|
});
|
|
233
238
|
it('should parse options correctly', () => {
|
|
234
|
-
const program = (0,
|
|
239
|
+
const program = (0, settings_1.default)();
|
|
235
240
|
program.parse([
|
|
236
241
|
'node',
|
|
237
242
|
'dxp-cli',
|
|
@@ -253,7 +258,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
253
258
|
expect(opts.tenant).toBe('test-tenant');
|
|
254
259
|
});
|
|
255
260
|
it('should parse options with kebab-case to camelCase conversion', () => {
|
|
256
|
-
const program = (0,
|
|
261
|
+
const program = (0, settings_1.default)();
|
|
257
262
|
program.parse([
|
|
258
263
|
'node',
|
|
259
264
|
'dxp-cli',
|
|
@@ -272,4 +277,7 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
272
277
|
expect(opts.matrixKey).toBe('secret-key-123');
|
|
273
278
|
});
|
|
274
279
|
});
|
|
280
|
+
afterEach(() => {
|
|
281
|
+
logSpy.mockRestore();
|
|
282
|
+
});
|
|
275
283
|
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface CommonCommandOptions {
|
|
2
|
+
tenant?: string;
|
|
3
|
+
overrideUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface AssetMigration {
|
|
6
|
+
migrationId: string;
|
|
7
|
+
assetId: string;
|
|
8
|
+
xmlFilePath: string;
|
|
9
|
+
matrixUrl: string;
|
|
10
|
+
previewAssetId: string;
|
|
11
|
+
previewPageAssetId?: string;
|
|
12
|
+
stage: string;
|
|
13
|
+
status: string;
|
|
14
|
+
stageDetails?: string;
|
|
15
|
+
created: number;
|
|
16
|
+
updated: number;
|
|
17
|
+
migrationIdAssetId: string;
|
|
18
|
+
componentsTarDownloadUrl?: string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AssetMigration, CommonCommandOptions } from '.';
|
|
2
|
+
export interface CreateMigrationOptions extends CommonCommandOptions, Pick<AssetMigration, 'assetId' | 'previewAssetId' | 'matrixUrl'> {
|
|
3
|
+
}
|
|
4
|
+
export interface CreateMigrationApiResponse {
|
|
5
|
+
assetMigration: AssetMigration;
|
|
6
|
+
uploadUrl: string;
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common.types"), exports);
|
|
18
|
+
__exportStar(require("./createMigration.types"), exports);
|
|
19
|
+
__exportStar(require("./getMigration.types"), exports);
|
|
20
|
+
__exportStar(require("./nextStage.types"), exports);
|
|
21
|
+
__exportStar(require("./settings.types"), exports);
|
|
22
|
+
__exportStar(require("./revert.types"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CommonCommandOptions } from '.';
|
|
2
|
+
export interface MatrixIdentifierSchema {
|
|
3
|
+
matrixUrl: string;
|
|
4
|
+
matrixIdentifier: string;
|
|
5
|
+
matrixKey: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SetMigrationSettingOptions extends CommonCommandOptions, MatrixIdentifierSchema {
|
|
8
|
+
}
|
|
9
|
+
export interface SetMigrationSettingApiResponse extends MatrixIdentifierSchema {
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* The purpose of this file is to provide utilities in common
|
|
4
|
+
* such as functions that can be reused across the migration service.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Handles errors from the migration service.
|
|
8
|
+
* @param command - The command that is being executed.
|
|
9
|
+
* @param error - The error that occurred.
|
|
10
|
+
*/
|
|
11
|
+
export declare function handleCommandError(command: Command, error: Error): void;
|
|
12
|
+
/**
|
|
13
|
+
* Throws an error if the user is not logged in.
|
|
14
|
+
* @param command - The command that is being executed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function throwErrorIfNotLoggedIn(command: Command): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Builds the migration URL.
|
|
19
|
+
* @param tenantID - The tenant ID.
|
|
20
|
+
* @param overrideUrl - The override URL.
|
|
21
|
+
* @returns The migration URL.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildMigrationUrl(tenantID?: string, overrideUrl?: string, baseDomain?: 'migrations' | 'settings'): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Validates the status of the axios request.
|
|
26
|
+
* @param status - The status of the axios request.
|
|
27
|
+
* @returns True if the status is less than 400, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateAxiosStatus(status: number): boolean;
|
|
30
|
+
export declare function getMigrationHeaders(tenantID?: string, isJson?: boolean): Promise<Record<string, string>>;
|
|
31
|
+
export declare function uploadFileToS3(uploadUrl: string, filePath: string, tenantID?: string): Promise<string>;
|
|
32
|
+
export declare function redactKey(key: string, visibleChars?: number): string;
|