Skip to content

Commit c65dfaa

Browse files
committed
Adds a test case to taskManager.
The new test covers the case in which `getTasks` is invoked with a `dueDate` parameter. None of the existing test cases covers this case. The new test case aims to verify the behavior of `getTasks` when a `dueDate` is provided, ensuring that the `nextDue` property is properly set for daily tasks based on the given dueDate. The new test adds new coverage: - 3 lines in server/libs/tasks/utils.js, in `setNextDue` - 20 lines in server/libs/tasks/index.js, mostly in `getTasks`
1 parent 439451a commit c65dfaa

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

Diff for: test/api/unit/libs/taskManager.js

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import moment from 'moment';
12
import {
23
createTasks,
34
getTasks,
@@ -15,8 +16,9 @@ import {
1516
} from '../../../helpers/api-unit.helper';
1617

1718
describe('taskManager', () => {
18-
let user; let group; let
19-
challenge;
19+
let user;
20+
let group;
21+
let challenge;
2022
const testHabit = {
2123
text: 'test habit',
2224
type: 'habit',
@@ -127,6 +129,60 @@ describe('taskManager', () => {
127129
expect(task.createdAt).to.exist;
128130
});
129131

132+
it('gets user tasks filtered by dueDate', async () => {
133+
req.body = [
134+
{
135+
text: 'test daily 1',
136+
type: 'daily',
137+
frequency: 'daily',
138+
everyX: 1,
139+
startDate: moment().toDate(),
140+
},
141+
{
142+
text: 'test daily 2',
143+
type: 'daily',
144+
frequency: 'weekly',
145+
everyX: 1,
146+
startDate: moment().toDate(),
147+
repeat: {
148+
su: true,
149+
s: true,
150+
f: true,
151+
th: true,
152+
w: true,
153+
t: true,
154+
m: true,
155+
},
156+
},
157+
{
158+
text: 'test habit 1',
159+
type: 'habit',
160+
},
161+
];
162+
res.t = i18n.t;
163+
164+
await createTasks(req, res, { user });
165+
166+
req.body = {};
167+
req.query = {};
168+
169+
const dueDate = moment().add(1, 'days').toDate();
170+
const tasks = await getTasks(req, res, { user, dueDate });
171+
172+
const userTasks = tasks.filter(task => task.type !== 'todo');
173+
174+
expect(userTasks.length).to.equal(3);
175+
userTasks.forEach(task => {
176+
if (task.type === 'daily') {
177+
expect(task.nextDue).to.exist;
178+
expect(task.nextDue.length).to.be.greaterThan(0);
179+
task.nextDue.forEach(due => {
180+
expect(moment(due).isSameOrAfter(moment(dueDate).startOf('day'))).to.be.true;
181+
});
182+
}
183+
});
184+
});
185+
130186
it('creates group tasks', async () => {
131187
req.body = testHabit;
132188
res.t = i18n.t;

0 commit comments

Comments
 (0)