mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-12 22:22:32 +01:00
add transformer tests
This commit is contained in:
parent
d11cc1d010
commit
c2ef811faa
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Import\Transformer\Quickbooks;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Import\Transformer\Quickbooks\ClientTransformer;
|
||||
|
||||
class ClientTransformerTest extends TestCase
|
||||
{
|
||||
private $customer_data;
|
||||
private $tranformed_data;
|
||||
private $transformer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
// Mock the company object
|
||||
$company = (new \App\Factory\CompanyFactory)->create(1234);
|
||||
|
||||
// Read the JSON string from a file and decode into an associative array
|
||||
$this->customer_data = json_decode( file_get_contents( app_path('/../tests/Mock/Response/Quickbooks/customer.json') ), true);
|
||||
$this->transformer = new ClientTransformer($company);
|
||||
$this->transformed_data = $this->transformer->transform($this->customer_data['Customer']);
|
||||
}
|
||||
|
||||
public function testClassExists()
|
||||
{
|
||||
$this->assertInstanceOf(ClientTransformer::class, $this->transformer);
|
||||
}
|
||||
|
||||
public function testTransformReturnsArray()
|
||||
{
|
||||
$this->assertIsArray($this->transformed_data);
|
||||
}
|
||||
|
||||
public function testTransformHasNameProperty()
|
||||
{
|
||||
$this->assertArrayHasKey('name', $this->transformed_data);
|
||||
$this->assertEquals($this->customer_data['Customer']['CompanyName'], $this->transformed_data['name']);
|
||||
}
|
||||
|
||||
public function testTransformHasContactsProperty()
|
||||
{
|
||||
$this->assertArrayHasKey('contacts', $this->transformed_data);
|
||||
$this->assertIsArray($this->transformed_data['contacts']);
|
||||
$this->assertArrayHasKey(0, $this->transformed_data['contacts']);
|
||||
$this->assertArrayHasKey('email', $this->transformed_data['contacts'][0]);
|
||||
$this->assertEquals($this->customer_data['Customer']['PrimaryEmailAddr']['Address'], $this->transformed_data['contacts'][0]['email']);
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Import\Transformer\Quickbooks;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Import\Transformer\Quickbooks\InvoiceTransformer;
|
||||
|
||||
class InvoiceTransformerTest extends TestCase
|
||||
{
|
||||
private $invoiceData;
|
||||
private $tranformedData;
|
||||
private $transformer;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
// Mock the company object
|
||||
$company = (new \App\Factory\CompanyFactory)->create(1234);
|
||||
|
||||
// Read the JSON string from a file and decode into an associative array
|
||||
$this->invoiceData = json_decode( file_get_contents( app_path('/../tests/Mock/Response/Quickbooks/invoice.json') ), true);
|
||||
$this->transformer = new InvoiceTransformer($company);
|
||||
$this->transformedData = $this->transformer->transform($this->invoiceData['Invoice']);
|
||||
}
|
||||
|
||||
public function testIsInstanceOf()
|
||||
{
|
||||
$this->assertInstanceOf(InvoiceTransformer::class, $this->transformer);
|
||||
}
|
||||
|
||||
public function testTransformReturnsArray()
|
||||
{
|
||||
$this->assertIsArray($this->transformedData);
|
||||
}
|
||||
|
||||
public function testTransformContainsNumber()
|
||||
{
|
||||
$this->assertArrayHasKey('number', $this->transformedData);
|
||||
$this->assertEquals($this->invoiceData['Invoice']['DocNumber'], $this->transformedData['number']);
|
||||
}
|
||||
|
||||
public function testTransformContainsDueDate()
|
||||
{
|
||||
$this->assertArrayHasKey('due_date', $this->transformedData);
|
||||
$this->assertEquals(strtotime($this->invoiceData['Invoice']['DueDate']), strtotime($this->transformedData['due_date']));
|
||||
}
|
||||
|
||||
public function testTransformContainsAmount()
|
||||
{
|
||||
$this->assertArrayHasKey('amount', $this->transformedData);
|
||||
$this->assertIsFloat($this->transformedData['amount']);
|
||||
$this->assertEquals($this->invoiceData['Invoice']['TotalAmt'], $this->transformedData['amount']);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user