@squiz/dxp-cli-next 5.26.0-develop.3 → 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 +10 -6
- 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.d.ts +3 -0
- package/lib/migration/revert/revert.js +47 -0
- package/lib/migration/revert/revert.spec.js +153 -0
- package/lib/migration/settings/{setMigrationSettings.js → settings.js} +7 -8
- package/lib/migration/settings/settings.spec.d.ts +1 -0
- 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 -49
- package/lib/migration/utils.d.ts +0 -14
- package/lib/migration/utils.js +0 -274
- package/lib/migration/utils.spec.js +0 -550
- /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/{utils.spec.d.ts → revert/revert.spec.d.ts} +0 -0
- /package/lib/migration/settings/{setMigrationSettings.d.ts → settings.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
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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 chalk_1 = __importDefault(require("chalk"));
|
|
16
|
+
const commander_1 = require("commander");
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const ora_1 = __importDefault(require("ora"));
|
|
19
|
+
const options_1 = require("../utils/options");
|
|
20
|
+
const revertMigrationCommand = () => {
|
|
21
|
+
const revertCommand = new commander_1.Command('revert')
|
|
22
|
+
.name('revert')
|
|
23
|
+
.description('Revert the current stage of a migration using the AI Page migration service')
|
|
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))
|
|
27
|
+
.configureOutput({
|
|
28
|
+
outputError(str, write) {
|
|
29
|
+
write(chalk_1.default.red(str));
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const spinner = (0, ora_1.default)('Reverting...').start();
|
|
34
|
+
yield (0, utils_1.throwErrorIfNotLoggedIn)(revertCommand);
|
|
35
|
+
try {
|
|
36
|
+
const response = yield (0, utils_1.revertMigration)(options);
|
|
37
|
+
spinner.succeed(response.message);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
spinner.fail();
|
|
41
|
+
(0, utils_1.handleCommandError)(revertCommand, error);
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
(0, options_1.addOverrideUrlOption)(revertCommand);
|
|
45
|
+
return revertCommand;
|
|
46
|
+
};
|
|
47
|
+
exports.default = revertMigrationCommand;
|
|
@@ -0,0 +1,153 @@
|
|
|
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 revert_1 = __importDefault(require("./revert"));
|
|
39
|
+
const utils = __importStar(require("../utils/common"));
|
|
40
|
+
const revertMigration = __importStar(require("../utils/revertMigration"));
|
|
41
|
+
jest.mock('../utils/common');
|
|
42
|
+
jest.mock('../utils/revertMigration');
|
|
43
|
+
jest.mock('../../ApplicationStore');
|
|
44
|
+
const mockUtils = utils;
|
|
45
|
+
const mockRevertMigration = revertMigration;
|
|
46
|
+
describe('revertMigrationCommand', () => {
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
jest.resetAllMocks();
|
|
50
|
+
});
|
|
51
|
+
describe('command configuration', () => {
|
|
52
|
+
it('should have correct command name and description', () => {
|
|
53
|
+
const program = (0, revert_1.default)();
|
|
54
|
+
expect(program.name()).toBe('revert');
|
|
55
|
+
expect(program.description()).toBe('Revert the current stage of a migration using the AI Page migration service');
|
|
56
|
+
});
|
|
57
|
+
it('should have required migration-id option', () => {
|
|
58
|
+
const program = (0, revert_1.default)();
|
|
59
|
+
const options = program.options;
|
|
60
|
+
const migrationIdOption = options.find((opt) => opt.long === '--migration-id');
|
|
61
|
+
expect(migrationIdOption).toBeDefined();
|
|
62
|
+
expect(migrationIdOption === null || migrationIdOption === void 0 ? void 0 : migrationIdOption.mandatory).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
it('should have optional asset-id option', () => {
|
|
65
|
+
const program = (0, revert_1.default)();
|
|
66
|
+
const options = program.options;
|
|
67
|
+
const assetIdOption = options.find((opt) => opt.long === '--asset-id');
|
|
68
|
+
expect(assetIdOption).toBeDefined();
|
|
69
|
+
expect(assetIdOption === null || assetIdOption === void 0 ? void 0 : assetIdOption.mandatory).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
it('should have optional tenant option', () => {
|
|
72
|
+
const program = (0, revert_1.default)();
|
|
73
|
+
const options = program.options;
|
|
74
|
+
const tenantOption = options.find((opt) => opt.long === '--tenant');
|
|
75
|
+
expect(tenantOption).toBeDefined();
|
|
76
|
+
expect(tenantOption === null || tenantOption === void 0 ? void 0 : tenantOption.mandatory).toBe(false);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('command execution', () => {
|
|
80
|
+
it('should revert migration successfully with required options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const mockResponse = { message: 'Migration reverted successfully' };
|
|
82
|
+
mockRevertMigration.revertMigration.mockResolvedValue(mockResponse);
|
|
83
|
+
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue();
|
|
84
|
+
const program = (0, revert_1.default)();
|
|
85
|
+
yield program.parseAsync([
|
|
86
|
+
'node',
|
|
87
|
+
'dxp-cli',
|
|
88
|
+
'migration',
|
|
89
|
+
'revert',
|
|
90
|
+
'--migration-id',
|
|
91
|
+
'migration-123',
|
|
92
|
+
'--asset-id',
|
|
93
|
+
'asset-456',
|
|
94
|
+
]);
|
|
95
|
+
expect(mockUtils.throwErrorIfNotLoggedIn).toHaveBeenCalledWith(program);
|
|
96
|
+
expect(mockRevertMigration.revertMigration).toHaveBeenCalledWith({
|
|
97
|
+
migrationId: 'migration-123',
|
|
98
|
+
assetId: 'asset-456',
|
|
99
|
+
});
|
|
100
|
+
expect(mockUtils.handleCommandError).not.toHaveBeenCalled();
|
|
101
|
+
}));
|
|
102
|
+
it('should revert migration with tenant option', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
|
+
const mockResponse = { message: 'Migration reverted successfully' };
|
|
104
|
+
mockRevertMigration.revertMigration.mockResolvedValue(mockResponse);
|
|
105
|
+
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue();
|
|
106
|
+
const program = (0, revert_1.default)();
|
|
107
|
+
yield program.parseAsync([
|
|
108
|
+
'node',
|
|
109
|
+
'dxp-cli',
|
|
110
|
+
'migration',
|
|
111
|
+
'revert',
|
|
112
|
+
'--migration-id',
|
|
113
|
+
'migration-123',
|
|
114
|
+
'--asset-id',
|
|
115
|
+
'asset-456',
|
|
116
|
+
'--tenant',
|
|
117
|
+
'test-tenant',
|
|
118
|
+
]);
|
|
119
|
+
expect(mockRevertMigration.revertMigration).toHaveBeenCalledWith({
|
|
120
|
+
migrationId: 'migration-123',
|
|
121
|
+
assetId: 'asset-456',
|
|
122
|
+
tenant: 'test-tenant',
|
|
123
|
+
});
|
|
124
|
+
}));
|
|
125
|
+
it('should handle revert migration error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
+
const error = new Error('Revert failed');
|
|
127
|
+
mockRevertMigration.revertMigration.mockRejectedValue(error);
|
|
128
|
+
mockUtils.throwErrorIfNotLoggedIn.mockResolvedValue();
|
|
129
|
+
const program = (0, revert_1.default)();
|
|
130
|
+
yield program.parseAsync([
|
|
131
|
+
'node',
|
|
132
|
+
'dxp-cli',
|
|
133
|
+
'migration',
|
|
134
|
+
'revert',
|
|
135
|
+
'--migration-id',
|
|
136
|
+
'migration-123',
|
|
137
|
+
'--asset-id',
|
|
138
|
+
'asset-456',
|
|
139
|
+
]);
|
|
140
|
+
expect(mockUtils.handleCommandError).toHaveBeenCalledWith(program, error);
|
|
141
|
+
}));
|
|
142
|
+
it('should include override URL option when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
|
+
const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
|
|
144
|
+
process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
|
|
145
|
+
const program = (0, revert_1.default)();
|
|
146
|
+
const options = program.options;
|
|
147
|
+
const overrideUrlOption = options.find((opt) => opt.long === '--overrideUrl');
|
|
148
|
+
expect(overrideUrlOption).toBeDefined();
|
|
149
|
+
expect(overrideUrlOption === null || overrideUrlOption === void 0 ? void 0 : overrideUrlOption.mandatory).toBe(false);
|
|
150
|
+
process.env.ENABLE_OVERRIDE_MIGRATION_URL = originalEnv;
|
|
151
|
+
}));
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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
|
+
}
|