mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 17:52:22 +00:00
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:
parent
c4049608a8
commit
1f8e2d5677
2 changed files with 48 additions and 0 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -681,6 +681,15 @@ api.updateTask = {
|
|||
task.group.managerNotes = sanitizedObj.managerNotes;
|
||||
}
|
||||
|
||||
// If the task was set to repeat monthly on a day of the month, and the start date was updated,
|
||||
// the task will then need to be updated to repeat on the same day of the month as the new
|
||||
// start date. For example, if the start date is updated to 7/2/2020, the daily should
|
||||
// repeat on the 2nd day of the month. It's possible that a task can repeat monthly on a
|
||||
// week of the month, in which case we won't update the repetition at all.
|
||||
if (task.frequency === 'monthly' && task.daysOfMonth.length && task.startDate) {
|
||||
task.daysOfMonth = [moment(task.startDate).date()];
|
||||
}
|
||||
|
||||
setNextDue(task, user);
|
||||
const savedTask = await task.save();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue