Skip to content

Commit

Permalink
tests(rdvi): add handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leo-naeka committed Sep 11, 2024
1 parent baed9a0 commit d2e8cd8
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 2 deletions.
149 changes: 149 additions & 0 deletions itou/utils/mocks/rdv_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,152 @@
"Erreur inconnue",
],
}


RDV_INSERTION_WEBHOOK_INVITATION_HEADERS = {
"Host": "localhost",
"Accept": "application/json",
"Content-Type": "application/json",
"X-Rdvi-Signature": "9ccf14d92f839a383ad27177e9ff4fd346b4d2295a36e842378fca3486cd5152",
}


RDV_INSERTION_WEBHOOK_INVITATION_BODY = {
"data": {
"id": 4806,
"user": {
"id": 3432,
"uid": None,
"role": "demandeur",
"email": "tech@inclusion.beta.gouv.fr",
"title": "madame",
"address": "102 Quai de Jemmapes, 75010 Paris 10ème",
"last_name": "Test",
"birth_date": "1969-05-01",
"birth_name": None,
"created_at": "2024-08-07T17:01:30.719+02:00",
"first_name": "Jeanne",
"phone_number": None,
"france_travail_id": None,
"affiliation_number": None,
"rights_opening_date": None,
"rdv_solidarites_user_id": 5527,
"carnet_de_bord_carnet_id": None,
},
"format": "email",
"clicked": True,
"created_at": "2024-08-15T19:23:08.107+02:00",
"delivered_at": "2024-08-16T08:17:08+02:00",
"motif_category": {"id": 16, "name": "Entretien SIAE", "short_name": "siae_interview"},
"delivery_status": None,
"rdv_with_referents": False,
},
"meta": {"event": "updated", "model": "Invitation", "timestamp": "2024-08-15 19:23:12 +0200"},
}


RDV_INSERTION_WEBHOOK_APPOINTMENT_HEADERS = {
"Host": "localhost",
"Accept": "application/json",
"Content-Type": "application/json",
"X-Rdvi-Signature": "1504bcba3bd89bd6ff409b9b80463c5ebf120665e3978be7d11a39cb18a4d189",
}


RDV_INSERTION_WEBHOOK_APPOINTMENT_BODY = {
"data": {
"id": 1261,
"lieu": {
"name": "PDI",
"address": "6 Boulevard Saint-Denis, Paris, 75010",
"phone_number": "",
"rdv_solidarites_lieu_id": 1026,
},
"uuid": "37141381-ac77-41a6-8a7e-748d1c9439d5",
"motif": {
"name": "Entretien d'embauche",
"collectif": False,
"follow_up": False,
"location_type": "public_office",
"motif_category": {"id": 16, "name": "Entretien SIAE", "short_name": "siae_interview"},
"rdv_solidarites_motif_id": 1443,
},
"users": [
{
"id": 3432,
"uid": None,
"role": "demandeur",
"email": "tech@inclusion.beta.gouv.fr",
"title": "madame",
"address": "102 Quai de Jemmapes, 75010 Paris 10ème",
"last_name": "Test",
"birth_date": "1969-05-01",
"birth_name": None,
"created_at": "2024-08-07T17:01:30.719+02:00",
"first_name": "Jeanne",
"phone_number": None,
"france_travail_id": None,
"affiliation_number": None,
"rights_opening_date": None,
"rdv_solidarites_user_id": 5527,
"carnet_de_bord_carnet_id": None,
}
],
"agents": [
{
"id": 370,
"email": "tech@inclusion.beta.gouv.fr",
"last_name": "Itou",
"first_name": "Tech",
"rdv_solidarites_agent_id": 1791,
}
],
"status": "unknown",
"address": "6 Boulevard Saint-Denis, Paris, 75010",
"starts_at": "2024-08-26T09:00:00.000+02:00",
"created_by": "user",
"users_count": 1,
"cancelled_at": "2024-08-20T09:00:00.000+02:00",
"organisation": {
"id": 91,
"name": "Les Emplois de l'Inclusion",
"email": None,
"phone_number": "0102030405",
"motif_categories": [{"id": 16, "name": "Entretien SIAE", "short_name": "siae_interview"}],
"department_number": "60",
"rdv_solidarites_organisation_id": 654,
},
"participations": [
{
"id": 1174,
"user": {
"id": 3432,
"uid": None,
"role": "demandeur",
"email": "tech@inclusion.beta.gouv.fr",
"title": "madame",
"address": "102 Quai de Jemmapes, 75010 Paris 10ème",
"last_name": "Test",
"birth_date": "1969-05-01",
"birth_name": None,
"created_at": "2024-08-07T17:01:30.719+02:00",
"first_name": "Jeanne",
"phone_number": None,
"france_travail_id": None,
"affiliation_number": None,
"rights_opening_date": None,
"rdv_solidarites_user_id": 5527,
"carnet_de_bord_carnet_id": None,
},
"status": "unknown",
"starts_at": "2024-08-26T09:00:00.000+02:00",
"created_at": "2024-08-15T19:30:08.719+02:00",
"created_by": "user",
}
],
"duration_in_min": 30,
"max_participants_count": None,
"rdv_solidarites_rdv_id": 8725,
},
"meta": {"event": "created", "model": "Rdv", "timestamp": "2024-08-15 19:30:08 +0200"},
}
18 changes: 17 additions & 1 deletion tests/rdv_insertion/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import factory
from faker import Faker

