update quickbook test for product import

This commit is contained in:
karneaud 2024-07-15 21:29:51 -04:00
parent 4cde94f203
commit 2df99a312e

View File

@ -5,17 +5,14 @@ namespace Tests\Feature\Import\Quickbooks;
use Tests\TestCase; use Tests\TestCase;
use App\Import\Providers\Quickbooks; use App\Import\Providers\Quickbooks;
use App\Import\Transformer\BaseTransformer; use App\Import\Transformer\BaseTransformer;
use App\Import\Transformer\Quickbooks\ClientTransformer;
use App\Repositories\ClientRepository;
use App\Factory\ClientFactory;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Routing\Middleware\ThrottleRequests;
use Tests\MockAccountData; use Tests\MockAccountData;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use App\Http\Requests\Client\StoreClientRequest;
use Mockery; use Mockery;
use App\Models\Client; use App\Models\Client;
use App\Models\Product;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use ReflectionClass; use ReflectionClass;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
@ -37,33 +34,34 @@ class QuickbooksTest extends TestCase
$this->withoutMiddleware(ThrottleRequests::class); $this->withoutMiddleware(ThrottleRequests::class);
config(['database.default' => config('ninja.db.default')]); config(['database.default' => config('ninja.db.default')]);
$this->makeTestData(); $this->makeTestData();
// $this->withoutExceptionHandling(); $this->withoutExceptionHandling();
Auth::setUser($this->user); Auth::setUser($this->user);
$this->data = (json_decode( file_get_contents( base_path('tests/Feature/Import/customers.json') ), true))['Customer'];
$hash = Str::random(32);
Cache::put($hash.'-client', base64_encode(json_encode($this->data)), 360);
$this->quickbooks = Mockery::mock(Quickbooks::class,[[
'hash' => $hash,
'column_map' => ['client' => ['mapping' => []]],
'skip_header' => true,
'import_type' => 'invoicely',
], $this->company ])->makePartial();
} }
public function testImportCallsGetDataOnceForClient() public function testImportCallsGetDataOnceForClient()
{ {
$this->quickbooks->shouldReceive('getData') $data = (json_decode( file_get_contents( base_path('tests/Feature/Import/customers.json') ), true))['Customer'];
$hash = Str::random(32);
Cache::put($hash.'-client', base64_encode(json_encode($data)), 360);
$quickbooks = Mockery::mock(Quickbooks::class,[[
'hash' => $hash,
'column_map' => ['client' => ['mapping' => []]],
'skip_header' => true,
'import_type' => 'quickbooks',
], $this->company ])->makePartial();
$quickbooks->shouldReceive('getData')
->once() ->once()
->with('client') ->with('client')
->andReturn($this->data); ->andReturn($data);
// Mocking the dependencies used within the client method // Mocking the dependencies used within the client method
$this->quickbooks->import('client'); $quickbooks->import('client');
$this->assertArrayHasKey('clients', $this->quickbooks->entity_count); $this->assertArrayHasKey('clients', $quickbooks->entity_count);
$this->assertGreaterThan(0, $this->quickbooks->entity_count['clients']); $this->assertGreaterThan(0, $quickbooks->entity_count['clients']);
$base_transformer = new BaseTransformer($this->company); $base_transformer = new BaseTransformer($this->company);
$this->assertTrue($base_transformer->hasClient('Sonnenschein Family Store')); $this->assertTrue($base_transformer->hasClient('Sonnenschein Family Store'));
@ -73,6 +71,37 @@ class QuickbooksTest extends TestCase
$this->assertEquals('Birds@Intuit.com',$contact->contacts()->first()->email); $this->assertEquals('Birds@Intuit.com',$contact->contacts()->first()->email);
} }
public function testImportCallsGetDataOnceForProducts()
{
$data = (json_decode( file_get_contents( base_path('tests/Feature/Import/items.json') ), true))['Item'];
$hash = Str::random(32);
Cache::put($hash.'-item', base64_encode(json_encode($data)), 360);
$quickbooks = Mockery::mock(Quickbooks::class,[[
'hash' => $hash,
'column_map' => ['item' => ['mapping' => []]],
'skip_header' => true,
'import_type' => 'quickbooks',
], $this->company ])->makePartial();
$quickbooks->shouldReceive('getData')
->once()
->with('product')
->andReturn($data);
// Mocking the dependencies used within the client method
$quickbooks->import('product');
$this->assertArrayHasKey('products', $quickbooks->entity_count);
$this->assertGreaterThan(0, $quickbooks->entity_count['products']);
$base_transformer = new BaseTransformer($this->company);
$this->assertTrue($base_transformer->hasProduct('Gardening'));
$product = Product::where('product_key','Pest Control')->first();
$this->assertGreaterThanOrEqual( 35, $product->price);
$this->assertLessThanOrEqual(0, $product->quantity);
}
protected function tearDown(): void protected function tearDown(): void
{ {
Mockery::close(); Mockery::close();