from Builders.xml.generate_xml import write_xml_from_string, generate_xml


def test_write_xml_from_string():

    xml_string = """<a>Test</a>"""
    destination_folder = "folder"

    destination_folder_empty = ""

    file_name = "file"
    file_name_ext = "file.xml"

    retour1 = write_xml_from_string(xml_string, destination_folder, file_name)
    retour2 = write_xml_from_string(xml_string, destination_folder, file_name_ext)
    retour3 = write_xml_from_string(xml_string, destination_folder, file_name_ext)

    assert retour1 == destination_folder +'\\' + file_name +'.xml'
    assert retour2 == destination_folder +'\\' + file_name_ext


def test_generate_xml():
    data = {
        "company": {
            "name": "ALCHIMIE DATA SOLUTIONS",
            "address": [
                "10 rue du SQL",
                "75010 PARIS 10 - France",
            ],
            "siren": "123456789"
        },

        "partner": {
            "name": "Mon client préféré",
            "address": [
                "6 Rue de Excel",
                "59300 Roubaix - France",
            ],
            "siren": "987654321"},

        "invoice": {
            "name": "1234",
            "order": "S00028",
            "date": "20260113",
            "expiration": "20260212",
            "salesperson": "Antoine Ducoulombier",
            "reference": "CAC-123456789",
            "description": ["Période du 01/01/2025 au 31/12/2025."]
        },
        "invoice_header":
            [
                {
                    "tva_code": 10,
                    "tva_texte": "TVA 10%",
                    "amount": 18.00
                },
                {
                    "tva_code": 20,
                    "tva_texte": "TVA 20%",
                    "amount": 108.00
                }],
        "invoice_lines": [
            {
                "product_code": "A3",
                "product_description": "Booking fee",
                "product_type": "LB",
                "quantity": 10,
                "unit_price": 50.00,
                "tva_code": 20,
                "tva_text": "TVA 20%",
                "amount": 108.00
            }
        ],
        "footer": {
            "left": "+33688305889",
            "middle": "contact@alchimiedatasolutions.com",
            "right": "http://www.alchimiedatasolutions.com",
            "bottom": "123456789"
        },

        "other": {

            "terms_url": "https://mon_site_web.com"
        }
    }
    document = generate_xml(data)

    assert isinstance(document, str)
