Skip to content

Commit

Permalink
bugfix(summary-flows) Calc isCompleted field for submission details
Browse files Browse the repository at this point in the history
  • Loading branch information
iwankrshkin committed Jun 6, 2024
1 parent 6f0dc8a commit df25ee5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/apps/answers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ async def get_flow_submission(

answer_result: list[ActivityAnswer] = []

is_completed = False
for answer in answers:
if answer.flow_history_id and answer.is_flow_completed:
is_completed = True
answer_result.append(
ActivityAnswer(
**answer.dict(exclude={"migrated_data"}),
Expand Down Expand Up @@ -548,6 +551,7 @@ async def get_flow_submission(
created_at=max([a.created_at for a in answer_result]),
end_datetime=max([a.end_datetime for a in answer_result]),
answers=answer_result,
is_completed=is_completed,
),
flow=flows[0],
)
Expand Down
43 changes: 43 additions & 0 deletions src/apps/answers/tests/test_answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,31 @@ async def tom_answer(tom: User, session: AsyncSession, answer_create: AppletAnsw
return await AnswerService(session, tom.id).create_answer(answer_create)


@pytest.fixture
async def tom_answer_activity_flow_not_completed(
session: AsyncSession, tom: User, applet_with_flow: AppletFull
) -> AnswerSchema:
answer_service = AnswerService(session, tom.id)
return await answer_service.create_answer(
AppletAnswerCreate(
applet_id=applet_with_flow.id,
version=applet_with_flow.version,
submit_id=uuid.uuid4(),
flow_id=applet_with_flow.activity_flows[1].id,
is_flow_completed=False,
activity_id=applet_with_flow.activities[0].id,
answer=ItemAnswerCreate(
item_ids=[applet_with_flow.activities[0].items[0].id],
start_time=datetime.datetime.utcnow(),
end_time=datetime.datetime.utcnow(),
user_public_key=str(tom.id),
identifier="encrypted_identifier",
),
client=ClientMeta(app_id=f"{uuid.uuid4()}", app_version="1.1", width=984, height=623),
)
)


@pytest.mark.usefixtures("mock_kiq_report")
class TestAnswerActivityItems(BaseTest):
fixtures = [
Expand Down Expand Up @@ -1589,6 +1614,7 @@ async def test_flow_submission(self, client, tom: User, applet_with_flow: Applet
data = data["result"]
assert set(data.keys()) == {"flow", "submission", "summary"}

assert data["submission"]["isCompleted"] is True
assert len(data["submission"]["answers"]) == len(applet_with_flow.activity_flows[0].items)
answer_data = data["submission"]["answers"][0]
# fmt: off
Expand Down Expand Up @@ -1905,3 +1931,20 @@ async def test_review_flows_one_answer_without_target_subject_id(
data = response.json()
assert data["result"][0]["message"] == "field required"
assert data["result"][0]["path"] == ["query", "targetSubjectId"]

async def test_flow_submission_not_completed(
self, client, tom: User, applet_with_flow: AppletFull, tom_answer_activity_flow_not_completed
):
client.login(tom)
url = self.flow_submission_url.format(
applet_id=applet_with_flow.id,
flow_id=applet_with_flow.activity_flows[1].id,
submit_id=tom_answer_activity_flow_not_completed.submit_id,
)
response = await client.get(url)
assert response.status_code == 200
data = response.json()
assert "result" in data
data = data["result"]
assert set(data.keys()) == {"flow", "submission", "summary"}
assert data["submission"]["isCompleted"] is False

0 comments on commit df25ee5

Please sign in to comment.