def test_most_recent_violation(self) -> None:
        violation_date = self.mock_client.supervision_start_date + timedelta(
            days=5)
        self.mock_client.most_recent_violation_date = violation_date

        case_presenter = CasePresenter(
            self.mock_client,
            [],
        )

        self.assertEqual(case_presenter.to_json()["mostRecentViolationDate"],
                         str(violation_date))
    def test_no_case_update(self) -> None:
        case_presenter = CasePresenter(self.mock_client, None)

        self.assertEqual(case_presenter.in_progress_officer_actions(), [])
        self.assertEqual(
            case_presenter.to_json(),
            _json_map_dates_to_strings({
                "personExternalId":
                self.mock_client.person_external_id,
                "fullName":
                json.loads(self.mock_client.full_name),
                "gender":
                self.mock_client.gender,
                "supervisingOfficerExternalId":
                self.mock_client.supervising_officer_external_id,
                "currentAddress":
                self.mock_client.current_address,
                "birthdate":
                self.mock_client.birthdate,
                "birthdateInferredFromAge":
                self.mock_client.birthdate_inferred_from_age,
                "supervisionStartDate":
                self.mock_client.supervision_start_date,
                "projectedEndDate":
                self.mock_client.projected_end_date,
                "supervisionType":
                self.mock_client.supervision_type,
                "caseType":
                self.mock_client.case_type,
                "supervisionLevel":
                self.mock_client.supervision_level,
                "stateCode":
                self.mock_client.state_code,
                "employer":
                self.mock_client.employer,
                "mostRecentAssessmentDate":
                self.mock_client.most_recent_assessment_date,
                "assessmentScore":
                self.mock_client.assessment_score,
                "mostRecentFaceToFaceDate":
                self.mock_client.most_recent_face_to_face_date,
                "nextAssessmentDate":
                date(2022, 2, 1),
                "nextFaceToFaceDate":
                date(2021, 3, 1),
                "needsMet": {
                    "employment": False,
                    "faceToFaceContact": True,
                    "assessment": True,
                },
            }),
        )
    def test_no_most_recent_violation(self) -> None:
        # violation predates the supervision period
        violation_date = self.mock_client.supervision_start_date - timedelta(
            days=5)
        self.mock_client.most_recent_violation_date = violation_date

        case_presenter = CasePresenter(
            self.mock_client,
            [],
        )

        self.assertEqual(case_presenter.to_json()["mostRecentViolationDate"],
                         None)
    def test_case_updates(self) -> None:
        case_presenter = CasePresenter(
            self.mock_client,
            [
                generate_fake_case_update(
                    self.mock_client,
                    self.mock_officer.external_id,
                    action_type=CaseUpdateActionType.SCHEDULED_FACE_TO_FACE,
                ),
            ],
        )

        case_json = case_presenter.to_json()
        self.assertEqual(len(case_json["caseUpdates"].keys()), 1)
        self.assertIn(CaseUpdateActionType.SCHEDULED_FACE_TO_FACE.value,
                      case_json["caseUpdates"])
    def test_dismiss_actions(self) -> None:
        """This tests dismissed actions. No changes to the ETL data that we see will
        affect the values we ultimately get from this."""
        dismiss_actions = [
            CaseUpdateActionType.INFORMATION_DOESNT_MATCH_OMS,
            CaseUpdateActionType.NOT_ON_CASELOAD,
            CaseUpdateActionType.FILED_REVOCATION_OR_VIOLATION,
            CaseUpdateActionType.OTHER_DISMISSAL,
        ]

        case_update = CaseUpdate(
            person_external_id=self.mock_client.person_external_id,
            officer_external_id=self.mock_client.
            supervising_officer_external_id,
            state_code=self.mock_client.state_code,
            update_metadata={
                "actions":
                CaseUpdatesInterface.serialize_actions(
                    self.mock_client,
                    dismiss_actions,
                ),
            },
        )

        case_presenter = CasePresenter(self.mock_client, case_update)

        self.assertEqual(
            [
                action.action_type
                for action in case_presenter.in_progress_officer_actions()
            ],
            dismiss_actions,
        )
        self.assertEqual(
            case_presenter.to_json(),
            _json_map_dates_to_strings({
                "personExternalId":
                self.mock_client.person_external_id,
                "fullName":
                json.loads(self.mock_client.full_name),
                "gender":
                self.mock_client.gender,
                "supervisingOfficerExternalId":
                self.mock_client.supervising_officer_external_id,
                "currentAddress":
                self.mock_client.current_address,
                "birthdate":
                self.mock_client.birthdate,
                "birthdateInferredFromAge":
                self.mock_client.birthdate_inferred_from_age,
                "supervisionType":
                self.mock_client.supervision_type,
                "caseType":
                self.mock_client.case_type,
                "supervisionStartDate":
                self.mock_client.supervision_start_date,
                "projectedEndDate":
                self.mock_client.projected_end_date,
                "supervisionLevel":
                self.mock_client.supervision_level,
                "stateCode":
                self.mock_client.state_code,
                "employer":
                self.mock_client.employer,
                "mostRecentAssessmentDate":
                self.mock_client.most_recent_assessment_date,
                "assessmentScore":
                self.mock_client.assessment_score,
                "mostRecentFaceToFaceDate":
                self.mock_client.most_recent_face_to_face_date,
                "inProgressActions":
                [action.value for action in dismiss_actions],
                "inProgressSubmissionDate":
                str(datetime(2020, 1, 1, 0, 0)),
                "nextAssessmentDate":
                date(2022, 2, 1),
                "nextFaceToFaceDate":
                date(2021, 3, 1),
                "needsMet": {
                    "employment": False,
                    "faceToFaceContact": True,
                    "assessment": True,
                },
            }),
        )
    def test_no_case_update_no_additional_client_info(self) -> None:
        case_presenter = CasePresenter(self.mock_client, [])

        self.assertEqual(
            case_presenter.to_json(),
            _json_map_dates_to_strings(
                {
                    "personExternalId":
                    self.mock_client.person_external_id,
                    "fullName":
                    json.loads(self.mock_client.full_name),
                    "gender":
                    self.mock_client.gender,
                    "supervisingOfficerExternalId":
                    self.mock_client.supervising_officer_external_id,
                    "currentAddress":
                    self.mock_client.current_address,
                    "emailAddress":
                    self.mock_client.email_address,
                    "phoneNumber":
                    self.mock_client.phone_number,
                    "birthdate":
                    self.mock_client.birthdate,
                    "birthdateInferredFromAge":
                    self.mock_client.birthdate_inferred_from_age,
                    "supervisionStartDate":
                    self.mock_client.supervision_start_date,
                    "projectedEndDate":
                    self.mock_client.projected_end_date,
                    "supervisionType":
                    self.mock_client.supervision_type,
                    "caseType":
                    self.mock_client.case_type,
                    "caseUpdates": {},
                    "supervisionLevel":
                    self.mock_client.supervision_level,
                    "stateCode":
                    self.mock_client.state_code,
                    "employer":
                    self.mock_client.employer,
                    "employmentStartDate":
                    self.mock_client.employment_start_date,
                    "mostRecentAssessmentDate":
                    self.mock_client.most_recent_assessment_date,
                    "assessmentScore":
                    self.mock_client.assessment_score,
                    "mostRecentFaceToFaceDate":
                    self.mock_client.most_recent_face_to_face_date,
                    "mostRecentHomeVisitDate":
                    self.mock_client.most_recent_home_visit_date,
                    "nextAssessmentDate":
                    date(2022, 2, 1),
                    "nextFaceToFaceDate":
                    date(2021, 3, 1),
                    "nextHomeVisitDate":
                    date(2021, 5, 3),
                    "needsMet": {
                        "employment": False,
                        "faceToFaceContact": True,
                        "homeVisitContact": True,
                        "assessment": True,
                    },
                    "notes": [],
                    "receivingSSIOrDisabilityIncome":
                    False,
                    "mostRecentViolationDate":
                    self.mock_client.most_recent_violation_date,
                }, ),
        )
    def test_no_case_update(self) -> None:
        client_info = generate_fake_client_info(
            client=self.mock_client,
            preferred_name="Alex",
            preferred_contact_method=PreferredContactMethod.Text,
        )
        self.mock_client.client_info = client_info
        officer_note = OfficerNote(
            note_id=uuid.uuid4(),
            state_code=self.mock_client.state_code,
            officer_external_id=self.mock_client.
            supervising_officer_external_id,
            person_external_id=self.mock_client.person_external_id,
            text="Simple note!",
        )
        self.mock_client.notes = [officer_note]
        case_presenter = CasePresenter(self.mock_client, [])

        self.assertEqual(
            case_presenter.to_json(),
            _json_map_dates_to_strings(
                {
                    "personExternalId":
                    self.mock_client.person_external_id,
                    "fullName":
                    json.loads(self.mock_client.full_name),
                    "gender":
                    self.mock_client.gender,
                    "supervisingOfficerExternalId":
                    self.mock_client.supervising_officer_external_id,
                    "currentAddress":
                    self.mock_client.current_address,
                    "emailAddress":
                    self.mock_client.email_address,
                    "phoneNumber":
                    self.mock_client.phone_number,
                    "birthdate":
                    self.mock_client.birthdate,
                    "birthdateInferredFromAge":
                    self.mock_client.birthdate_inferred_from_age,
                    "supervisionStartDate":
                    self.mock_client.supervision_start_date,
                    "projectedEndDate":
                    self.mock_client.projected_end_date,
                    "supervisionType":
                    self.mock_client.supervision_type,
                    "caseType":
                    self.mock_client.case_type,
                    "caseUpdates": {},
                    "supervisionLevel":
                    self.mock_client.supervision_level,
                    "stateCode":
                    self.mock_client.state_code,
                    "employer":
                    self.mock_client.employer,
                    "employmentStartDate":
                    self.mock_client.employment_start_date,
                    "mostRecentAssessmentDate":
                    self.mock_client.most_recent_assessment_date,
                    "assessmentScore":
                    self.mock_client.assessment_score,
                    "mostRecentFaceToFaceDate":
                    self.mock_client.most_recent_face_to_face_date,
                    "mostRecentHomeVisitDate":
                    self.mock_client.most_recent_home_visit_date,
                    "nextAssessmentDate":
                    date(2022, 2, 1),
                    "nextFaceToFaceDate":
                    date(2021, 3, 1),
                    "nextHomeVisitDate":
                    date(2021, 5, 3),
                    "needsMet": {
                        "employment": False,
                        "faceToFaceContact": True,
                        "homeVisitContact": True,
                        "assessment": True,
                    },
                    "preferredName":
                    client_info.preferred_name,
                    "preferredContactMethod":
                    client_info.preferred_contact_method,
                    "receivingSSIOrDisabilityIncome":
                    client_info.receiving_ssi_or_disability_income,
                    "notes": [officer_note.to_json()],
                    "mostRecentViolationDate":
                    self.mock_client.most_recent_violation_date,
                }, ),
        )