diff --git a/tests/Integration/Services/Import/Quickbooks/QuickBooksServiceTest.php b/tests/Integration/Services/Import/Quickbooks/QuickBooksServiceTest.php new file mode 100644 index 000000000000..5b9502129464 --- /dev/null +++ b/tests/Integration/Services/Import/Quickbooks/QuickBooksServiceTest.php @@ -0,0 +1,48 @@ +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']); + } +} diff --git a/tests/Unit/Services/Import/Quickbooks/SdkWrapperTest.php b/tests/Unit/Services/Import/Quickbooks/SdkWrapperTest.php new file mode 100644 index 000000000000..a76da2720fe1 --- /dev/null +++ b/tests/Unit/Services/Import/Quickbooks/SdkWrapperTest.php @@ -0,0 +1,47 @@ +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))); + } +} diff --git a/tests/Unit/Services/Import/Quickbooks/ServiceTest.php b/tests/Unit/Services/Import/Quickbooks/ServiceTest.php new file mode 100644 index 000000000000..2c0f2b5553d8 --- /dev/null +++ b/tests/Unit/Services/Import/Quickbooks/ServiceTest.php @@ -0,0 +1,54 @@ +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); + } +}