Skip to content

Commit

Permalink
Merge pull request #17 from dichaudhary/CQ-4328314
Browse files Browse the repository at this point in the history
CQ-4328314: Test cases, Configs validity for tools
  • Loading branch information
dichaudhary authored Jul 27, 2021
2 parents e5b3ee6 + 2e6572a commit d8655ff
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/commands/aem-migration/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,33 @@ async function runDispatcherConverter(config, command) {
const flag = flags.type;
command.log("\n********** Executing Dispatcher Converter **********");
command.log("Converting Dispatcher Configurations...");
let isConfigValid = false;
if (flag && flag.toLowerCase() === "ams") {
helper.createBaseDispatcherConfig(config.dispatcherConverter.ams.cfg);
let aemDispatcherConfigConverter = new DispatcherConverter.AEMDispatcherConfigConverter(
config.dispatcherConverter,
Commons.constants.TARGET_DISPATCHER_SRC_FOLDER
);
aemDispatcherConfigConverter.transform();
if (aemDispatcherConfigConverter.checkConfig(config.dispatcherConverter)) {
isConfigValid = true;
aemDispatcherConfigConverter.transform();
}
} else {
helper.createBaseDispatcherConfig(config.dispatcherConverter.sdkSrc);
let singleFilesConverter = new DispatcherConverter.SingleFilesConverter(
config.dispatcherConverter,
Commons.constants.TARGET_DISPATCHER_SRC_FOLDER
);
singleFilesConverter.transform();
if (singleFilesConverter.checkConfig(config.dispatcherConverter)) {
isConfigValid = true;
singleFilesConverter.transform();
}
}
if (!isConfigValid) {
command.log(
`Missing configuration! Please check ${Commons.constants.LOG_FILE} for more information.`
);
return;
}
command.log("\nConversion Complete!");
command.log(
Expand Down
17 changes: 15 additions & 2 deletions src/commands/aem-migration/dispatcher-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DispatcherConverterCommand extends Command {
);
let config = helper.readConfigFile(this.config.configDir);
const { flags } = this.parse(DispatcherConverterCommand);
let isConfigValid = false;
if (flags.type && flags.type.toLowerCase() === "ams") {
helper.createBaseDispatcherConfig(
config.dispatcherConverter.ams.cfg
Expand All @@ -33,7 +34,10 @@ class DispatcherConverterCommand extends Command {
config.dispatcherConverter,
Commons.constants.TARGET_DISPATCHER_SRC_FOLDER
);
aemDispatcherConfigConverter.transform();
if (aemDispatcherConfigConverter.checkConfig(config.dispatcherConverter)) {
isConfigValid = true;
aemDispatcherConfigConverter.transform();
}
} else {
helper.createBaseDispatcherConfig(
config.dispatcherConverter.sdkSrc
Expand All @@ -42,7 +46,16 @@ class DispatcherConverterCommand extends Command {
config.dispatcherConverter,
Commons.constants.TARGET_DISPATCHER_SRC_FOLDER
);
singleFilesConverter.transform();
if (singleFilesConverter.checkConfig(config.dispatcherConverter)) {
isConfigValid = true;
singleFilesConverter.transform();
}
}
if (!isConfigValid) {
this.log(
`Missing configuration! Please check ${Commons.constants.LOG_FILE} for more information.`
);
return;
}
this.log("\nConversion Complete!");
this.log(
Expand Down
5 changes: 5 additions & 0 deletions src/commands/aem-migration/workflow-migrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class WorkflowMigratorCommand extends Command {
try {
helper.clearOutputFolder(constants.TARGET_WORKFLOW_FOLDER);
let config = helper.readConfigFile(this.config.configDir);
if (!helper.isWorkflowConfigValid(config.workflowMigrator)) {
// invalid wf-migrator related configs found.
this.log(`Invalid configuration! Please check ${Commons.constants.LOG_FILE} for more information.\n`);
return;
}
helper
.fetchLatestReleasedAsset(
constants.WF_MIGRATOR_REPO_OWNER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ governing permissions and limitations under the License.
*/

const mockTransform = jest.fn();
const checkConfig = jest.fn(()=> {return true});

const AEMDispatcherConfigConverter = jest.fn().mockImplementation(() => {
return { transform: mockTransform };
return { transform: mockTransform,
checkConfig: checkConfig,
};
});

const SingleFilesConverter = jest.fn().mockImplementation(() => {
return { transform: mockTransform };
return { transform: mockTransform,
checkConfig: checkConfig,
};
});

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions test/commands/workflow-migrator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("Test Command", () => {
command.config = {
configDir: configDir,
};
helper.isWorkflowConfigValid.mockReturnValue(true);
helper.clearOutputFolder.mockResolvedValue(true);
helper.readConfigFile.mockReturnValue(config);
helper.fetchLatestReleasedAsset.mockResolvedValue(true);
Expand Down

0 comments on commit d8655ff

Please sign in to comment.