summaryrefslogtreecommitdiff
path: root/tests/peppol_write_tests.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-09-17 19:56:14 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-09-17 19:56:14 +0200
commit3402cba0fe6fa1b89a029c612b622e7a4771d901 (patch)
tree96a8eeccec970cdbf4efad3306698fb1196c9c2b /tests/peppol_write_tests.cpp
parent41ddcc70f6ac27688c0a7dccc975c4b72de718e2 (diff)
test setup to test for peppol validation
Diffstat (limited to 'tests/peppol_write_tests.cpp')
-rw-r--r--tests/peppol_write_tests.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/peppol_write_tests.cpp b/tests/peppol_write_tests.cpp
new file mode 100644
index 0000000..8e8c102
--- /dev/null
+++ b/tests/peppol_write_tests.cpp
@@ -0,0 +1,92 @@
+#include "zip.h"
+#include "xml.h"
+
+static contact _create_nl_business()
+{
+ contact pw = administration_contact_create_empty();
+ strops_copy(pw.name, "John Johnsson", sizeof(pw.name));
+ strops_copy(pw.address.address1, "Address 1", sizeof(pw.address.address1));
+ strops_copy(pw.address.country_code, "FR", sizeof(pw.address.country_code));
+ strops_copy(pw.address.city, "Paris", sizeof(pw.address.city));
+ strops_copy(pw.address.postal, "12345", sizeof(pw.address.postal));
+ strops_copy(pw.taxid, "T123", sizeof(pw.taxid));
+ strops_copy(pw.businessid, "B321", sizeof(pw.businessid));
+ pw.type = contact_type::CONTACT_BUSINESS;
+ return pw;
+}
+
+static billing_item _create_bi1(invoice *inv)
+{
+ billing_item item = administration_billing_item_create_empty();
+ item.amount = 1;
+ item.amount_is_percentage = 0;
+ strops_copy(item.description, "Shampoo", MAX_LEN_LONG_DESC);
+ item.net_per_item = 10.00f;
+ item.discount = 2.0f;
+ item.discount_is_percentage = 0;
+
+ tax_rate buffer[20];
+ char* country_codes[2] = {inv->supplier.address.country_code, inv->customer.address.country_code};
+ administration_tax_rate_get_by_country(buffer, 2, country_codes);
+ tax_rate rand_rate = buffer[0];
+ strops_copy(item.tax_rate_id, rand_rate.id, MAX_LEN_ID);
+
+ return item;
+}
+
+static bool _test_peppol_file(char* id)
+{
+ bool result = 1;
+
+ zip_extract(test_file_path, "build\\extracted", 0, 0);
+ system("java -jar libs\\schxslt-cli.jar -d build\\extracted\\I\\2.xml -s libs\\PEPPOL-EN16931-UBL.sch -o build\\invoice_report.xml > NUL 2>&1");
+
+ FILE* file = fopen("build\\invoice_report.xml", "r");
+ struct xml_document* document = xml_open_document(file);
+
+ struct xml_node* root = xml_document_root(document);
+
+ size_t num_children = xml_node_children(root);
+ for (int i = 0; i < num_children; i++)
+ {
+ struct xml_node* node = xml_node_child(root, i);
+
+ char* name = (char*)xml_easy_name(node);
+
+ if (strcmp(name, "svrl:failed-assert") == 0) {
+ struct xml_node* text_node = xml_easy_child(node, (uint8_t *)"svrl:text", 0);
+ char* content = (char*)xml_easy_content(text_node);
+ printf("FAILURE: %s\n", content);
+ result = 0;
+ }
+ }
+
+ return result;
+}
+
+//////////////////
+// Netherlands
+//////////////////
+TEST _peppol_write_outgoing_nl2nl_b2b(void)
+{
+ administration_writer_create();
+ administration_create_empty(test_file_path);
+
+ invoice inv = administration_invoice_create_empty();
+ inv.supplier = _create_nl_business();
+ inv.customer = _create_nl_business();
+ inv.is_outgoing = 1;
+ inv.status = invoice_status::INVOICE_CONCEPT;
+ inv.issued_at = time(NULL);
+ inv.delivered_at = inv.issued_at;
+ inv.expires_at = inv.issued_at + 1000;
+
+ administration_billing_item_add_to_invoice(&inv, _create_bi1(&inv));
+ administration_invoice_add(&inv);
+
+ if (_test_peppol_file(inv.id)) { PASS(); } else { FAIL(); }
+}
+
+SUITE(peppol_write) {
+ RUN_TEST(_peppol_write_outgoing_nl2nl_b2b);
+} \ No newline at end of file