Skip to content

Commit

Permalink
fix: batch in applicantApplication error (#3062)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Jun 7, 2024
1 parent 0b5a14a commit 86c52e8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
13 changes: 4 additions & 9 deletions backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,15 +1472,10 @@ class ApplicantApplicationSerializer(BaseApplicationSerializer):
),
)

batch = SimpleApplicationBatchSerializer(
allow_null=True,
required=False,
)
has_batch = serializers.SerializerMethodField()

def get_batch(self, _):
if self.batch:
return True
return None
def get_has_batch(self, obj):
return obj.batch is not None

changes = serializers.SerializerMethodField(
help_text=("Possible changes made by handler to the application."),
Expand Down Expand Up @@ -1510,7 +1505,7 @@ def update(self, instance, validated_data):
return self._base_update(instance, validated_data)

class Meta(BaseApplicationSerializer.Meta):
fields = BaseApplicationSerializer.Meta.fields + ["batch"]
fields = BaseApplicationSerializer.Meta.fields + ["batch", "has_batch"]


class HandlerApplicationSerializer(BaseApplicationSerializer):
Expand Down
10 changes: 7 additions & 3 deletions backend/benefit/applications/tests/test_applications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import tempfile
import uuid
from datetime import date, datetime, timedelta, timezone
from decimal import Decimal
from unittest import mock
Expand Down Expand Up @@ -376,7 +377,7 @@ def test_application_single_read_without_ahjo_decision_as_applicant(
assert response.data["ahjo_decision"] is None
assert response.data["application_number"] is not None
assert response.data["status"] == visible_status
assert response.data["batch"] is None
assert response.data["has_batch"] is False
assert Decimal(response.data["duration_in_months_rounded"]) == duration_in_months(
application.start_date, application.end_date, decimal_places=2
)
Expand All @@ -387,7 +388,8 @@ def test_application_single_read_without_ahjo_decision_as_applicant(
response = api_client.get(get_detail_url(application))

assert response.status_code == 200
assert response.data["batch"] is True
assert response.data["has_batch"] is True
assert isinstance(response.data["batch"], uuid.UUID)


@pytest.mark.parametrize(
Expand All @@ -410,7 +412,9 @@ def test_application_single_read_with_ahjo_decision_as_applicant(
assert response.data["ahjo_decision"] is not None
assert response.data["application_number"] is not None
assert response.data["status"] == visible_status
assert response.data["batch"] is True
assert response.data["has_batch"] is True

assert isinstance(response.data["batch"], uuid.UUID)
assert Decimal(response.data["duration_in_months_rounded"]) == duration_in_months(
application.start_date, application.end_date, decimal_places=2
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const useHeader = (): ExtendedComponentProps => {
);

const { data: application } = useApplicationQuery(id);
const canWriteNewMessages = !application?.batch;
const canWriteNewMessages = !application?.has_batch;

useEffect(() => {
if (application?.unread_messages_count) {
Expand Down
1 change: 1 addition & 0 deletions frontend/benefit/shared/src/types/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export type ApplicationData = {
training_compensations: TrainingCompensationData[];
handled_at?: string;
batch?: BatchData;
has_batch?: boolean;
latest_decision_comment?: string;
unread_messages_count?: number;
application_origin?: APPLICATION_ORIGINS;
Expand Down

0 comments on commit 86c52e8

Please sign in to comment.