Updating daysOfMonths array when the startDate of a monthly is updated in the API - Fixes #12041 (#12399)

* Updating daily daysOfMonth array when startDate is updated and adding integration tests to test this functionality

* Adding more test cases and adding semicolons to the end of lines

* Only updating the monthly repetition if the daily was already set to repeat on a day of the month

* fix(lint): whitespace

Co-authored-by: Laurel Thomson <laurel.beth.thomson@gmai.com>
Co-authored-by: Sabe Jones <sabrecat@gmail.com>
This commit is contained in:
Laurel Thomson
2020-07-31 02:16:55 -07:00
committed by GitHub
parent c4049608a8
commit 1f8e2d5677
2 changed files with 48 additions and 0 deletions

View File

@@ -499,6 +499,45 @@ describe('PUT /tasks/:id', () => {
});
});
context('monthly dailys', () => {
let monthly;
beforeEach(async () => {
const date1 = moment.utc('2020-07-01').toDate();
monthly = await user.post('/tasks/user', {
text: 'test monthly',
type: 'daily',
frequency: 'monthly',
startDate: date1,
daysOfMonth: [date1.getDate()],
});
});
it('updates days of month when start date updated', async () => {
const date2 = moment.utc('2020-07-01').toDate();
const savedMonthly = await user.put(`/tasks/${monthly._id}`, {
startDate: date2,
});
expect(savedMonthly.daysOfMonth).to.deep.equal([moment(date2).date()]);
});
it('updates next due when start date updated', async () => {
const date2 = moment.utc('2020-07-01').toDate();
const savedMonthly = await user.put(`/tasks/${monthly._id}`, {
startDate: date2,
});
expect(savedMonthly.nextDue.length).to.eql(6);
expect(moment(savedMonthly.nextDue[0]).toDate()).to.eql(moment.utc('2020-08-01').toDate());
expect(moment(savedMonthly.nextDue[1]).toDate()).to.eql(moment.utc('2020-09-01').toDate());
expect(moment(savedMonthly.nextDue[2]).toDate()).to.eql(moment.utc('2020-10-01').toDate());
expect(moment(savedMonthly.nextDue[3]).toDate()).to.eql(moment.utc('2020-11-01').toDate());
expect(moment(savedMonthly.nextDue[4]).toDate()).to.eql(moment.utc('2020-12-01').toDate());
expect(moment(savedMonthly.nextDue[5]).toDate()).to.eql(moment.utc('2021-01-01').toDate());
});
});
context('rewards', () => {
let reward;