From 5c1947108d98c26c9dffb3e15e6f99d06aa5076f Mon Sep 17 00:00:00 2001
From: Jamie Magee <JamieMagee@users.noreply.github.com>
Date: Mon, 24 Aug 2020 10:43:21 +0200
Subject: [PATCH] test: feature support for prs rarer than 1 month (#7033)

---
 docs/usage/configuration-options.md     |  1 +
 lib/config/presets/internal/schedule.ts |  4 ++++
 lib/workers/branch/schedule.spec.ts     | 29 +++++++++++++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md
index ea788d3374..d52c79888b 100644
--- a/docs/usage/configuration-options.md
+++ b/docs/usage/configuration-options.md
@@ -1411,6 +1411,7 @@ before 5:00am
 after 10pm and before 5:00am
 after 10pm and before 5am every weekday
 on friday and saturday
+every 3 months on the first day of the month
 ```
 
 One example might be that you don't want Renovate to run during your typical business hours, so that your build machines don't get clogged up testing `package.json` updates. You could then configure a schedule like this at the repository level:
diff --git a/lib/config/presets/internal/schedule.ts b/lib/config/presets/internal/schedule.ts
index 6281b100d2..9de5cb1c67 100644
--- a/lib/config/presets/internal/schedule.ts
+++ b/lib/config/presets/internal/schedule.ts
@@ -17,6 +17,10 @@ export const presets: Record<string, Preset> = {
     description: 'Schedule monthly',
     schedule: ['before 3am on the first day of the month'],
   },
+  quarterly: {
+    description: 'Schedule quarterly',
+    schedule: ['every 3 months on the first day of the month'],
+  },
   weekends: {
     description: 'Schedule for weekends',
     schedule: ['every weekend'],
diff --git a/lib/workers/branch/schedule.spec.ts b/lib/workers/branch/schedule.spec.ts
index 53679c5666..ccd5f46f62 100644
--- a/lib/workers/branch/schedule.spec.ts
+++ b/lib/workers/branch/schedule.spec.ts
@@ -61,6 +61,11 @@ describe('workers/branch/schedule', () => {
         schedule.hasValidSchedule(['on the first day of the month'])[0]
       ).toBe(true);
     });
+    it('returns true for schedules longer than 1 month', () => {
+      expect(schedule.hasValidSchedule(['every 3 months'])[0]).toBe(true);
+      expect(schedule.hasValidSchedule(['every 6 months'])[0]).toBe(true);
+      expect(schedule.hasValidSchedule(['every 12 months'])[0]).toBe(true);
+    });
     it('returns true if schedule has an end time', () => {
       expect(schedule.hasValidSchedule(['before 6:00am'])[0]).toBe(true);
     });
@@ -227,5 +232,29 @@ describe('workers/branch/schedule', () => {
       const res = schedule.isScheduledNow(config);
       expect(res).toBe(false);
     });
+    it('approves schedule longer than 1 month', () => {
+      config.schedule = ['every 3 months'];
+      mockDate.set('2017-07-01T06:00:00.000'); // Locally Saturday, 1 July 2017 6am
+      const res = schedule.isScheduledNow(config);
+      expect(res).toBe(true);
+    });
+    it('rejects schedule longer than 1 month', () => {
+      config.schedule = ['every 6 months'];
+      mockDate.set('2017-02-01T06:00:00.000'); // Locally Thursday, 2 February 2017 6am
+      const res = schedule.isScheduledNow(config);
+      expect(res).toBe(false);
+    });
+    it('approves schedule longer than 1 month with day of month', () => {
+      config.schedule = ['every 3 months on the first day of the month'];
+      mockDate.set('2017-07-01T06:00:00.000'); // Locally Saturday, 1 July 2017 6am
+      const res = schedule.isScheduledNow(config);
+      expect(res).toBe(true);
+    });
+    it('rejects schedule longer than 1 month with day of month', () => {
+      config.schedule = ['every 3 months on the first day of the month'];
+      mockDate.set('2017-02-01T06:00:00.000'); // Locally Thursday, 2 February 2017 6am
+      const res = schedule.isScheduledNow(config);
+      expect(res).toBe(false);
+    });
   });
 });
-- 
GitLab