From df25ee50d6fcba65d879d37d4580906f72b1b1ae Mon Sep 17 00:00:00 2001 From: ivan koryshkin Date: Thu, 6 Jun 2024 12:50:40 +0400 Subject: [PATCH] bugfix(summary-flows) Calc isCompleted field for submission details --- src/apps/answers/service.py | 4 +++ src/apps/answers/tests/test_answers.py | 43 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/apps/answers/service.py b/src/apps/answers/service.py index 9f6d86a1c87..77e4a624e68 100644 --- a/src/apps/answers/service.py +++ b/src/apps/answers/service.py @@ -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"}), @@ -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], ) diff --git a/src/apps/answers/tests/test_answers.py b/src/apps/answers/tests/test_answers.py index 6ea8d930735..08b061da913 100644 --- a/src/apps/answers/tests/test_answers.py +++ b/src/apps/answers/tests/test_answers.py @@ -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 = [ @@ -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 @@ -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