Skip to content

Commit

Permalink
Task tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexd-bes committed Aug 22, 2024
1 parent 1c93e8e commit a7f0b57
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ describe('TaskCompletionHandler', () => {
{ entity_id: tonga.id, date: '2024-07-21' },
]);
await assertTaskStatus(task.id, 'completed', responseIds[0]);
const comments = await models.taskComment.find({ task_id: task.id });
expect(comments[0]).toMatchObject({
message: 'Completed this task',
user_id: userId,
const comments = await models.taskComment.find({
task_id: task.id,
type: models.taskComment.types.System,
'template_variables->>type': models.taskComment.systemCommentTypes.Complete,
});
expect(comments).toHaveLength(1);
});

it('created response marks associated tasks as completed if created_time === data_time', async () => {
Expand All @@ -112,18 +112,6 @@ describe('TaskCompletionHandler', () => {
await createResponses([{ entity_id: tonga.id, date: '2021-07-08' }]);
await assertTaskStatus(task.id, 'to_do', null);
});

it('created response does not mark associated tasks as completed if status is null, but should still create a comment', async () => {
await models.task.update({ id: task.id }, { status: null });
await createResponses([{ entity_id: tonga.id, date: '2021-07-08' }]);
await assertTaskStatus(task.id, null, null);
const comments = await models.taskComment.find({ task_id: task.id });
expect(comments[0]).toMatchObject({
message: 'Completed this task',
user_id: userId,
type: 'system',
});
});
});

describe('updating a survey response', () => {
Expand Down
10 changes: 8 additions & 2 deletions packages/database/src/modelClasses/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const formatValue = async (field, value, models) => {
export class TaskRecord extends DatabaseRecord {
static databaseRecord = RECORDS.TASK;

statusTypes = {
ToDo: 'to_do',
Completed: 'completed',
Cancelled: 'cancelled',
};

static joins = [
{
joinWith: RECORDS.ENTITY,
Expand Down Expand Up @@ -104,7 +110,7 @@ export class TaskRecord extends DatabaseRecord {
survey_id: surveyId,
entity_id: entityId,
repeat_schedule: repeatSchedule,
status: 'completed',
status: this.statusTypes.Completed,
survey_response_id: surveyResponseId,
parent_task_id: id,
};
Expand All @@ -120,7 +126,7 @@ export class TaskRecord extends DatabaseRecord {
}
} else {
await this.model.updateById(id, {
status: 'complete',
status: this.statusTypes.Completed,
survey_response_id: surveyResponseId,
});
await this.addCompletedComment(commentUserId);
Expand Down

0 comments on commit a7f0b57

Please sign in to comment.