Skip to content

Commit

Permalink
Add archived_at constraint to the PRIOR_TO_HIRE state
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisfreitag committed Sep 11, 2024
1 parent 76091fc commit c89e801
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ class Migration(migrations.Migration):
migrations.AddConstraint(
model_name="jobapplication",
constraint=models.CheckConstraint(
check=models.Q(("archived_at__isnull", False), ("state", "accepted"), _negated=True),
name="archived_not_accepted",
violation_error_message="Impossible d’archiver une candidature acceptée.",
check=models.Q(
("archived_at__isnull", False), ("state__in", ["accepted", "prior_to_hire"]), _negated=True
),
name="archived_status",
violation_error_message=(
"Impossible d’archiver une candidature acceptée ou en action préalable à l’embauche."
),
),
),
migrations.AddConstraint(
Expand Down
11 changes: 8 additions & 3 deletions itou/job_applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,9 +780,14 @@ class Meta:
),
),
models.CheckConstraint(
name="archived_not_accepted",
violation_error_message="Impossible d’archiver une candidature acceptée.",
check=~models.Q(state=JobApplicationState.ACCEPTED, archived_at__isnull=False),
name="archived_status",
violation_error_message=(
"Impossible d’archiver une candidature acceptée ou en action préalable à l’embauche."
),
check=~models.Q(
state__in=[JobApplicationState.ACCEPTED, JobApplicationState.PRIOR_TO_HIRE],
archived_at__isnull=False,
),
),
models.CheckConstraint(
name="archived_by__no_archived_at",
Expand Down
11 changes: 10 additions & 1 deletion tests/job_applications/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,16 @@ def test_job_application_transitions(transition, from_state):
pytest.param(transition, from_state, id=f"transition={transition.name} from_state={from_state}")
for transition in JobApplicationWorkflow.transitions
for from_state in transition.source
if JobApplicationState.ACCEPTED not in [from_state.name, transition.target.name]
if not (
# Leads to a state that cannot be archived.
{
# Employment relationship between employer and job seeker, it is active.
JobApplicationState.ACCEPTED,
# Employer waits for a prior action before to establish an employment relationship.
JobApplicationState.PRIOR_TO_HIRE,
}
& {from_state.name, transition.target.name}
)
],
)
def test_job_application_transition_unarchives(transition, from_state):
Expand Down

0 comments on commit c89e801

Please sign in to comment.