Fixes for tests

This commit is contained in:
David Bomba 2024-11-07 16:35:27 +11:00
parent ce6eb9d975
commit 55188c9820
2 changed files with 390 additions and 329 deletions

View File

@ -64,6 +64,9 @@ use InvoiceNinja\EInvoice\Models\Peppol\SupplierPartyType\AccountingSupplierPart
use InvoiceNinja\EInvoice\Models\Peppol\PartyIdentificationType\PartyIdentification; use InvoiceNinja\EInvoice\Models\Peppol\PartyIdentificationType\PartyIdentification;
use InvoiceNinja\EInvoice\Models\Peppol\TaxCategoryType\TaxCategory; use InvoiceNinja\EInvoice\Models\Peppol\TaxCategoryType\TaxCategory;
/**
*
*/
class Fact1Test extends TestCase class Fact1Test extends TestCase
{ {
use MockAccountData; use MockAccountData;
@ -78,371 +81,371 @@ class Fact1Test extends TestCase
$this->makeTestData(); $this->makeTestData();
} }
// public function testRoBuild() public function testRoBuild()
// { {
// $settings = $this->company->settings; $settings = $this->company->settings;
// $settings->currency_id = '42'; $settings->currency_id = '42';
// $this->company->saveSettings($settings, $this->company); $this->company->saveSettings($settings, $this->company);
// $this->company->save(); $this->company->save();
// $settings = ClientSettings::defaults(); $settings = ClientSettings::defaults();
// $settings->currency_id = '42'; $settings->currency_id = '42';
// //VAT //VAT
// //19% //19%
// $client = Client::factory() $client = Client::factory()
// ->create([ ->create([
// 'user_id' => $this->user->id, 'user_id' => $this->user->id,
// 'company_id' => $this->company->id, 'company_id' => $this->company->id,
// 'id_number' => '646546549', 'id_number' => '646546549',
// 'address1' => '40D, Șoseaua București-Ploiești', 'address1' => '40D, Șoseaua București-Ploiești',
// 'city' => 'SECTOR3', 'city' => 'SECTOR3',
// 'state' => 'RO-B', 'state' => 'RO-B',
// 'country_id' => 642, 'country_id' => 642,
// 'vat_number' => 646546549, 'vat_number' => 646546549,
// 'name' => 'Client Company Name', 'name' => 'Client Company Name',
// 'settings' => $settings, 'settings' => $settings,
// ]); ]);
// ClientContact::factory()->create([ ClientContact::factory()->create([
// 'user_id' => $this->user->id, 'user_id' => $this->user->id,
// 'company_id' => $this->company->id, 'company_id' => $this->company->id,
// 'client_id' => $client->id, 'client_id' => $client->id,
// 'first_name' => 'Bob', 'first_name' => 'Bob',
// 'last_name' => 'Jane', 'last_name' => 'Jane',
// 'email' => 'bob@gmail.com', 'email' => 'bob@gmail.com',
// ]); ]);
// $items = []; $items = [];
// $item = new InvoiceItem(); $item = new InvoiceItem();
// $item->cost = 10; $item->cost = 10;
// $item->quantity = 10; $item->quantity = 10;
// $item->tax_name1 = 'VAT'; $item->tax_name1 = 'VAT';
// $item->tax_rate1 = '19'; $item->tax_rate1 = '19';
// $item->product_key = "Product Name"; $item->product_key = "Product Name";
// $item->notes = "A great product description"; $item->notes = "A great product description";
// $_invoice = Invoice::factory()->create([ $_invoice = Invoice::factory()->create([
// 'user_id' => $this->user->id, 'user_id' => $this->user->id,
// 'company_id' => $this->company->id, 'company_id' => $this->company->id,
// 'client_id' => $client->id, 'client_id' => $client->id,
// 'number' => 'INV-'.rand(1000, 1000000), 'number' => 'INV-'.rand(1000, 1000000),
// 'line_items' => [$item], 'line_items' => [$item],
// 'due_date' => now()->addDays(20)->format('Y-m-d'), 'due_date' => now()->addDays(20)->format('Y-m-d'),
// 'status_id' => 1, 'status_id' => 1,
// 'discount' => 0, 'discount' => 0,
// ]); ]);
// $_invoice->service()->markSent()->save(); $_invoice->service()->markSent()->save();
// $calc = $_invoice->calc(); $calc = $_invoice->calc();
// $invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice(); $invoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
// $invoice->UBLVersionID = '2.1'; $invoice->UBLVersionID = '2.1';
// $invoice->CustomizationID = 'urn:cen.eu:en16931:2017#compliant#urn:efactura.mfinante.ro:CIUS-RO:1.0.1'; $invoice->CustomizationID = 'urn:cen.eu:en16931:2017#compliant#urn:efactura.mfinante.ro:CIUS-RO:1.0.1';
// $invoice->ID = $_invoice->number; $invoice->ID = $_invoice->number;
// $invoice->InvoiceTypeCode = 380; $invoice->InvoiceTypeCode = 380;
// $invoice->IssueDate = new DateTime($_invoice->date); $invoice->IssueDate = new DateTime($_invoice->date);
// $invoice->DueDate = new DateTime($_invoice->due_date); $invoice->DueDate = new DateTime($_invoice->due_date);
// $invoice->DocumentCurrencyCode = 'RON'; $invoice->DocumentCurrencyCode = 'RON';
// $invoice->TaxCurrencyCode = 'RON'; $invoice->TaxCurrencyCode = 'RON';
// $asp = new AccountingSupplierParty(); $asp = new AccountingSupplierParty();
// $party = new Party(); $party = new Party();
// $party_identification = new PartyIdentification(); $party_identification = new PartyIdentification();
// $party_identification->ID = 'company_id_number'; $party_identification->ID = 'company_id_number';
// $party->PartyIdentification[] = $party_identification; $party->PartyIdentification[] = $party_identification;
// $sp_address = new PostalAddress(); $sp_address = new PostalAddress();
// $sp_address->StreetName = $this->company->settings->address1; $sp_address->StreetName = $this->company->settings->address1;
// $sp_address->CityName = 'SECTOR2'; $sp_address->CityName = 'SECTOR2';
// $sp_address->CountrySubentity = 'RO-B'; $sp_address->CountrySubentity = 'RO-B';
// $country = new Country(); $country = new Country();
// $country->IdentificationCode = 'RO'; $country->IdentificationCode = 'RO';
// $sp_address->Country = $country; $sp_address->Country = $country;
// $party->PostalAddress = $sp_address; $party->PostalAddress = $sp_address;
// $pts = new PartyTaxScheme(); $pts = new PartyTaxScheme();
// $tax_scheme = new TaxScheme(); $tax_scheme = new TaxScheme();
// $tax_scheme->ID = 'VAT'; $tax_scheme->ID = 'VAT';
// $pts->CompanyID = 'RO234234234'; $pts->CompanyID = 'RO234234234';
// $pts->TaxScheme = $tax_scheme; $pts->TaxScheme = $tax_scheme;
// $party->PartyTaxScheme[] = $pts; $party->PartyTaxScheme[] = $pts;
// $ple = new PartyLegalEntity(); $ple = new PartyLegalEntity();
// $ple->RegistrationName = $this->company->settings->name; $ple->RegistrationName = $this->company->settings->name;
// $ple->CompanyID = 'J40/2222/2009'; $ple->CompanyID = 'J40/2222/2009';
// $party->PartyLegalEntity[] = $ple; $party->PartyLegalEntity[] = $ple;
// $p_contact = new Contact(); $p_contact = new Contact();
// $p_contact->Name = $this->company->owner()->present()->name(); $p_contact->Name = $this->company->owner()->present()->name();
// $p_contact->Telephone = $this->company->settings->phone; $p_contact->Telephone = $this->company->settings->phone;
// $p_contact->ElectronicMail = $this->company->owner()->email; $p_contact->ElectronicMail = $this->company->owner()->email;
// $party->Contact = $p_contact; $party->Contact = $p_contact;
// $asp->Party = $party; $asp->Party = $party;
// $invoice->AccountingSupplierParty = $asp; $invoice->AccountingSupplierParty = $asp;
// $acp = new AccountingCustomerParty(); $acp = new AccountingCustomerParty();
// $party = new Party(); $party = new Party();
// $party_identification = new PartyIdentification(); $party_identification = new PartyIdentification();
// $party_identification->ID = 'client_id_number'; $party_identification->ID = 'client_id_number';
// $party->PartyIdentification[] = $party_identification; $party->PartyIdentification[] = $party_identification;
// $sp_address = new PostalAddress(); $sp_address = new PostalAddress();
// $sp_address->StreetName = $client->address1; $sp_address->StreetName = $client->address1;
// $sp_address->CityName = 'SECTOR2'; $sp_address->CityName = 'SECTOR2';
// $sp_address->CountrySubentity = 'RO-B'; $sp_address->CountrySubentity = 'RO-B';
// $country = new Country(); $country = new Country();
// $country->IdentificationCode = 'RO'; $country->IdentificationCode = 'RO';
// $sp_address->Country = $country; $sp_address->Country = $country;
// $party->PostalAddress = $sp_address; $party->PostalAddress = $sp_address;
// $ple = new PartyLegalEntity(); $ple = new PartyLegalEntity();
// $ple->RegistrationName = $client->name; $ple->RegistrationName = $client->name;
// $ple->CompanyID = '646546549'; $ple->CompanyID = '646546549';
// $party->PartyLegalEntity[] = $ple; $party->PartyLegalEntity[] = $ple;
// $p_contact = new Contact(); $p_contact = new Contact();
// $p_contact->Name = $client->contacts->first()->present()->name(); $p_contact->Name = $client->contacts->first()->present()->name();
// $p_contact->Telephone = $client->contacts->first()->present()->phone(); $p_contact->Telephone = $client->contacts->first()->present()->phone();
// $p_contact->ElectronicMail = $client->contacts->first()->present()->email(); $p_contact->ElectronicMail = $client->contacts->first()->present()->email();
// $party->Contact = $p_contact; $party->Contact = $p_contact;
// $acp->Party = $party; $acp->Party = $party;
// $invoice->AccountingCustomerParty = $acp; $invoice->AccountingCustomerParty = $acp;
// $taxtotal = new TaxTotal(); $taxtotal = new TaxTotal();
// $tax_amount = new TaxAmount(); $tax_amount = new TaxAmount();
// $tax_amount->amount = $calc->getItemTotalTaxes(); $tax_amount->amount = $calc->getItemTotalTaxes();
// $tax_amount->currencyID = $_invoice->client->currency()->code; $tax_amount->currencyID = $_invoice->client->currency()->code;
// $tc = new TaxCategory(); $tc = new TaxCategory();
// $tc->ID = "S"; $tc->ID = "S";
// $taxable = $this->getTaxable($_invoice); $taxable = $this->getTaxable($_invoice);
// $taxable_amount = new TaxableAmount(); $taxable_amount = new TaxableAmount();
// $taxable_amount->amount = $taxable; $taxable_amount->amount = $taxable;
// $taxable_amount->currencyID = $_invoice->client->currency()->code; $taxable_amount->currencyID = $_invoice->client->currency()->code;
// $tax_sub_total = new TaxSubtotal(); $tax_sub_total = new TaxSubtotal();
// $tax_sub_total->TaxAmount = $tax_amount; $tax_sub_total->TaxAmount = $tax_amount;
// $tax_sub_total->TaxCategory = $tc; $tax_sub_total->TaxCategory = $tc;
// $tax_sub_total->TaxableAmount = $taxable_amount; $tax_sub_total->TaxableAmount = $taxable_amount;
// $taxtotal->TaxSubtotal[] = $tax_sub_total; $taxtotal->TaxSubtotal[] = $tax_sub_total;
// $invoice->TaxTotal[] = $taxtotal; $invoice->TaxTotal[] = $taxtotal;
// $lmt = new LegalMonetaryTotal(); $lmt = new LegalMonetaryTotal();
// $lea = new LineExtensionAmount(); $lea = new LineExtensionAmount();
// $lea->amount = $taxable; $lea->amount = $taxable;
// $lea->currencyID = $_invoice->client->currency()->code; $lea->currencyID = $_invoice->client->currency()->code;
// $lmt->LineExtensionAmount = $lea; $lmt->LineExtensionAmount = $lea;
// $tea = new TaxExclusiveAmount(); $tea = new TaxExclusiveAmount();
// $tea->amount = $taxable; $tea->amount = $taxable;
// $tea->currencyID = $_invoice->client->currency()->code; $tea->currencyID = $_invoice->client->currency()->code;
// $lmt->TaxExclusiveAmount = $tea; $lmt->TaxExclusiveAmount = $tea;
// $tia = new TaxInclusiveAmount(); $tia = new TaxInclusiveAmount();
// $tia->amount = $_invoice->amount; $tia->amount = $_invoice->amount;
// $tia->currencyID = $_invoice->client->currency()->code; $tia->currencyID = $_invoice->client->currency()->code;
// $lmt->TaxInclusiveAmount = $tia; $lmt->TaxInclusiveAmount = $tia;
// $pa = new PayableAmount(); $pa = new PayableAmount();
// $pa->amount = $_invoice->amount; $pa->amount = $_invoice->amount;
// $pa->currencyID = $_invoice->client->currency()->code; $pa->currencyID = $_invoice->client->currency()->code;
// $lmt->PayableAmount = $pa; $lmt->PayableAmount = $pa;
// $invoice->LegalMonetaryTotal = $lmt; $invoice->LegalMonetaryTotal = $lmt;
// foreach($_invoice->line_items as $key => $item) { foreach($_invoice->line_items as $key => $item) {
// $invoice_line = new InvoiceLine(); $invoice_line = new InvoiceLine();
// $invoice_line->ID = $key++; $invoice_line->ID = $key++;
// $iq = new InvoicedQuantity(); $iq = new InvoicedQuantity();
// $iq->amount = $item->cost; $iq->amount = $item->cost;
// $iq->unitCode = 'H87'; $iq->unitCode = 'H87';
// $invoice_line->InvoicedQuantity = $iq; $invoice_line->InvoicedQuantity = $iq;
// $invoice_line->Note = substr($item->notes, 0, 200); $invoice_line->Note = substr($item->notes, 0, 200);
// $ctc = new ClassifiedTaxCategory(); $ctc = new ClassifiedTaxCategory();
// $ctc->ID = 'S'; $ctc->ID = 'S';
// $i = new Item(); $i = new Item();
// $i->Description = $item->notes; $i->Description = $item->notes;
// $i->Name = $item->product_key; $i->Name = $item->product_key;
// $tax_scheme = new PeppolTaxScheme(); $tax_scheme = new PeppolTaxScheme();
// $tax_scheme->ID = $item->tax_name1; $tax_scheme->ID = $item->tax_name1;
// $tax_scheme->Name = $item->tax_rate1; $tax_scheme->Name = $item->tax_rate1;
// $ctc = new ClassifiedTaxCategory(); $ctc = new ClassifiedTaxCategory();
// $ctc->TaxScheme = $tax_scheme; $ctc->TaxScheme = $tax_scheme;
// $ctc->ID = 'S'; $ctc->ID = 'S';
// $i->ClassifiedTaxCategory[] = $ctc; $i->ClassifiedTaxCategory[] = $ctc;
// $invoice_line->Item = $i; $invoice_line->Item = $i;
// $lea = new LineExtensionAmount(); $lea = new LineExtensionAmount();
// $lea->amount = $item->line_total; $lea->amount = $item->line_total;
// $lea->currencyID = $_invoice->client->currency()->code; $lea->currencyID = $_invoice->client->currency()->code;
// $invoice_line->LineExtensionAmount = $lea; $invoice_line->LineExtensionAmount = $lea;
// $price = new Price(); $price = new Price();
// $pa = new PriceAmount(); $pa = new PriceAmount();
// $pa->amount = $item->line_total; $pa->amount = $item->line_total;
// $pa->currencyID = $_invoice->client->currency()->code; $pa->currencyID = $_invoice->client->currency()->code;
// $price->PriceAmount = $pa; $price->PriceAmount = $pa;
// $lea = new LineExtensionAmount(); $lea = new LineExtensionAmount();
// $lea->amount = $item->line_total; $lea->amount = $item->line_total;
// $lea->currencyID = $_invoice->client->currency()->code; $lea->currencyID = $_invoice->client->currency()->code;
// $invoice_line->LineExtensionAmount = $lea; $invoice_line->LineExtensionAmount = $lea;
// $invoice->InvoiceLine[] = $invoice_line; $invoice->InvoiceLine[] = $invoice_line;
// } }
// $validator = Validation::createValidatorBuilder() $validator = Validation::createValidatorBuilder()
// ->enableAttributeMapping() ->enableAttributeMapping()
// ->getValidator(); ->getValidator();
// $errors = $validator->validate($invoice); $errors = $validator->validate($invoice);
// foreach($errors as $error) { foreach($errors as $error) {
// // echo $error->getPropertyPath() . ': ' . $error->getMessage() . "\n"; // echo $error->getPropertyPath() . ': ' . $error->getMessage() . "\n";
// } }
// $this->assertCount(0, $errors); $this->assertCount(0, $errors);
// $phpDocExtractor = new PhpDocExtractor(); $phpDocExtractor = new PhpDocExtractor();
// $reflectionExtractor = new ReflectionExtractor(); $reflectionExtractor = new ReflectionExtractor();
// // list of PropertyListExtractorInterface (any iterable) // list of PropertyListExtractorInterface (any iterable)
// $listExtractors = [$reflectionExtractor]; $listExtractors = [$reflectionExtractor];
// // list of PropertyTypeExtractorInterface (any iterable) // list of PropertyTypeExtractorInterface (any iterable)
// $typeExtractors = [$reflectionExtractor,$phpDocExtractor]; $typeExtractors = [$reflectionExtractor,$phpDocExtractor];
// // list of PropertyDescriptionExtractorInterface (any iterable) // list of PropertyDescriptionExtractorInterface (any iterable)
// $descriptionExtractors = [$phpDocExtractor]; $descriptionExtractors = [$phpDocExtractor];
// // list of PropertyAccessExtractorInterface (any iterable) // list of PropertyAccessExtractorInterface (any iterable)
// $accessExtractors = [$reflectionExtractor]; $accessExtractors = [$reflectionExtractor];
// // list of PropertyInitializableExtractorInterface (any iterable) // list of PropertyInitializableExtractorInterface (any iterable)
// $propertyInitializableExtractors = [$reflectionExtractor]; $propertyInitializableExtractors = [$reflectionExtractor];
// $propertyInfo = new PropertyInfoExtractor( $propertyInfo = new PropertyInfoExtractor(
// // $listExtractors, // $listExtractors,
// $propertyInitializableExtractors, $propertyInitializableExtractors,
// $descriptionExtractors, $descriptionExtractors,
// $typeExtractors, $typeExtractors,
// // $accessExtractors, // $accessExtractors,
// ); );
// $context = [ $context = [
// 'xml_format_output' => true, 'xml_format_output' => true,
// 'remove_empty_tags' => true, 'remove_empty_tags' => true,
// ]; ];
// $encoder = new XmlEncoder($context); $encoder = new XmlEncoder($context);
// $classMetadataFactory = new ClassMetadataFactory(new AttributeLoader()); $classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
// $metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory); $metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory);
// $discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory); $discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);
// $normalizer = new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter, null, $propertyInfo); $normalizer = new ObjectNormalizer($classMetadataFactory, $metadataAwareNameConverter, null, $propertyInfo);
// $normalizers = [ new DateTimeNormalizer(), $normalizer, new ArrayDenormalizer() , ]; $normalizers = [ new DateTimeNormalizer(), $normalizer, new ArrayDenormalizer() , ];
// $encoders = [$encoder, new JsonEncoder()]; $encoders = [$encoder, new JsonEncoder()];
// $serializer = new Serializer($normalizers, $encoders); $serializer = new Serializer($normalizers, $encoders);
// $n_context = [ $n_context = [
// AbstractObjectNormalizer::SKIP_NULL_VALUES => true, AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
// // AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true, // AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => true,
// ]; ];
// // $invoice = $normalizer->normalize($invoice, 'json', $n_context); // $invoice = $normalizer->normalize($invoice, 'json', $n_context);
// // echo print_r($invoice); // echo print_r($invoice);
// // $invoice = $serializer->serialize($invoice, 'xml', $n_context); // $invoice = $serializer->serialize($invoice, 'xml', $n_context);
// $dataxml = $serializer->encode($invoice, 'xml', $context); $dataxml = $serializer->encode($invoice, 'xml', $context);
// // echo $dataxml; // echo $dataxml;
// //set default standard props //set default standard props
// } }
// /** /**
// * @return float|int|mixed * @return float|int|mixed
// */ */
// private function getTaxable(Invoice $invoice): float private function getTaxable(Invoice $invoice): float
// { {
// $total = 0; $total = 0;
// foreach ($invoice->line_items as $item) { foreach ($invoice->line_items as $item) {
// $line_total = $item->quantity * $item->cost; $line_total = $item->quantity * $item->cost;
// if ($item->discount != 0) { if ($item->discount != 0) {
// if ($invoice->is_amount_discount) { if ($invoice->is_amount_discount) {
// $line_total -= $item->discount; $line_total -= $item->discount;
// } else { } else {
// $line_total -= $line_total * $item->discount / 100; $line_total -= $line_total * $item->discount / 100;
// } }
// } }
// $total += $line_total; $total += $line_total;
// } }
// if ($invoice->discount > 0) { if ($invoice->discount > 0) {
// if ($invoice->is_amount_discount) { if ($invoice->is_amount_discount) {
// $total -= $invoice->discount; $total -= $invoice->discount;
// } else { } else {
// $total *= (100 - $invoice->discount) / 100; $total *= (100 - $invoice->discount) / 100;
// $total = round($total, 2); $total = round($total, 2);
// } }
// } }
// if ($invoice->custom_surcharge1 && $invoice->custom_surcharge_tax1) { if ($invoice->custom_surcharge1 && $invoice->custom_surcharge_tax1) {
// $total += $invoice->custom_surcharge1; $total += $invoice->custom_surcharge1;
// } }
// if ($invoice->custom_surcharge2 && $invoice->custom_surcharge_tax2) { if ($invoice->custom_surcharge2 && $invoice->custom_surcharge_tax2) {
// $total += $invoice->custom_surcharge2; $total += $invoice->custom_surcharge2;
// } }
// if ($invoice->custom_surcharge3 && $invoice->custom_surcharge_tax3) { if ($invoice->custom_surcharge3 && $invoice->custom_surcharge_tax3) {
// $total += $invoice->custom_surcharge3; $total += $invoice->custom_surcharge3;
// } }
// if ($invoice->custom_surcharge4 && $invoice->custom_surcharge_tax4) { if ($invoice->custom_surcharge4 && $invoice->custom_surcharge_tax4) {
// $total += $invoice->custom_surcharge4; $total += $invoice->custom_surcharge4;
// } }
// return $total; return $total;
// } }
} }

