import requests

from .conftest import diff, link, unlink


def test_direct_debit_order(conn, create_data):
    unlink(conn, create_data['name_id'])
    link(conn, create_data)

    url = conn + '/add-rl1-direct-debit-order?NameID=%s' % create_data['name_id']
    payload = {
        'codeRegie': '1',
        'bank/bankBIC': 'BDFEFR2T',
        'bank/bankIBAN': 'FR7630001007941234567890185',
        'bank/bankRUM': 'xxx',
        'bank/dateStart': '2023-01-01',
        'bank/bankAddress': '75049 PARIS cedex 01',
        'bank/civility': 'x',
        'bank/lastName': 'Ewing',
        'bank/firstName': 'John Ross',
    }
    resp = requests.post(url, json=payload)
    resp.raise_for_status()
    res = resp.json()
    assert res['data'] == 'ok'

    url = conn + '/get-rl1-direct-debit-order?NameID=%s' % create_data['name_id']
    params = {
        'codeRegie': '1',
        'dateRef': '2023-01-01',
    }
    resp = requests.get(url, params=params)
    resp.raise_for_status()
    res = resp.json()
    res['data']['numPerson'] = 'N/A'
    assert diff(res['data'], 'test_get_rl1_direct_debit_order.json')
