def METHOD_NAME(
    app, client, librarian_martigny, item_lib_martigny
):
    """Test item stats."""
    # A mock on the answer has been created, because it is not possible
    # to freeze on the date, because the string "now-1y" passed to
    # the configuration of the "year" facet is calculated
    # on the Elasticsearch instance.
    es_response = Response(OperationLogsSearch(), {
        'aggregations': {
            'trigger': {
                'buckets': [{
                    'doc_count': 1,
                    'key': 'checkout',
                    'year': {
                        'doc_count': 1,
                        'meta': {}
                    }
                }, {
                    'doc_count': 2,
                    'key': 'extend',
                    'year': {
                        'doc_count': 1,
                        'meta': {}
                    }
                }, {
                    'doc_count': 2,
                    'key': 'checkin',
                    'year': {
                        'doc_count': 1,
                        'meta': {}
                    }
                }]
            }
        }
    })
    es_response_checkin = Response(OperationLogsSearch(), {
        'aggregations': {
            'trigger': {
                'buckets': [{
                    'doc_count': 2,
                    'key': 'checkin',
                    'year': {
                        'doc_count': 1,
                        'meta': {}
                    }
                }]
            }
        }
    })
    login_user_via_session(client, librarian_martigny.user)
    with mock.patch.object(
        OperationLogsSearch,
        'execute',
        mock.MagicMock(return_value=es_response)
    ):
        # We sum the Legacy_count field in the checkout field
        res = client.get(url_for('api_item.stats', item_pid='item1'))
        assert res.json == \
            {
                'total': {'checkout': 5, 'extend': 2, 'checkin': 2},
                'total_year': {'checkout': 1, 'extend': 1, 'checkin': 1}}
    with mock.patch.object(
        OperationLogsSearch,
        'execute',
        mock.MagicMock(return_value=es_response_checkin)
    ):
        # item found
        # We add the legacy_checkout_count field to the checkout field
        res = client.get(url_for('api_item.stats', item_pid='item1'))
        assert res.json == \
            {
                'total': {'checkout': 4, 'checkin': 2},
                'total_year': {'checkin': 1}}
        # No item found
        res = client.get(url_for('api_item.stats', item_pid='foot'))
        assert res.json == \
            {
                'total': {'checkin': 2},
                'total_year': {'checkin': 1}}