mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 04:57:31 -04:00 
			
		
		
		
	add service tests for quickbooks
This commit is contained in:
		
							parent
							
								
									d5e499febd
								
							
						
					
					
						commit
						3ba4533b28
					
				| @ -0,0 +1,48 @@ | ||||
| <?php | ||||
| 
 | ||||
| namespace Tests\Integration\Services\Import\Quickbooks; | ||||
| 
 | ||||
| use App\Services\Import\Quickbooks\Contracts\SdkInterface as QuickbooksInterface; | ||||
| use App\Services\Import\Quickbooks\Service as QuickbooksService; | ||||
| use App\Services\Import\Quickbooks\SdkWrapper as QuickbooksSDK; | ||||
| use Illuminate\Support\Collection; | ||||
| use Illuminate\Support\Arr; | ||||
| use Tests\TestCase; | ||||
| use Mockery; | ||||
| 
 | ||||
| class QuickBooksServiceTest extends TestCase | ||||
| { | ||||
|     private $service; | ||||
| 
 | ||||
|     protected function setUp(): void | ||||
|     { | ||||
|         parent::setUp(); | ||||
|   | ||||
|         $data = json_decode( | ||||
|             file_get_contents(base_path('tests/Mock/Quickbooks/Data/customers.json')),true | ||||
|         ); | ||||
|         $count = count($data); | ||||
|         $sdkMock = Mockery::mock(sdtClass::class); | ||||
|         $sdkMock->shouldReceive('Query')->andReturnUsing(function($val) use ($count, $data) { | ||||
|             if(stristr($val, 'count')) { | ||||
|                 return $count; | ||||
|             } | ||||
| 
 | ||||
|             return Arr::take($data,4); | ||||
|         }); | ||||
|         app()->singleton(QuickbooksInterface::class, fn() => new QuickbooksSDK($sdkMock)); | ||||
| 
 | ||||
|         $this->service = app(QuickbooksService::class); | ||||
|          | ||||
|     } | ||||
| 
 | ||||
|     public function testImportCustomers() | ||||
|     { | ||||
|         $collection = $this->service->fetchCustomers(4); | ||||
|          | ||||
|         $this->assertInstanceOf(Collection::class, $collection); | ||||
|         $this->assertEquals(4, $collection->count()); | ||||
|         $this->assertNotNull($item = $collection->whereStrict('CompanyName', "Cool Cars")->first()); | ||||
|         $this->assertEquals("Grace", $item['GivenName']); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										47
									
								
								tests/Unit/Services/Import/Quickbooks/SdkWrapperTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								tests/Unit/Services/Import/Quickbooks/SdkWrapperTest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,47 @@ | ||||
| <?php | ||||
| // tests/Unit/IntuitSDKWrapperTest.php
 | ||||
| namespace Tests\Unit\Services\Import\Quickbooks; | ||||
| 
 | ||||
| use Mockery; | ||||
| use Tests\TestCase; | ||||
| use Illuminate\Support\Arr; | ||||
| use App\Services\Import\Quickbooks\Contracts\SdkInterface; | ||||
| use App\Services\Import\Quickbooks\SdkWrapper as QuickbookSDK; | ||||
| 
 | ||||
| class SdkWrapperTest extends TestCase | ||||
| { | ||||
| 
 | ||||
|     protected $sdk; | ||||
|     protected $sdkMock; | ||||
| 
 | ||||
|     protected function setUp(): void | ||||
|     { | ||||
|         parent::setUp(); | ||||
| 
 | ||||
|         $this->sdkMock = Mockery::mock(sdtClass::class); | ||||
|         $this->sdk = new QuickbookSDK($this->sdkMock); | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     function testIsInstanceOf() { | ||||
|         $this->assertInstanceOf(SdkInterface::class, $this->sdk); | ||||
|     } | ||||
| 
 | ||||
|     function testMethodFetchRecords() { | ||||
|         $data = json_decode( | ||||
|                     file_get_contents(base_path('tests/Mock/Quickbooks/Data/customers.json')),true | ||||
|         ); | ||||
|         $count = count($data); | ||||
|         $this->sdkMock->shouldReceive('Query')->andReturnUsing(function($val) use ($count, $data) { | ||||
|             if(stristr($val, 'count')) { | ||||
|                 return $count; | ||||
|             } | ||||
| 
 | ||||
|             return Arr::take($data,4); | ||||
|         }); | ||||
| 
 | ||||
|         $this->assertEquals($count, $this->sdk->totalRecords('Customer')); | ||||
|         $this->assertEquals(4, count($this->sdk->fetchRecords('Customer', 4))); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										54
									
								
								tests/Unit/Services/Import/Quickbooks/ServiceTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								tests/Unit/Services/Import/Quickbooks/ServiceTest.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| <?php | ||||
| namespace Tests\Unit\Services\Import\Quickbooks; | ||||
| 
 | ||||
| use Mockery; | ||||
| use Tests\TestCase; | ||||
| use Illuminate\Support\Collection; | ||||
| use App\Services\Import\Quickbooks\Service as QuickbooksService; | ||||
| use App\Services\Import\Quickbooks\Contracts\SdkInterface as QuickbooksInterface; | ||||
| 
 | ||||
| class ServiceTest extends TestCase | ||||
| { | ||||
|     protected $service; | ||||
| 
 | ||||
|     protected function setUp(): void | ||||
|     { | ||||
|         parent::setUp(); | ||||
|         // Inject the mock into the IntuitSDKservice instance
 | ||||
|         $this->service = Mockery::mock( new QuickbooksService(Mockery::mock(QuickbooksInterface::class)))->shouldAllowMockingProtectedMethods(); | ||||
|     } | ||||
| 
 | ||||
|     protected function tearDown(): void | ||||
|     { | ||||
|         Mockery::close(); | ||||
|         parent::tearDown(); | ||||
|     } | ||||
| 
 | ||||
|     public function testTotalRecords() | ||||
|     { | ||||
|         $entity = 'Customer'; | ||||
|         $count = 10; | ||||
| 
 | ||||
|         $this->service->shouldReceive('totalRecords') | ||||
|                       ->with($entity) | ||||
|                       ->andReturn($count); | ||||
| 
 | ||||
|         $result = $this->service->totalRecords($entity); | ||||
| 
 | ||||
|         $this->assertEquals($count, $result); | ||||
|     } | ||||
| 
 | ||||
|     public function testHasFetchRecords() | ||||
|     { | ||||
|         $entity = 'Customer'; | ||||
|         $count = 10; | ||||
| 
 | ||||
|         $this->service->shouldReceive('fetchRecords') | ||||
|                       ->with($entity, $count) | ||||
|                       ->andReturn(collect()); | ||||
| 
 | ||||
|         $result = $this->service->fetchCustomers($count); | ||||
| 
 | ||||
|         $this->assertInstanceOf(Collection::class, $result); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user