From 2df99a312e577a49e5868f0c9e23c168287cacc9 Mon Sep 17 00:00:00 2001 From: karneaud Date: Mon, 15 Jul 2024 21:29:51 -0400 Subject: [PATCH] update quickbook test for product import --- .../Import/Quickbooks/QuickbooksTest.php | 69 +++++++++++++------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/tests/Feature/Import/Quickbooks/QuickbooksTest.php b/tests/Feature/Import/Quickbooks/QuickbooksTest.php index 65bc1dab15ff..29a894baa774 100644 --- a/tests/Feature/Import/Quickbooks/QuickbooksTest.php +++ b/tests/Feature/Import/Quickbooks/QuickbooksTest.php @@ -5,17 +5,14 @@ namespace Tests\Feature\Import\Quickbooks; use Tests\TestCase; use App\Import\Providers\Quickbooks; 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 Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Routing\Middleware\ThrottleRequests; use Tests\MockAccountData; use Illuminate\Support\Facades\Cache; -use App\Http\Requests\Client\StoreClientRequest; use Mockery; use App\Models\Client; +use App\Models\Product; use Illuminate\Support\Str; use ReflectionClass; use Illuminate\Support\Facades\Auth; @@ -37,33 +34,34 @@ class QuickbooksTest extends TestCase $this->withoutMiddleware(ThrottleRequests::class); config(['database.default' => config('ninja.db.default')]); $this->makeTestData(); - // $this->withoutExceptionHandling(); + $this->withoutExceptionHandling(); 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() { - $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() ->with('client') - ->andReturn($this->data); + ->andReturn($data); // Mocking the dependencies used within the client method - $this->quickbooks->import('client'); + $quickbooks->import('client'); - $this->assertArrayHasKey('clients', $this->quickbooks->entity_count); - $this->assertGreaterThan(0, $this->quickbooks->entity_count['clients']); + $this->assertArrayHasKey('clients', $quickbooks->entity_count); + $this->assertGreaterThan(0, $quickbooks->entity_count['clients']); $base_transformer = new BaseTransformer($this->company); $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); } + 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 { Mockery::close();