Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(page-job-scheduler): corrige erro quando 'firstExecution' undefined #2327

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,22 @@ describe('PoPageJobSchedulerComponent:', () => {
expect(executionElementHiddenAttribute).toBeFalsy();
});
});

it(`getSteps: should use 'literals' when the parameterization step title is not defined`, () => {
const mock = Object.assign(new QueryList(), {
_results: [{}, {}],
length: 1
}) as QueryList<PoJobSchedulerParametersTemplateDirective>;

component.parametersTemplate = mock;
component['getSteps']();

const result = component['steps'].slice(1, -1);
const resultExpected = [
{ label: `${component['literals']['parameterization']} 1` },
{ label: `${component['literals']['parameterization']} 2` }
];

expect(result).toEqual(resultExpected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,84 @@ describe('PoPageJobSchedulerService:', () => {
expect(poPageJobSchedulerService['removeInvalidKeys']).toHaveBeenCalledWith(jobSchedulerInternal);
});

it(`convertToJobScheduler: should ignore when 'firstExecutionHour' is set but 'firstExecution' is not set`, () => {
const jobSchedulerInternal = {
executionParameter: 'value',
firstExecution: undefined,
firstExecutionHour: '15:30',
processID: '1'
};

const jobSchedulerInternalExpected = {
executionParameter: 'value',
firstExecution: undefined,
processID: '1'
};

const result = <any>poPageJobSchedulerService['convertToJobScheduler'](jobSchedulerInternal);

expect(result).toEqual(jobSchedulerInternalExpected);
});

it(`convertToJobScheduler: should ignore when 'firstExecutionHour' is set but 'firstExecution' is set date invalid`, () => {
const jobSchedulerInternal = {
executionParameter: 'value',
firstExecution: 'XPTO',
firstExecutionHour: '99',
processID: '1'
};

const jobSchedulerInternalExpected = {
executionParameter: 'value',
firstExecution: 'XPTO',
processID: '1'
};

const result = <any>poPageJobSchedulerService['convertToJobScheduler'](jobSchedulerInternal);

expect(result).toEqual(jobSchedulerInternalExpected);
});

it(`convertToJobScheduler: should ignore when 'firstExecutionHour' is set but 'firstExecution' is set string in format yyyy-mm-dd`, () => {
const jobSchedulerInternal = {
executionParameter: 'value',
firstExecution: 'XPTO-XP-TO',
firstExecutionHour: '15:30',
processID: '1'
};

const jobSchedulerInternalExpected = {
executionParameter: 'value',
firstExecution: 'XPTO-XP-TO',
processID: '1'
};

const result = <any>poPageJobSchedulerService['convertToJobScheduler'](jobSchedulerInternal);

expect(result).toEqual(jobSchedulerInternalExpected);
});

it(`convertToJobScheduler: should ignore 'firstExecutionHour' when thrown error`, () => {
const jobSchedulerInternal = {
executionParameter: 'value',
firstExecution: '2024-12-30',
firstExecutionHour: '15:30',
processID: '1'
};

const jobSchedulerInternalExpected = {
executionParameter: 'value',
firstExecution: '2024-12-30',
processID: '1'
};

spyOn(utilsFunctions, 'convertDateToISOExtended').and.throwError('Convert Date');

const result = <any>poPageJobSchedulerService['convertToJobScheduler'](jobSchedulerInternal);

expect(result).toEqual(jobSchedulerInternalExpected);
});

it(`convertToJobSchedulerInternal: should set 'jobSchedulerInternal.firstExecutionHour' with 'getHourFirstExecution'
return if 'firstExecution' is defined`, () => {
const jobSchedulerInternal = {
Expand Down Expand Up @@ -482,6 +560,7 @@ describe('PoPageJobSchedulerService:', () => {

expect(result).toEqual(jobSchedulerInternalExpected);
});

it(`convertToJobSchedulerInternal: should return the merge between 'jobSchedulerInternal' and
the return from 'convertToPeriodicityInternal'`, () => {
const jobSchedulerInternal = {
Expand Down Expand Up @@ -787,6 +866,15 @@ describe('PoPageJobSchedulerService:', () => {
);
});

it(`replaceHourFirstExecution: should replace hour add time zone`, () => {
const stringDate = new Date().toString();
const timeZone = `${stringDate.substring(28, 31)}:${stringDate.substring(31, 33)}`;

const result = `2025-12-24T23:59:00${timeZone}`;

expect(poPageJobSchedulerService['replaceHourFirstExecution']('2025-12-24', '23:59')).toBe(result);
});

it('returnValidExecutionParameter: should remove keys that have undefined value', () => {
const parameter = {
numberKey: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,35 @@ export class PoPageJobSchedulerService {
}

private replaceHourFirstExecution(date: string, time: string): string {
const dateSplited = date.split('-');
const year = parseInt(dateSplited[0]);
const monthIndex = parseInt(dateSplited[1]) - 1;
const day = parseInt(dateSplited[2]);
try {
if (!date) {
return date;
}

const dateSplited = date.split('-');
const timeSplited = time.split(':');

if (dateSplited.length < 2 || timeSplited.length < 1) {
return date;
}

const timeSplited = time.split(':');
const hours = parseInt(timeSplited[0], 10);
const minutes = parseInt(timeSplited[1], 10);
const year = parseInt(dateSplited[0]);
const monthIndex = parseInt(dateSplited[1]) - 1;
const day = parseInt(dateSplited[2]);

const firstExecutionDate = new Date(year, monthIndex, day, hours, minutes);
const hours = parseInt(timeSplited[0], 10);
const minutes = parseInt(timeSplited[1], 10);

return convertDateToISOExtended(firstExecutionDate);
const firstExecutionDate = new Date(year, monthIndex, day, hours, minutes);

if (!(firstExecutionDate instanceof Date && !isNaN(firstExecutionDate.getTime()))) {
return date;
}

return convertDateToISOExtended(firstExecutionDate);
} catch {
return date;
}
}

private returnValidExecutionParameter(parameter: object) {
Expand Down
Loading