Skip to content
Snippets Groups Projects
Commit e443e6b8 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix: only migrate 'and' schedule if it includes before and after (#724)

parent 5693b17e
No related branches found
No related tags found
No related merge requests found
......@@ -61,8 +61,8 @@ Example scheduling:
```
every weekend
before 5:00am
after 10pm and before 5:00am
after 10pm and before 5am every weekday
[after 10pm, before 5:00am]
[after 10pm every weekday, before 5am every weekday]
on friday and saturday
```
......
......@@ -80,7 +80,11 @@ function migrateConfig(config, parentConfig) {
let schedules = typeof val === 'string' ? [val] : val;
// split 'and'
for (let i = 0; i < schedules.length; i += 1) {
if (schedules[i].indexOf(' and ') !== -1) {
if (
schedules[i].includes(' and ') &&
schedules[i].includes('before ') &&
schedules[i].includes('after ')
) {
isMigrated = true;
const split = schedules[i].split(' and ');
schedules[i] = split[0];
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`config/migration migrateConfig(config, parentConfig) does not migrate multi days 1`] = `
Object {
"schedule": "after 5:00pm on wednesday and thursday",
}
`;
exports[`config/migration migrateConfig(config, parentConfig) it migrates config 1`] = `
Object {
"autodiscover": true,
......@@ -101,7 +107,7 @@ Object {
}
`;
exports[`config/migration migrateConfig(config, parentConfig) migrates schedules with and 1`] = `
exports[`config/migration migrateConfig(config, parentConfig) migrates before and after schedules 1`] = `
Object {
"schedule": Array [
"after 10pm",
......
......@@ -57,7 +57,7 @@ describe('config/migration', () => {
expect(migratedConfig.automerge).toEqual(false);
expect(migratedConfig).toMatchSnapshot();
});
it('migrates schedules with and', () => {
it('migrates before and after schedules', () => {
const config = {
schedule: 'after 10pm and before 7am',
};
......@@ -72,6 +72,19 @@ describe('config/migration', () => {
expect(migratedConfig.schedule[0]).toEqual('after 10pm');
expect(migratedConfig.schedule[1]).toEqual('before 7am');
});
it('does not migrate multi days', () => {
const config = {
schedule: 'after 5:00pm on wednesday and thursday',
};
const parentConfig = { ...defaultConfig };
const { isMigrated, migratedConfig } = configMigration.migrateConfig(
config,
parentConfig
);
expect(migratedConfig).toMatchSnapshot();
expect(isMigrated).toBe(false);
expect(migratedConfig.schedule).toEqual(config.schedule);
});
it('it migrates packages', () => {
const config = {
packages: [
......
......@@ -38,6 +38,11 @@ describe('workers/branch/schedule', () => {
true
);
});
it('returns true for multi day schedules', () => {
expect(
schedule.hasValidSchedule(['after 5:00pm on wednesday and thursday'])[0]
).toBe(true);
});
it('returns true if schedule has a start time', () => {
expect(schedule.hasValidSchedule(['after 8:00pm'])[0]).toBe(true);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment