def test_update_environment_json(settings, environment_document):  # type: ignore[no-untyped-def]
    """
    Test to verify that, when we call update_environment_json, the response is written
    to the correct file and that the sensitive data from the response is masked.
    """
    # Given
    api_url = "https://api.flagsmith.com/api/v1"
    settings.FLAGSMITH_ON_FLAGSMITH_SERVER_API_URL = api_url

    responses.add(
        method="GET",
        url=f"{api_url}/environment-document",
        body=json.dumps(environment_document),
        status=200,
    )

    # When
    with patch("builtins.open", mock_open(read_data="")) as mocked_open:
        update_environment_json()

    # Then
    written_json = json.loads(mocked_open.return_value.write.call_args[0][0])
    assert written_json["id"] == 0
    assert written_json["api_key"] == "masked"
    assert written_json["feature_states"] == environment_document["feature_states"]
    assert written_json["project"]["id"] == 0
    assert written_json["project"]["segments"] == []
    assert written_json["project"]["organisation"]["id"] == 0

    Test to verify that, when we call update_environment_json, the response is written
    to the correct file and that the sensitive data from the response is masked.
    
api/tests/unit/integrations/flagsmith/test_unit_flagsmith_service.py