diff --git a/policy/services.py b/policy/services.py index fcacc26..59cf9f0 100644 --- a/policy/services.py +++ b/policy/services.py @@ -41,7 +41,9 @@ def __init__(self, user): self.user = user @register_service_signal('policy_service.create_or_update') - def update_or_create(self, data, user): + def update_or_create(self, data, user): + if isinstance(data['enroll_date'], str): + data['enroll_date'] = py_date.strptime(data['enroll_date'], "%Y-%m-%d") policy_uuid = data.get('uuid', None) if 'enroll_date' in data and data['enroll_date'] > py_date.today(): raise ValidationError("policy.enroll_date_in_the_future") diff --git a/policy/tests_gql.py b/policy/tests_gql.py index 048c14e..f689f3c 100644 --- a/policy/tests_gql.py +++ b/policy/tests_gql.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from core.utils import filter_validity from core.models import User -from core.test_helpers import create_test_interactive_user +from core.test_helpers import create_test_interactive_user, AssertMutation from django.conf import settings from medical.models import Service from graphene_django.utils.testing import GraphQLTestCase @@ -38,7 +38,7 @@ class PolicyGraphQLTestCase(GraphQLTestCase): # is shown as an error in the IDE, so leaving it as True. GRAPHQL_SCHEMA = True admin_user = None - + @classmethod def setUpClass(cls): super().setUpClass() @@ -317,3 +317,32 @@ def test_insuree_policy_query(self): # Add some more asserts if you like ... + def test_mutation_simple(self): + muuid = "203327cd-501e-41e1-a026-ed742e360081" + response = self.query( + f''' + mutation {{ + createPolicy( + input: {{ + clientMutationId: "{muuid}" + clientMutationLabel: "Création de la police ttttt eeeee (123123123) - 2024-06-01 : 2025-05-31" + + enrollDate: "2024-04-07" + startDate: "2024-06-01" + expiryDate: "2025-05-31" + value: "10000.00" + productId: {self.product.id} + familyId: {self.insuree.family.id} + officerId: 1 + }} + ) {{ + clientMutationId + internalId + }} + }} + ''', + headers={"HTTP_AUTHORIZATION": f"Bearer {self.admin_token}"}, + variables={'chfid': self.insuree.chf_id, 'activeOrLastExpiredOnly':True} + ) + content = AssertMutation(self,muuid,self.admin_token) +