"""Reapplicant history — badge vs kept attempts. No database: the helpers decide whether a prior row counts as Reapplied and how a system-dropped attempt is labelled. """ from job.candidate.serializers import ( is_assigned_application, rejection_reason, serialize_application_history, serialize_application_history_item, ) from job.candidate.views import _is_current_application def test_unassigned_inbox_is_not_a_reapplication(): row = { "source": "inbox", "job_post_id": None, "job_title": None, "status": "CLOSED", "attachment": True, "match_status": "matched", } assert is_assigned_application(row) is False assert rejection_reason(row) is None def test_assigned_inbox_is_a_reapplication(): row = {"source": "inbox", "job_post_id": "job-1", "job_title": "Engineer"} assert is_assigned_application(row) is True assert rejection_reason(row) is None def test_form_role_name_counts_without_job_post(): row = {"source": "form", "job_post_id": None, "job_title": "Data Analyst"} assert is_assigned_application(row) is True def test_unreadable_cv_is_wrong_format(): row = { "source": "inbox", "job_post_id": None, "attachment": True, "match_status": "no_text", "status": "CLOSED", } assert rejection_reason(row) == "wrong_format" item = serialize_application_history_item(row) assert item["status"] == "WRONG_FORMAT" assert item["rejection_reason"] == "wrong_format" def test_body_only_mail_is_wrong_format(): row = {"source": "inbox", "job_post_id": None, "attachment": False, "status": "CLOSED"} assert rejection_reason(row) == "wrong_format" def test_filtered_classifier_row_is_wrong_format(): row = {"source": "filtered", "job_post_id": None, "status": "WRONG_FORMAT"} assert rejection_reason(row) == "wrong_format" history = serialize_application_history("a@x.com", applications=[row]) assert history["is_reapplicant"] is False assert history["applications"][0]["status"] == "WRONG_FORMAT" def test_history_reapplicant_needs_an_assigned_job(): unassigned = {"source": "inbox", "job_post_id": None, "status": "CLOSED", "attachment": True} assigned = {"source": "inbox", "job_post_id": "job-1", "job_title": "Engineer", "status": "PENDING"} only_mail = serialize_application_history("a@x.com", applications=[unassigned]) assert only_mail["is_reapplicant"] is False assert len(only_mail["applications"]) == 1 both = serialize_application_history("a@x.com", applications=[unassigned, assigned]) assert both["is_reapplicant"] is True assert len(both["applications"]) == 2 def test_current_inbox_row_matches_message_pk(): item = {"source": "inbox", "message_id": "11111111-1111-1111-1111-111111111111"} payload = {"id": "11111111-1111-1111-1111-111111111111", "email": "a@x.com"} assert _is_current_application(item, payload) is True assert _is_current_application(item, {"id": "other"}) is False def test_filtered_row_matches_graph_id_on_detail_payload(): item = {"source": "filtered", "message_id": "AAMkGraph", "upstream_id": "AAMkGraph"} payload = {"message_id": "AAMkGraph", "fromEmail": "a@x.com"} assert _is_current_application(item, payload) is True