@squiz/dxp-cli-next 5.27.0-develop.1 → 5.27.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/next/next.js +15 -1
- package/lib/migration/next/next.spec.js +23 -0
- package/lib/migration/settings/settings.js +15 -2
- package/lib/migration/settings/settings.spec.js +30 -0
- package/lib/migration/types/nextStage.types.d.ts +4 -0
- package/lib/migration/types/settings.types.d.ts +4 -0
- package/lib/migration/utils/index.d.ts +1 -0
- package/lib/migration/utils/index.js +1 -0
- package/lib/migration/utils/loadStageOptionsFromFile.d.ts +1 -0
- package/lib/migration/utils/loadStageOptionsFromFile.js +32 -0
- package/lib/migration/utils/loadStageOptionsFromFile.spec.d.ts +1 -0
- package/lib/migration/utils/loadStageOptionsFromFile.spec.js +77 -0
- package/lib/migration/utils/nextStage.d.ts +2 -2
- package/lib/migration/utils/nextStage.js +2 -1
- package/lib/migration/utils/nextStage.spec.js +1 -1
- package/lib/migration/utils/options.d.ts +2 -1
- package/lib/migration/utils/options.js +8 -0
- package/lib/migration/utils/setMigrationSettings.d.ts +2 -2
- package/lib/migration/utils/setMigrationSettings.js +1 -7
- package/lib/migration/utils/setMigrationSettings.spec.js +9 -8
- package/package.json +1 -1
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -23,6 +34,7 @@ const nextStageCommand = () => {
|
|
|
23
34
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MIGRATION_ID))
|
|
24
35
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.ASSET_ID))
|
|
25
36
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.TENANT, false))
|
|
37
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.STAGE_OPTIONS, false))
|
|
26
38
|
.configureOutput({
|
|
27
39
|
outputError(str, write) {
|
|
28
40
|
write(chalk_1.default.red(str));
|
|
@@ -32,7 +44,9 @@ const nextStageCommand = () => {
|
|
|
32
44
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(nextCommand);
|
|
33
45
|
const spinner = (0, ora_1.default)('Starting next stage').start();
|
|
34
46
|
try {
|
|
35
|
-
const
|
|
47
|
+
const { stageOptions: stageOptionsPath } = options, otherOptions = __rest(options, ["stageOptions"]);
|
|
48
|
+
const stageOptions = (0, utils_1.loadStageOptionsFromFile)(stageOptionsPath);
|
|
49
|
+
const response = yield (0, utils_1.nextStage)(Object.assign(Object.assign({}, otherOptions), (stageOptions && { stageOptions })));
|
|
36
50
|
spinner.succeed(response.message);
|
|
37
51
|
}
|
|
38
52
|
catch (error) {
|
|
@@ -103,6 +103,29 @@ describe('nextStageCommand', () => {
|
|
|
103
103
|
tenant: 'test-tenant',
|
|
104
104
|
});
|
|
105
105
|
}));
|
|
106
|
+
it('should execute next stage with stageOptions from JSON file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
+
const program = (0, next_1.default)();
|
|
108
|
+
yield program.parseAsync([
|
|
109
|
+
'node',
|
|
110
|
+
'dxp-cli',
|
|
111
|
+
'next',
|
|
112
|
+
'--migration-id',
|
|
113
|
+
'migration-123',
|
|
114
|
+
'--asset-id',
|
|
115
|
+
'asset-456',
|
|
116
|
+
'--stage-options',
|
|
117
|
+
'./src/__tests__/migration/stageOptionsInput.json',
|
|
118
|
+
]);
|
|
119
|
+
expect(mockNextStage.nextStage).toHaveBeenCalledWith({
|
|
120
|
+
migrationId: 'migration-123',
|
|
121
|
+
assetId: 'asset-456',
|
|
122
|
+
stageOptions: {
|
|
123
|
+
'cct-to-cmp': {
|
|
124
|
+
overwriteSuccessful: false,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
}));
|
|
106
129
|
});
|
|
107
130
|
describe('error scenarios', () => {
|
|
108
131
|
it('should handle nextStage API error', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
@@ -26,17 +37,19 @@ const setMigrationSettingsCommand = () => {
|
|
|
26
37
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.MATRIX_KEY))
|
|
27
38
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.CONTENT_API_KEY))
|
|
28
39
|
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.TENANT, false))
|
|
40
|
+
.addOption((0, utils_1.getParamOption)(utils_1.OptionName.STAGE_OPTIONS, false))
|
|
29
41
|
.configureOutput({
|
|
30
42
|
outputError(str, write) {
|
|
31
43
|
write(chalk_1.default.red(str));
|
|
32
44
|
},
|
|
33
45
|
})
|
|
34
46
|
.action((options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
-
console.log('options', options);
|
|
36
47
|
const spinner = (0, ora_1.default)('Setting migration configuration...').start();
|
|
37
48
|
yield (0, utils_1.throwErrorIfNotLoggedIn)(settingsCommand);
|
|
38
49
|
try {
|
|
39
|
-
const
|
|
50
|
+
const { stageOptions: stageOptionsPath } = options, otherOptions = __rest(options, ["stageOptions"]);
|
|
51
|
+
const stageOptions = (0, utils_1.loadStageOptionsFromFile)(stageOptionsPath);
|
|
52
|
+
const response = yield (0, utils_1.setMigrationSettings)(Object.assign(Object.assign({}, otherOptions), (stageOptions && { stageOptions })));
|
|
40
53
|
spinner.succeed(`Migration settings updated: ${JSON.stringify(response, null, 2)}`);
|
|
41
54
|
}
|
|
42
55
|
catch (error) {
|
|
@@ -122,6 +122,36 @@ describe('setMigrationSettingsCommand', () => {
|
|
|
122
122
|
contentApiKey: 'content-api-key-456',
|
|
123
123
|
});
|
|
124
124
|
}));
|
|
125
|
+
it('should set migration settings with stageOptions from JSON file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
+
const program = (0, settings_1.default)();
|
|
127
|
+
yield program.parseAsync([
|
|
128
|
+
'node',
|
|
129
|
+
'dxp-cli',
|
|
130
|
+
'migration',
|
|
131
|
+
'settings',
|
|
132
|
+
'--matrix-url',
|
|
133
|
+
'https://matrix.example.com',
|
|
134
|
+
'--matrix-identifier',
|
|
135
|
+
'@user:matrix.example.com',
|
|
136
|
+
'--matrix-key',
|
|
137
|
+
'secret-key-123',
|
|
138
|
+
'--content-api-key',
|
|
139
|
+
'content-api-key-456',
|
|
140
|
+
'--stage-options',
|
|
141
|
+
'./src/__tests__/migration/stageOptionsInput.json',
|
|
142
|
+
]);
|
|
143
|
+
expect(mockSetMigrationSettings.setMigrationSettings).toHaveBeenCalledWith({
|
|
144
|
+
matrixUrl: 'https://matrix.example.com',
|
|
145
|
+
matrixIdentifier: '@user:matrix.example.com',
|
|
146
|
+
matrixKey: 'secret-key-123',
|
|
147
|
+
contentApiKey: 'content-api-key-456',
|
|
148
|
+
stageOptions: {
|
|
149
|
+
'cct-to-cmp': {
|
|
150
|
+
overwriteSuccessful: false,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}));
|
|
125
155
|
it('should set migration settings with override URL when environment variable is set', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
156
|
const originalEnv = process.env.ENABLE_OVERRIDE_MIGRATION_URL;
|
|
127
157
|
process.env.ENABLE_OVERRIDE_MIGRATION_URL = 'true';
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { AssetMigration, CommonCommandOptions } from '.';
|
|
2
2
|
export interface NextStageOptions extends CommonCommandOptions, Pick<AssetMigration, 'migrationId' | 'assetId'> {
|
|
3
|
+
stageOptions?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface NextStageParsedOptions extends Omit<NextStageOptions, 'stageOptions'> {
|
|
6
|
+
stageOptions?: Record<string, any>;
|
|
3
7
|
}
|
|
4
8
|
export interface NextStageApiResponse {
|
|
5
9
|
message: string;
|
|
@@ -6,6 +6,10 @@ export interface MatrixIdentifierSchema {
|
|
|
6
6
|
contentApiKey: string;
|
|
7
7
|
}
|
|
8
8
|
export interface SetMigrationSettingOptions extends CommonCommandOptions, MatrixIdentifierSchema {
|
|
9
|
+
stageOptions?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SetMigrationSettingParsedOptions extends Omit<SetMigrationSettingOptions, 'stageOptions'>, MatrixIdentifierSchema {
|
|
12
|
+
stageOptions?: Record<string, any>;
|
|
9
13
|
}
|
|
10
14
|
export interface SetMigrationSettingApiResponse extends MatrixIdentifierSchema {
|
|
11
15
|
}
|
|
@@ -21,3 +21,4 @@ __exportStar(require("./getMigration"), exports);
|
|
|
21
21
|
__exportStar(require("./nextStage"), exports);
|
|
22
22
|
__exportStar(require("./setMigrationSettings"), exports);
|
|
23
23
|
__exportStar(require("./revertMigration"), exports);
|
|
24
|
+
__exportStar(require("./loadStageOptionsFromFile"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loadStageOptionsFromFile: (filePath?: string) => any;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.loadStageOptionsFromFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const loadStageOptionsFromFile = (filePath) => {
|
|
9
|
+
if (!filePath) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
14
|
+
throw new Error(`Stage options file not found: ${filePath}`);
|
|
15
|
+
}
|
|
16
|
+
const fileContent = fs_1.default.readFileSync(filePath, 'utf8');
|
|
17
|
+
const stageOptions = JSON.parse(fileContent);
|
|
18
|
+
if (typeof stageOptions !== 'object' ||
|
|
19
|
+
stageOptions === null ||
|
|
20
|
+
Array.isArray(stageOptions)) {
|
|
21
|
+
throw new Error('Stage options file must contain a valid JSON object');
|
|
22
|
+
}
|
|
23
|
+
return stageOptions;
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
throw new Error(`Failed to load stage options from file: ${error.message}`);
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`Failed to load stage options from file: ${error}`);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.loadStageOptionsFromFile = loadStageOptionsFromFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const loadStageOptionsFromFile_1 = require("./loadStageOptionsFromFile");
|
|
8
|
+
jest.mock('fs');
|
|
9
|
+
const mockFs = fs_1.default;
|
|
10
|
+
describe('loadStageOptionsFromFile', () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
jest.clearAllMocks();
|
|
13
|
+
});
|
|
14
|
+
it('should return undefined when no file path is provided', () => {
|
|
15
|
+
const result = (0, loadStageOptionsFromFile_1.loadStageOptionsFromFile)();
|
|
16
|
+
expect(result).toBeUndefined();
|
|
17
|
+
});
|
|
18
|
+
it('should load and parse valid JSON file', () => {
|
|
19
|
+
const mockFilePath = '/test/path/options.json';
|
|
20
|
+
const mockJsonContent = '{"option1": "value1", "option2": "value2"}';
|
|
21
|
+
const expectedResult = { option1: 'value1', option2: 'value2' };
|
|
22
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
23
|
+
mockFs.readFileSync.mockReturnValue(mockJsonContent);
|
|
24
|
+
const result = (0, loadStageOptionsFromFile_1.loadStageOptionsFromFile)(mockFilePath);
|
|
25
|
+
expect(mockFs.existsSync).toHaveBeenCalledWith(mockFilePath);
|
|
26
|
+
expect(mockFs.readFileSync).toHaveBeenCalledWith(mockFilePath, 'utf8');
|
|
27
|
+
expect(result).toEqual(expectedResult);
|
|
28
|
+
});
|
|
29
|
+
it('should throw error when file does not exist', () => {
|
|
30
|
+
const mockFilePath = '/test/path/nonexistent.json';
|
|
31
|
+
mockFs.existsSync.mockReturnValue(false);
|
|
32
|
+
expect(() => (0, loadStageOptionsFromFile_1.loadStageOptionsFromFile)(mockFilePath)).toThrow(`Stage options file not found: ${mockFilePath}`);
|
|
33
|
+
});
|
|
34
|
+
it('should throw error when JSON is invalid', () => {
|
|
35
|
+
const mockFilePath = '/test/path/invalid.json';
|
|
36
|
+
const invalidJson = '{"invalid": json}';
|
|
37
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
38
|
+
mockFs.readFileSync.mockReturnValue(invalidJson);
|
|
39
|
+
expect(() => (0, loadStageOptionsFromFile_1.loadStageOptionsFromFile)(mockFilePath)).toThrow('Failed to load stage options from file:');
|
|
40
|
+
});
|
|
41
|
+
it('should throw error when JSON is not an object', () => {
|
|
42
|
+
const mockFilePath = '/test/path/array.json';
|
|
43
|
+
const arrayJson = '["item1", "item2"]';
|
|
44
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
45
|
+
mockFs.readFileSync.mockReturnValue(arrayJson);
|
|
46
|
+
expect(() => (0, loadStageOptionsFromFile_1.loadStageOptionsFromFile)(mockFilePath)).toThrow('Stage options file must contain a valid JSON object');
|
|
47
|
+
});
|
|
48
|
+
it('should throw error when JSON is null', () => {
|
|
49
|
+
const mockFilePath = '/test/path/null.json';
|
|
50
|
+
const nullJson = 'null';
|
|
51
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
52
|
+
mockFs.readFileSync.mockReturnValue(nullJson);
|
|
53
|
+
expect(() => (0, loadStageOptionsFromFile_1.loadStageOptionsFromFile)(mockFilePath)).toThrow('Stage options file must contain a valid JSON object');
|
|
54
|
+
});
|
|
55
|
+
it('should handle complex nested objects', () => {
|
|
56
|
+
const mockFilePath = '/test/path/complex.json';
|
|
57
|
+
const complexJson = JSON.stringify({
|
|
58
|
+
option1: 'value1',
|
|
59
|
+
nestedOption: {
|
|
60
|
+
subOption1: 'subValue1',
|
|
61
|
+
subOption2: 'subValue2',
|
|
62
|
+
},
|
|
63
|
+
arrayOption: ['item1', 'item2'],
|
|
64
|
+
});
|
|
65
|
+
mockFs.existsSync.mockReturnValue(true);
|
|
66
|
+
mockFs.readFileSync.mockReturnValue(complexJson);
|
|
67
|
+
const result = (0, loadStageOptionsFromFile_1.loadStageOptionsFromFile)(mockFilePath);
|
|
68
|
+
expect(result).toEqual({
|
|
69
|
+
option1: 'value1',
|
|
70
|
+
nestedOption: {
|
|
71
|
+
subOption1: 'subValue1',
|
|
72
|
+
subOption2: 'subValue2',
|
|
73
|
+
},
|
|
74
|
+
arrayOption: ['item1', 'item2'],
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { NextStageApiResponse,
|
|
2
|
-
export declare function nextStage(options:
|
|
1
|
+
import { NextStageApiResponse, NextStageParsedOptions } from '../types';
|
|
2
|
+
export declare function nextStage(options: NextStageParsedOptions): Promise<NextStageApiResponse>;
|
|
@@ -19,7 +19,8 @@ function nextStage(options) {
|
|
|
19
19
|
});
|
|
20
20
|
const migrationUrl = yield (0, _1.buildMigrationUrl)(options.tenant, options.overrideUrl);
|
|
21
21
|
try {
|
|
22
|
-
const
|
|
22
|
+
const payload = Object.assign({}, (options.stageOptions && { stageOptions: options.stageOptions }));
|
|
23
|
+
const response = yield apiService.client.post(`${migrationUrl}/${options.migrationId}/assets/${options.assetId}/next`, payload, {
|
|
23
24
|
headers: yield (0, _1.getMigrationHeaders)(options.tenant),
|
|
24
25
|
});
|
|
25
26
|
if (response.status !== 202) {
|
|
@@ -97,7 +97,7 @@ describe('nextStage', () => {
|
|
|
97
97
|
data: {},
|
|
98
98
|
};
|
|
99
99
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
100
|
-
yield expect((0, nextStage_1.nextStage)(mockOptions)).rejects.toThrow('Invalid response format from next stage');
|
|
100
|
+
yield expect((0, nextStage_1.nextStage)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }))).rejects.toThrow('Invalid response format from next stage');
|
|
101
101
|
}));
|
|
102
102
|
it('handles API service errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
103
|
const error = new Error('Network error');
|
|
@@ -7,7 +7,8 @@ export declare enum OptionName {
|
|
|
7
7
|
MIGRATION_ID = "migration-id",
|
|
8
8
|
MATRIX_IDENTIFIER = "matrix-identifier",
|
|
9
9
|
MATRIX_KEY = "matrix-key",
|
|
10
|
-
CONTENT_API_KEY = "content-api-key"
|
|
10
|
+
CONTENT_API_KEY = "content-api-key",
|
|
11
|
+
STAGE_OPTIONS = "stage-options"
|
|
11
12
|
}
|
|
12
13
|
export declare const getParamOption: (param: OptionName, makeOptionMandatory?: boolean) => Option;
|
|
13
14
|
export declare const addOverrideUrlOption: (command: Command) => void;
|
|
@@ -12,6 +12,7 @@ var OptionName;
|
|
|
12
12
|
OptionName["MATRIX_IDENTIFIER"] = "matrix-identifier";
|
|
13
13
|
OptionName["MATRIX_KEY"] = "matrix-key";
|
|
14
14
|
OptionName["CONTENT_API_KEY"] = "content-api-key";
|
|
15
|
+
OptionName["STAGE_OPTIONS"] = "stage-options";
|
|
15
16
|
})(OptionName = exports.OptionName || (exports.OptionName = {}));
|
|
16
17
|
const params = new Map([
|
|
17
18
|
[
|
|
@@ -70,6 +71,13 @@ const params = new Map([
|
|
|
70
71
|
description: 'The Content API key for the Migrator API to interact with Content API',
|
|
71
72
|
},
|
|
72
73
|
],
|
|
74
|
+
[
|
|
75
|
+
OptionName.STAGE_OPTIONS,
|
|
76
|
+
{
|
|
77
|
+
flags: '--stage-options <path>',
|
|
78
|
+
description: 'Path to a JSON file containing stage options',
|
|
79
|
+
},
|
|
80
|
+
],
|
|
73
81
|
]);
|
|
74
82
|
const getParamOption = (param, makeOptionMandatory = true) => {
|
|
75
83
|
const paramInfo = params.get(param);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function setMigrationSettings(options:
|
|
1
|
+
import { SetMigrationSettingParsedOptions, SetMigrationSettingApiResponse } from '../types';
|
|
2
|
+
export declare function setMigrationSettings(options: SetMigrationSettingParsedOptions): Promise<SetMigrationSettingApiResponse>;
|
|
@@ -19,13 +19,7 @@ function setMigrationSettings(options) {
|
|
|
19
19
|
});
|
|
20
20
|
const migrationUrl = yield (0, _1.buildMigrationUrl)(options.tenant, options.overrideUrl, 'settings');
|
|
21
21
|
try {
|
|
22
|
-
const payload = {
|
|
23
|
-
matrixUrl: options.matrixUrl,
|
|
24
|
-
matrixIdentifier: options.matrixIdentifier,
|
|
25
|
-
matrixKey: options.matrixKey,
|
|
26
|
-
contentApiKey: options.contentApiKey,
|
|
27
|
-
};
|
|
28
|
-
console.log('payload', payload);
|
|
22
|
+
const payload = Object.assign({ matrixUrl: options.matrixUrl, matrixIdentifier: options.matrixIdentifier, matrixKey: options.matrixKey, contentApiKey: options.contentApiKey }, (options.stageOptions && { stageOptions: options.stageOptions }));
|
|
29
23
|
const response = yield apiService.client.post(migrationUrl, payload, {
|
|
30
24
|
headers: yield (0, _1.getMigrationHeaders)(options.tenant),
|
|
31
25
|
});
|
|
@@ -68,7 +68,7 @@ describe('setMigrationSettings', () => {
|
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
70
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
71
|
-
const result = yield (0, setMigrationSettings_1.setMigrationSettings)(mockOptions);
|
|
71
|
+
const result = yield (0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }));
|
|
72
72
|
expect(result).toEqual({
|
|
73
73
|
matrixUrl: 'https://matrix.example.com',
|
|
74
74
|
matrixIdentifier: 'test-identifier',
|
|
@@ -82,6 +82,7 @@ describe('setMigrationSettings', () => {
|
|
|
82
82
|
matrixIdentifier: 'test-identifier',
|
|
83
83
|
matrixKey: 'test-key-123',
|
|
84
84
|
contentApiKey: 'test-content-api-key-456',
|
|
85
|
+
stageOptions: {},
|
|
85
86
|
}, {
|
|
86
87
|
headers: {
|
|
87
88
|
'Content-Type': 'application/json',
|
|
@@ -102,7 +103,7 @@ describe('setMigrationSettings', () => {
|
|
|
102
103
|
},
|
|
103
104
|
};
|
|
104
105
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
105
|
-
yield (0, setMigrationSettings_1.setMigrationSettings)(optionsWithOverride);
|
|
106
|
+
yield (0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, optionsWithOverride), { stageOptions: {} }));
|
|
106
107
|
expect(mockBuildMigrationUrl).toHaveBeenCalledWith('test-tenant', 'https://custom.migration.url', 'settings');
|
|
107
108
|
}));
|
|
108
109
|
it('should handle non-success status codes', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -111,7 +112,7 @@ describe('setMigrationSettings', () => {
|
|
|
111
112
|
data: {},
|
|
112
113
|
};
|
|
113
114
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
114
|
-
yield expect((0, setMigrationSettings_1.setMigrationSettings)(mockOptions)).rejects.toThrow('Migration settings update failed with status: 400');
|
|
115
|
+
yield expect((0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }))).rejects.toThrow('Migration settings update failed with status: 400');
|
|
115
116
|
}));
|
|
116
117
|
it('should handle missing response data', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
118
|
const mockResponse = {
|
|
@@ -119,16 +120,16 @@ describe('setMigrationSettings', () => {
|
|
|
119
120
|
data: null,
|
|
120
121
|
};
|
|
121
122
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
122
|
-
yield expect((0, setMigrationSettings_1.setMigrationSettings)(mockOptions)).rejects.toThrow('No data returned from migration service');
|
|
123
|
+
yield expect((0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }))).rejects.toThrow('No data returned from migration service');
|
|
123
124
|
}));
|
|
124
125
|
it('should handle API service errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
126
|
const error = new Error('Network error');
|
|
126
127
|
mockApiServiceInstance.client.post.mockRejectedValue(error);
|
|
127
|
-
yield expect((0, setMigrationSettings_1.setMigrationSettings)(mockOptions)).rejects.toThrow('Network error');
|
|
128
|
+
yield expect((0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }))).rejects.toThrow('Network error');
|
|
128
129
|
}));
|
|
129
130
|
it('should handle unknown errors', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
131
|
mockApiServiceInstance.client.post.mockRejectedValue('Unknown error');
|
|
131
|
-
yield expect((0, setMigrationSettings_1.setMigrationSettings)(mockOptions)).rejects.toThrow('Failed to set migration settings: Unknown error');
|
|
132
|
+
yield expect((0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }))).rejects.toThrow('Failed to set migration settings: Unknown error');
|
|
132
133
|
}));
|
|
133
134
|
it('should redact matrix key in response', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
134
135
|
const mockResponse = {
|
|
@@ -142,7 +143,7 @@ describe('setMigrationSettings', () => {
|
|
|
142
143
|
};
|
|
143
144
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
144
145
|
mockRedactKey.mockReturnValue('***123');
|
|
145
|
-
const result = yield (0, setMigrationSettings_1.setMigrationSettings)(mockOptions);
|
|
146
|
+
const result = yield (0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }));
|
|
146
147
|
expect(result.matrixKey).toBe('***123');
|
|
147
148
|
expect(mockRedactKey).toHaveBeenCalledWith('test-key-123', 3);
|
|
148
149
|
}));
|
|
@@ -155,7 +156,7 @@ describe('setMigrationSettings', () => {
|
|
|
155
156
|
},
|
|
156
157
|
};
|
|
157
158
|
mockApiServiceInstance.client.post.mockResolvedValue(mockResponse);
|
|
158
|
-
const result = yield (0, setMigrationSettings_1.setMigrationSettings)(mockOptions);
|
|
159
|
+
const result = yield (0, setMigrationSettings_1.setMigrationSettings)(Object.assign(Object.assign({}, mockOptions), { stageOptions: {} }));
|
|
159
160
|
expect(result.matrixKey).toBe('');
|
|
160
161
|
expect(mockRedactKey).not.toHaveBeenCalled();
|
|
161
162
|
}));
|