Skip to content

Commit

Permalink
job_seekers_views: test the modal when a user is found by NIR or email
Browse files Browse the repository at this point in the history
This modal is displayed when a job seeker is found with a NIR or an
email. It is more and more complex and we need to test its content.
  • Loading branch information
EwenKorr committed Feb 3, 2025
1 parent d5da897 commit b282d16
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,30 @@ <h3 class="modal-title" id="email-confirmation-label">Email existant</h3>
{% endif %}
</p>
{% if can_add_nir %}
{# djlint:off #}
<p>
En cliquant sur « Continuer », <b>vous acceptez que le numéro de sécurité sociale {{ nir|format_nir }} soit associé à ce
{{ is_gps|default:False|yesno:"bénéficiaire,candidat" }}
.</b>
</p>
{% endif %}
</div>
<div class="modal-footer">
{{ is_gps|default:False|yesno:"bénéficiaire,candidat" }}.</b>
</p>
{# djlint:on #}
{% endif %}
</div>
<div class="modal-footer">

{# Reload this page with a new form. #}
{% if is_gps|default:False %}
{% bootstrap_button "Suivre un autre bénéficiaire" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% else %}
{% bootstrap_button "Ce n'est pas mon candidat" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% endif %}
{# Go to the next step. #}
{% bootstrap_button "Continuer" button_type="submit" button_class="btn btn-sm btn-primary" name="confirm" value="1" %}
{# Reload this page with a new form. #}
{% if is_gps|default:False %}
{% bootstrap_button "Suivre un autre bénéficiaire" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% else %}
{% bootstrap_button "Ce n'est pas mon candidat" button_type="submit" button_class="btn btn-sm btn-outline-primary" name="cancel" value="1" %}
{% endif %}
{# Go to the next step. #}
{% bootstrap_button "Continuer" button_type="submit" button_class="btn btn-sm btn-primary" name="confirm" value="1" %}
</div>
</div>
</div>
</div>
</div>
{% endif %}
</form>
{% endif %}
</form>
{% endblock %}

{% block script %}
Expand Down
69 changes: 65 additions & 4 deletions tests/gps/test_create_beneficiary.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from itou.users.enums import LackOfPoleEmploiId, UserKind
from itou.users.models import User
from itou.utils.mocks.address_format import mock_get_geocoding_data_by_ban_api_resolved
from itou.utils.templatetags.format_filters import format_nir
from itou.utils.templatetags.str_filters import mask_unless
from itou.utils.urls import add_url_params
from itou.www.job_seekers_views.enums import JobSeekerSessionKinds
from tests.cities.factories import create_city_geispolsheim, create_test_cities
Expand All @@ -21,6 +23,67 @@
from tests.utils.test import KNOWN_SESSION_KEYS


def helper_contains_nir_modal_gps(response, job_seeker, with_personal_information=True):
assertContains(
response,
f"""
<div class="modal-body">
<p>
Le numéro {format_nir(job_seeker.jobseeker_profile.nir)} est associé au compte de
<b>{mask_unless(job_seeker.get_full_name(), with_personal_information)}</b>.
</p>
<p>
Si ce n'est pas le bénéficiaire que vous souhaitez suivre,
cliquez sur « Suivre un autre bénéficiaire » afin de modifier le numéro de sécurité sociale.
</p>
</div>
<div class="modal-footer">
<button class="btn btn-sm btn-outline-primary" name="cancel" type="submit" value="1">
Suivre un autre bénéficiaire</button>
<button class="btn btn-sm btn-primary" name="confirm" type="submit" value="1">Continuer</button>
</div>
""",
html=True,
)


def helper_contains_email_modal_gps(response, job_seeker, with_personal_information=True, nir_to_add=None):
add_nir_text = (
f"""
<p>
En cliquant sur « Continuer », <b>vous acceptez que le numéro de sécurité sociale
{format_nir(nir_to_add)} soit associé à ce bénéficiaire.</b>
</p>
"""
if nir_to_add is not None
else ""
)
assertContains(
response,
f"""
<div class="modal-body">
<p>
L'adresse {job_seeker.email} est associée au compte de
<b>{mask_unless(job_seeker.get_full_name(), with_personal_information)}</b>.
</p>
<p>
L'identité du candidat est une information clé pour la structure.
Si vous ne souhaitez pas suivre
<b>{mask_unless(job_seeker.get_full_name(), with_personal_information)}</b>,
cliquez sur « Suivre un autre bénéficiaire » afin d'enregistrer ses informations personnelles.
</p>
{add_nir_text}
</div>
<div class="modal-footer">
<button class="btn btn-sm btn-outline-primary" name="cancel" type="submit" value="1">
Suivre un autre bénéficiaire</button>
<button class="btn btn-sm btn-primary" name="confirm" type="submit" value="1">Continuer</button>
</div>
""",
html=True,
)


@pytest.mark.ignore_unknown_variable_template_error("confirmation_needed", "job_seeker")
@override_settings(API_BAN_BASE_URL="http://ban-api")
@mock.patch(
Expand Down Expand Up @@ -272,11 +335,10 @@ def test_existing_user_with_email(client):
post_data = {"email": job_seeker.email, "preview": "1"}

response = client.post(next_url, data=post_data)
assert response.status_code == 200

# Display GPS text in modal
# ----------------------------------------------------------------------
assertContains(response, "Si vous ne souhaitez pas suivre")
helper_contains_email_modal_gps(response, job_seeker, nir_to_add=nir)

post_data = {"email": job_seeker.email, "confirm": "1"}
response = client.post(next_url, data=post_data)
Expand Down Expand Up @@ -319,8 +381,7 @@ def test_existing_user_with_nir(client):
post_data = {"nir": nir, "preview": 1}
response = client.post(last_url, data=post_data)

assert response.status_code == 200
assertContains(response, "Si ce n'est pas le bénéficiaire que vous souhaitez suivre")
helper_contains_nir_modal_gps(response, job_seeker)

post_data = {"nir": nir, "confirm": 1}
response = client.post(last_url, data=post_data)
Expand Down
Loading

0 comments on commit b282d16

Please sign in to comment.