View File

@ -12,19 +12,22 @@
namespace Tests\Integration\Einvoice\Storecove; namespace Tests\Integration\Einvoice\Storecove;
use Tests\TestCase; use Tests\TestCase;
use App\Models\User;
use App\Models\Client; use App\Models\Client;
use App\Models\Account; use App\Models\Account;
use App\Models\Company; use App\Models\Company;
use App\Models\Invoice; use App\Models\Invoice;
use Tests\MockAccountData; use Tests\MockAccountData;
use App\Models\CompanyToken;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\DataMapper\InvoiceItem; use App\DataMapper\InvoiceItem;
use App\DataMapper\ClientSettings; use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use App\Factory\CompanyUserFactory;
use App\Services\EDocument\Standards\Peppol; use App\Services\EDocument\Standards\Peppol;
use App\Services\EDocument\Standards\Validation\Peppol\EntityLevel;
use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans; use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Services\EDocument\Standards\Validation\Peppol\EntityLevel;
class EInvoiceValidationTest extends TestCase class EInvoiceValidationTest extends TestCase
{ {
@ -35,53 +38,107 @@ class EInvoiceValidationTest extends TestCase
{ {
parent::setUp(); parent::setUp();
// $this->markTestSkipped('company model issues');
$this->makeTestData(); $this->makeTestData();
} }
public function testEinvoiceValidationEndpointInvoice() // public function testEinvoiceValidationEndpointInvoice()
{ // {
// $company = Company::factory()->create([
// 'account_id' => $this->account->id,
// 'legal_entity_id' => 123432
// ]);
$this->company->legal_entity_id = 123432; // $user = User::factory()->create([
$this->company->save(); // 'account_id' => $this->account->id,
// 'confirmation_code' => '123',
// 'email' => $this->faker->safeEmail(),
// ]);
$data =[ // $cu = CompanyUserFactory::create($user->id, $company->id, $this->account->id);
'entity' => 'invoices', // $cu->is_owner = true;
'entity_id' => $this->invoice->hashed_id, // $cu->is_admin = true;
]; // $cu->is_locked = false;
// $cu->permissions = '["view_client"]';
// $cu->save();
$response = $this->withHeaders([ // $different_company_token = \Illuminate\Support\Str::random(64);
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/einvoice/validateEntity', $data);
$response->assertStatus(200); // $company_token = new CompanyToken();
// $company_token->user_id = $user->id;
// $company_token->company_id = $company->id;
// $company_token->account_id = $this->account->id;
// $company_token->name = 'test token';
// $company_token->token = $different_company_token;
// $company_token->is_system = true;
// $company_token->save();
$arr = $response->json(); // $data = [
// 'action' => 'archive',
// 'ids' => [
// $this->client->id
// ]
// ];
}
public function testEinvoiceValidationEndpoint() // $c = Client::factory()->create([
{ // 'company_id' => $company->id,
// 'user_id' => $user->id
// ]);
$this->company->legal_entity_id = 123432;
$this->company->save();
$data =[ // ClientContact::factory()->create([
'entity' => 'companies', // 'user_id' => $user->id,
'entity_id' => $this->company->hashed_id, // 'client_id' => $c->id,
]; // 'company_id' => $company->id,
// 'is_primary' => 1,
// ]);
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/einvoice/validateEntity', $data);
$response->assertStatus(200); // $i = Invoice::factory()->create([
// 'company_id' => $company->id,
// 'user_id' => $user->id,
// 'client_id' => $c->id
// ]);
$arr = $response->json(); // $data =[
// 'entity' => 'invoices',
// 'entity_id' => $i->hashed_id,
// ];
} // $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $different_company_token,
// ])->postJson('/api/v1/einvoice/validateEntity', $data);
// $response->assertStatus(200);
// }
// public function testEinvoiceValidationEndpoint()
// {
// $this->company->legal_entity_id = 123432;
// $this->company->save();
// $data =[
// 'entity' => 'companies',
// 'entity_id' => $this->company->hashed_id,
// ];
// $response = $this->withHeaders([
// 'X-API-SECRET' => config('ninja.api_secret'),
// 'X-API-TOKEN' => $this->token,
// ])->postJson('/api/v1/einvoice/validateEntity', $data);
// $response->assertStatus(200);
// $arr = $response->json();
// }
public function testInvalidCompanySettings() public function testInvalidCompanySettings()
{ {
@ -170,6 +227,7 @@ class EInvoiceValidationTest extends TestCase
$settings->postal_code = '2113'; $settings->postal_code = '2113';
$settings->country_id = '1'; $settings->country_id = '1';
$settings->vat_number = ''; $settings->vat_number = '';
$settings->id_number ='adfadf';
$settings->classification = 'individual'; $settings->classification = 'individual';
$account = Account::factory()->create(); $account = Account::factory()->create();