Exemple #1
0
def test_normal_user_can_add_additional_contact_persons(
    rf, user_gql_client, phone_data
):
    profile = ProfileFactory(user=user_gql_client.user)
    YouthProfileFactory(profile=profile)
    acpd = AdditionalContactPersonDictFactory()
    request = rf.post("/graphql")
    request.user = user_gql_client.user

    variables = {"input": {"youthProfile": {"addAdditionalContactPersons": [acpd]}}}
    executed = user_gql_client.execute(
        UPDATE_MUTATION, context=request, variables=variables
    )

    acp = AdditionalContactPerson.objects.first()
    expected_data = {
        "updateMyYouthProfile": {
            "youthProfile": {
                "additionalContactPersons": {
                    "edges": [
                        {
                            "node": {
                                "id": to_global_id(
                                    type="AdditionalContactPersonNode", id=acp.pk
                                ),
                                **acpd,
                            }
                        }
                    ]
                }
            }
        }
    }
    assert dict(executed["data"]) == expected_data
def test_profile_approval_allows_changing_contact_persons(
        rf, anon_user_gql_client, youth_profile, mocker,
        restricted_profile_response):
    mocker.patch.object(
        ProfileAPI,
        "fetch_profile_with_temporary_access_token",
        return_value=restricted_profile_response,
    )
    request = rf.post("/graphql")
    request.user = anon_user_gql_client.user

    acp_new_data = AdditionalContactPersonDictFactory()
    acp_update = AdditionalContactPersonFactory(youth_profile=youth_profile)
    acp_update_values = AdditionalContactPersonDictFactory()
    acp_remove = AdditionalContactPersonFactory(youth_profile=youth_profile)

    variables = {
        "input": {
            "approvalToken": youth_profile.approval_token,
            "approvalData": {
                "addAdditionalContactPersons": [acp_new_data],
                "updateAdditionalContactPersons": [{
                    "id":
                    to_global_id(type="AdditionalContactPersonNode",
                                 id=acp_update.pk),
                    **acp_update_values,
                }],
                "removeAdditionalContactPersons": [
                    to_global_id(type="AdditionalContactPersonNode",
                                 id=acp_remove.pk)
                ],
            },
        }
    }

    anon_user_gql_client.execute(APPROVAL_MUTATION,
                                 context=request,
                                 variables=variables)

    assert not youth_profile.additional_contact_persons.filter(
        pk=acp_remove.pk).exists()
    assert youth_profile.additional_contact_persons.filter(
        pk=acp_update.pk, first_name=acp_update_values["firstName"]).exists()
    assert youth_profile.additional_contact_persons.exclude(
        pk__in=[acp_update.pk, acp_remove.pk]).exists()
def test_profile_approval_allows_changing_contact_persons(
        rf, anon_user_gql_client, youth_profile):
    EmailFactory(primary=True, profile=youth_profile.profile)

    request = rf.post("/graphql")
    request.user = anon_user_gql_client.user

    acp_new_data = AdditionalContactPersonDictFactory()
    acp_update = AdditionalContactPersonFactory(youth_profile=youth_profile)
    acp_update_values = AdditionalContactPersonDictFactory()
    acp_remove = AdditionalContactPersonFactory(youth_profile=youth_profile)

    variables = {
        "input": {
            "approvalToken": youth_profile.approval_token,
            "approvalData": {
                "addAdditionalContactPersons": [acp_new_data],
                "updateAdditionalContactPersons": [{
                    "id":
                    to_global_id(type="AdditionalContactPersonNode",
                                 id=acp_update.pk),
                    **acp_update_values,
                }],
                "removeAdditionalContactPersons": [
                    to_global_id(type="AdditionalContactPersonNode",
                                 id=acp_remove.pk)
                ],
            },
        }
    }

    anon_user_gql_client.execute(APPROVAL_MUTATION,
                                 context=request,
                                 variables=variables)

    assert not youth_profile.additional_contact_persons.filter(
        pk=acp_remove.pk).exists()
    assert youth_profile.additional_contact_persons.filter(
        pk=acp_update.pk, first_name=acp_update_values["firstName"]).exists()
    assert youth_profile.additional_contact_persons.exclude(
        pk__in=[acp_update.pk, acp_remove.pk]).exists()
def test_normal_user_can_update_additional_contact_persons(
        rf, user_gql_client):
    youth_profile = YouthProfileFactory(user=user_gql_client.user)
    acp = AdditionalContactPersonFactory(youth_profile=youth_profile)
    new_values = AdditionalContactPersonDictFactory()
    request = rf.post("/graphql")
    request.user = user_gql_client.user

    variables = {
        "input": {
            "youthProfile": {
                "updateAdditionalContactPersons": [{
                    "id":
                    to_global_id(type="AdditionalContactPersonNode",
                                 id=acp.pk),
                    **new_values,
                }],
            },
            "profileApiToken": "token",
        }
    }
    executed = user_gql_client.execute(UPDATE_MUTATION,
                                       context=request,
                                       variables=variables)

    expected_data = {
        "updateMyYouthProfile": {
            "youthProfile": {
                "additionalContactPersons": {
                    "edges": [{
                        "node": {
                            "id":
                            to_global_id(type="AdditionalContactPersonNode",
                                         id=acp.pk),
                            **new_values,
                        }
                    }]
                }
            }
        }
    }
    assert dict(executed["data"]) == expected_data