import { tap, expect } from '@push.rocks/tapbundle';

import * as xinvoice from '../ts/index.js';

import * as getInvoices from './assets/getasset.js';

const test1 = tap.test('XInvoice should correctly embed XML into a PDF', async (tools) => {
  // lets setup the XInvoice instance
  const xInvoice = new xinvoice.XInvoice();
  const testZugferdBuffer = await getInvoices.getInvoice(
    getInvoices.invoices.ZUGFeRDv2.correct.intarsys.BASIC['zugferd_2p0_BASIC_Einfach.pdf']
  );
  // add the pdf buffer
  xInvoice.addPdfBuffer(testZugferdBuffer);

  // lets get the xml buffer
  const xmlResult = await xInvoice.getXmlData();
  console.log(xmlResult);

  return xmlResult;
});

tap.test('should parse the xml', async () => {
  const xmlResult: string = await test1.testResultPromise as string;

  // lets setup the XInvoice instance
  const xInvoiceInstance = new xinvoice.XInvoice();
  xInvoiceInstance.addXmlString(xmlResult);
  const parsedXml = await xInvoiceInstance.getParsedXmlData();
  console.log(JSON.stringify(parsedXml, null, 2));
  return parsedXml;
});

tap.start(); // Run the test suite
