Skip to content

Commit 19b5ce5

Browse files
feat: adds excluded days of week logic
1 parent 6cbe27c commit 19b5ce5

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

models/discordactions.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ const updateUsersWith31DaysPlusOnboarding = async () => {
841841
};
842842

843843
const getMissedProgressUpdatesUsers = async (options = {}) => {
844-
const { cursor, size = 500, excludedDates = [], dateGap = 3 } = options;
844+
const { cursor, size = 500, excludedDates = [], excludedDays = [0], dateGap = 3 } = options;
845845
const stats = {
846846
tasks: 0,
847847
missedUpdatesTasks: 0,
@@ -858,6 +858,17 @@ const getMissedProgressUpdatesUsers = async (options = {}) => {
858858
}
859859
});
860860

861+
if (excludedDays.length === 7) {
862+
return { usersToAddRole: [], ...stats };
863+
}
864+
865+
for (let i = gapWindowEnd; i >= gapWindowStart; i -= convertDaysToMilliseconds(1)) {
866+
const day = new Date(i).getDay();
867+
if (excludedDays.includes(day)) {
868+
gapWindowStart -= convertDaysToMilliseconds(1);
869+
}
870+
}
871+
861872
let taskQuery = buildTasksQueryForMissedUpdates(gapWindowStart, size);
862873

863874
if (cursor) {

test/unit/models/discordactions.test.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ describe("discordactions", function () {
595595
let activeUserWithProgressUpdates;
596596
let idleUser;
597597
let userNotInDiscord;
598+
let activeUserId;
598599
beforeEach(async function () {
599600
idleUser = { ...userData[9], discordId: getDiscordMembers[0].user.id };
600601
activeUserWithProgressUpdates = { ...userData[10], discordId: getDiscordMembers[1].user.id };
@@ -611,6 +612,7 @@ describe("discordactions", function () {
611612
await addUser(activeUserWithNoUpdates), // active user with no task progress updates
612613
await addUser(userNotInDiscord), // OOO user with
613614
]);
615+
activeUserId = userIdList[2];
614616
await Promise.all([
615617
await userStatusModel.updateUserStatus(userIdList[0], idleUserStatus),
616618
await userStatusModel.updateUserStatus(userIdList[1], activeUserStatus),
@@ -625,12 +627,12 @@ describe("discordactions", function () {
625627
const validTask = {
626628
...task,
627629
assignee: userIdList[index],
628-
startedOn: (new Date().getTime() - convertDaysToMilliseconds(5)) / 1000,
630+
startedOn: (new Date().getTime() - convertDaysToMilliseconds(7)) / 1000,
629631
endsOn: (new Date().getTime() + convertDaysToMilliseconds(4)) / 1000,
630632
status: TASK_STATUS.IN_PROGRESS,
631633
};
632634

633-
tasksPromise.push(await tasksModel.add(validTask));
635+
tasksPromise.push(tasksModel.add(validTask));
634636
}
635637
const taskIdList = (await Promise.all(tasksPromise)).map((tasksDoc) => tasksDoc.id);
636638
const progressDataList = [];
@@ -676,7 +678,6 @@ describe("discordactions", function () {
676678
date3.setDate(date3.getDate() - 3);
677679
const date4 = new Date();
678680
date4.setDate(date4.getDate() - 4);
679-
// this should now only get users who have not provided any update in last 7 days instead of 3;
680681
const result = await getMissedProgressUpdatesUsers({
681682
excludedDates: [date.valueOf(), date2.valueOf(), date3.valueOf(), date4.valueOf()],
682683
});
@@ -688,6 +689,40 @@ describe("discordactions", function () {
688689
});
689690
});
690691

692+
it("should not list of users when all days of week are excluded", async function () {
693+
const result = await getMissedProgressUpdatesUsers({
694+
excludedDays: [0, 1, 2, 3, 4, 5, 6],
695+
});
696+
expect(result).to.be.an("object");
697+
expect(result).to.be.deep.equal({
698+
tasks: 0,
699+
missedUpdatesTasks: 0,
700+
usersToAddRole: [],
701+
});
702+
});
703+
it("should not list any users since 5 days of weeks are excluded", async function () {
704+
const oneMonthOldTask = { ...tasksData[0] };
705+
oneMonthOldTask.assignee = activeUserId;
706+
oneMonthOldTask.startedOn = (new Date().getTime() - convertDaysToMilliseconds(30)) / 1000;
707+
oneMonthOldTask.endsOn = (new Date().getTime() + convertDaysToMilliseconds(4)) / 1000;
708+
const taskId = (await tasksModel.add(oneMonthOldTask)).id;
709+
const date = new Date();
710+
date.setDate(date.getDate() - 29);
711+
const progressData = stubbedModelTaskProgressData(null, taskId, date.getTime(), date.valueOf());
712+
await createProgressDocument(progressData);
713+
714+
const result = await getMissedProgressUpdatesUsers({
715+
excludedDays: [0, 1, 2, 3, 4, 5],
716+
dateGap: 3,
717+
});
718+
expect(result).to.be.an("object");
719+
expect(result).to.be.deep.equal({
720+
tasks: 1,
721+
missedUpdatesTasks: 0,
722+
usersToAddRole: [],
723+
});
724+
});
725+
691726
it("should process only 1 task when size is passed as 1", async function () {
692727
const result = await getMissedProgressUpdatesUsers({ size: 1 });
693728

0 commit comments

Comments
 (0)