from itou.rdv_insertion.models import Appointment, Invitation, InvitationRequest, Location, Participation
from itou.rdv_insertion.models import Appointment, Invitation, InvitationRequest, Location, Participation, WebhookEvent
from itou.users.enums import Title
from itou.utils.mocks import rdv_insertion as rdvi_mocks
from tests.companies.factories import CompanyFactory
from tests.users.factories import JobSeekerFactory

Expand Down Expand Up @@ -201,3 +202,18 @@ class Params:
status = factory.Faker("random_element", elements=Participation.Status.values)
rdv_insertion_user_id = factory.Sequence(lambda n: n)
rdv_insertion_id = factory.Sequence(lambda n: n)


class WebhookEventFactory(factory.django.DjangoModelFactory):
class Meta:
model = WebhookEvent

class Params:
for_appointment = factory.Trait(
body=rdvi_mocks.RDV_INSERTION_WEBHOOK_APPOINTMENT_BODY,
headers=rdvi_mocks.RDV_INSERTION_WEBHOOK_APPOINTMENT_HEADERS,
)

body = rdvi_mocks.RDV_INSERTION_WEBHOOK_INVITATION_BODY
headers = rdvi_mocks.RDV_INSERTION_WEBHOOK_INVITATION_HEADERS
is_processed = factory.Faker("boolean", chance_of_getting_true=30)
21 changes: 20 additions & 1 deletion tests/rdv_insertion/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
)
from tests.job_applications.factories import JobApplicationFactory
from tests.prescribers.factories import PrescriberOrganizationWithMembershipFactory
from tests.rdv_insertion.factories import InvitationFactory, InvitationRequestFactory, ParticipationFactory
from tests.rdv_insertion.factories import (
InvitationFactory,
InvitationRequestFactory,
ParticipationFactory,
WebhookEventFactory,
)
from tests.utils.test import TestCase


Expand Down Expand Up @@ -271,3 +276,17 @@ def test_get_status_class_name(self):

self.participation.status = Participation.Status.NOSHOW
assert self.participation.get_status_class_name() == "bg-danger-lighter text-danger"


class TestWebhookEventModel:
def setup_method(self, **kwargs):
self.webhook_event_invitation = WebhookEventFactory()
self.webhook_event_appointment = WebhookEventFactory(for_appointment=True)

def test_for_invitation_property(self):
assert self.webhook_event_invitation.for_invitation
assert not self.webhook_event_appointment.for_invitation

def test_for_appointment_property(self):
assert not self.webhook_event_invitation.for_appointment
assert self.webhook_event_appointment.for_appointment
Empty file.
Loading

0 comments on commit d2e8cd8

Please sign in to comment.