Skip to content

Commit

Permalink
employee_record: Handle a conditionnal required field for static data
Browse files Browse the repository at this point in the history
  • Loading branch information
rsebille committed Dec 9, 2024
1 parent a3d6877 commit 01ac6f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
5 changes: 4 additions & 1 deletion itou/employee_record/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,13 @@ def get_adresse(self, obj: EmployeeRecordUpdateNotification):
return _AddressSerializer(obj.employee_record.job_application.job_seeker).data

def get_situationSalarie(self, obj: EmployeeRecordUpdateNotification):
required_fields = {"education_level"}
if obj.employee_record.job_application.job_seeker.jobseeker_profile.pole_emploi_id:
required_fields.add("pole_emploi_since")
is_missing_required_fields = not all(
[
getattr(obj.employee_record.job_application.job_seeker.jobseeker_profile, field)
for field in {"education_level", "pole_emploi_since"}
for field in required_fields
]
)
if is_missing_required_fields:
Expand Down
12 changes: 6 additions & 6 deletions tests/employee_record/__snapshots__/test_serializers.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ReturnDict({
'inscritPoleEmploi': False,
'inscritPoleEmploiDepuis': None,
'niveauFormation': '00',
'niveauFormation': '01',
'numeroIDE': None,
'orienteur': '08',
'salarieAideSociale': False,
Expand Down Expand Up @@ -51,7 +51,7 @@
ReturnDict({
'inscritPoleEmploi': False,
'inscritPoleEmploiDepuis': None,
'niveauFormation': '00',
'niveauFormation': '01',
'numeroIDE': None,
'orienteur': '08',
'salarieAideSociale': False,
Expand Down Expand Up @@ -99,7 +99,7 @@
ReturnDict({
'inscritPoleEmploi': False,
'inscritPoleEmploiDepuis': None,
'niveauFormation': '00',
'niveauFormation': '01',
'numeroIDE': None,
'orienteur': '08',
'salarieAideSociale': False,
Expand Down Expand Up @@ -147,7 +147,7 @@
ReturnDict({
'inscritPoleEmploi': False,
'inscritPoleEmploiDepuis': None,
'niveauFormation': '00',
'niveauFormation': '01',
'numeroIDE': None,
'orienteur': '08',
'salarieAideSociale': False,
Expand Down Expand Up @@ -195,7 +195,7 @@
ReturnDict({
'inscritPoleEmploi': False,
'inscritPoleEmploiDepuis': None,
'niveauFormation': '00',
'niveauFormation': '01',
'numeroIDE': None,
'orienteur': '08',
'salarieAideSociale': False,
Expand Down Expand Up @@ -595,7 +595,7 @@
'codetypevoie': 'AV',
})
# ---
# name: test_update_notification_use_static_serializers_on_missing_fields[pole_emploi_since--situationSalarie]
# name: test_update_notification_use_static_serializers_on_missing_pole_emploi_since_fields
ReturnDict({
'inscritPoleEmploi': False,
'inscritPoleEmploiDepuis': None,
Expand Down
12 changes: 11 additions & 1 deletion tests/employee_record/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def test_batch_serializer(self, subtests):
("hexa_post_code", "", "adresse"),
("hexa_commune", None, "adresse"),
("education_level", "", "situationSalarie"),
("pole_emploi_since", "", "situationSalarie"),
],
)
def test_update_notification_use_static_serializers_on_missing_fields(snapshot, field, value, key):
Expand All @@ -198,6 +197,17 @@ def test_update_notification_use_static_serializers_on_missing_fields(snapshot,
assert data[key] == snapshot()


def test_update_notification_use_static_serializers_on_missing_pole_emploi_since_fields(snapshot):
notification = EmployeeRecordUpdateNotificationFactory(
employee_record__job_application__for_snapshot=True,
employee_record__job_application__job_seeker__jobseeker_profile__pole_emploi_id="1234567U",
employee_record__job_application__job_seeker__jobseeker_profile__pole_emploi_since="",
)

data = EmployeeRecordUpdateNotificationSerializer(notification).data
assert data["situationSalarie"] == snapshot()


@pytest.mark.parametrize("kind", Company.ASP_EMPLOYEE_RECORD_KINDS)
def test_situation_salarie_serializer_with_empty_fields(snapshot, kind):
employee_record = EmployeeRecordWithProfileFactory(
Expand Down

0 comments on commit 01ac6f7

Please sign in to comment.