Skip to content

Commit

Permalink
Handle completion of repeating tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexd-bes committed Aug 13, 2024
1 parent 056e03d commit 0dc578a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe('TaskCompletionHandler', () => {
});

describe('Repeating tasks', () => {
it('updating a survey response for a repeating task creates a new completed task', async () => {
it('creating a survey response for a repeating task creates a new completed task', async () => {
const samoa = await findOrCreateDummyRecord(models.entity, { code: 'WS' });
const repeatTask = await findOrCreateDummyRecord(models.task, {
entity_id: samoa.id,
Expand All @@ -154,11 +154,12 @@ describe('TaskCompletionHandler', () => {
const newTask = await models.task.findOne({
survey_response_id: responses[0],
entity_id: samoa.id,
parent_task_id: repeatTask.id,
});
await assertTaskStatus(newTask.id, 'completed', responses[0]);
});

it('updating a survey response for a repeating task with status do_do creates a new completed task', async () => {
it('creating a survey response for a repeating task with status to_do creates a new completed task', async () => {
const fiji = await findOrCreateDummyRecord(models.entity, { code: 'FJ' });
const repeatTask = await findOrCreateDummyRecord(models.task, {
entity_id: fiji.id,
Expand All @@ -176,6 +177,7 @@ describe('TaskCompletionHandler', () => {
const newTask = await models.task.findOne({
survey_response_id: responses[0],
entity_id: fiji.id,
parent_task_id: repeatTask.id,
});
await assertTaskStatus(newTask.id, 'completed', responses[0]);
});
Expand Down
1 change: 1 addition & 0 deletions packages/database/src/modelClasses/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class TaskRecord extends DatabaseRecord {
repeat_schedule: repeatSchedule,
status: 'completed',
survey_response_id: surveyResponseId,
parent_task_id: id,
};

// Check for an existing task so that multiple tasks aren't created for the same survey response
Expand Down

0 comments on commit 0dc578a

Please sign in to comment.