diff --git a/docs/faq.md b/docs/faq.md index 93bf9ad9e02393391da8db9114029ff4de48f90d..de5b181ab2bb8630b100241413a7ab903f8d08aa 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -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 ``` diff --git a/lib/config/migration.js b/lib/config/migration.js index cb395816acb34799f38032dccede370b3cc33834..73399a8f252999c602203b519d2de19082fa263b 100644 --- a/lib/config/migration.js +++ b/lib/config/migration.js @@ -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]; diff --git a/test/config/__snapshots__/migration.spec.js.snap b/test/config/__snapshots__/migration.spec.js.snap index 6c540b234216afb81ed541acff3b137319c6a32d..3f8ee96f270855d1bae9e36b9af391a43267cbe1 100644 --- a/test/config/__snapshots__/migration.spec.js.snap +++ b/test/config/__snapshots__/migration.spec.js.snap @@ -1,5 +1,11 @@ // 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", diff --git a/test/config/migration.spec.js b/test/config/migration.spec.js index 289f4760a4dcd8de85b16467a7d08d09905ee4a1..cd6c99472f86be9ca836056333ec0b1b9a6e0923 100644 --- a/test/config/migration.spec.js +++ b/test/config/migration.spec.js @@ -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: [ diff --git a/test/workers/branch/schedule.spec.js b/test/workers/branch/schedule.spec.js index 8b09c38b1aa933d4d52e2ceca0e5069a9bd59684..6e5e8659ecc91a7510abc3a802669e8f5519f062 100644 --- a/test/workers/branch/schedule.spec.js +++ b/test/workers/branch/schedule.spec.js @@ -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); });