From f2755aa1f483bf11b4f33f93474cfcddc22a46d3 Mon Sep 17 00:00:00 2001 From: karneaud Date: Thu, 8 Aug 2024 12:56:36 -0400 Subject: [PATCH] update tests --- .../ImportQuickbooksControllerTest.php | 61 ++++++++----------- .../Jobs/Import/QuickbooksIngestTest.php | 2 +- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/tests/Feature/Http/Controllers/ImportQuickbooksControllerTest.php b/tests/Feature/Http/Controllers/ImportQuickbooksControllerTest.php index 92d6f58f9148..26185371675d 100644 --- a/tests/Feature/Http/Controllers/ImportQuickbooksControllerTest.php +++ b/tests/Feature/Http/Controllers/ImportQuickbooksControllerTest.php @@ -38,7 +38,7 @@ class ImportQuickbooksControllerTest extends TestCase Session::start(); - app()->singleton(QuickbooksInterface::class, fn() => new QuickbooksSDK($this->mock)); + //app()->singleton(QuickbooksInterface::class, fn() => new QuickbooksSDK($this->mock)); } public function testAuthorize(): void @@ -88,47 +88,38 @@ class ImportQuickbooksControllerTest extends TestCase $this->mock->shouldHaveReceived('exchangeAuthorizationCodeForToken')->once()->with(123456,12345678); } - // public function testImport(): void - // { - // Cache::spy(); - // Bus::fake(); - // $this->mock->shouldReceive('Query')->andReturnUsing( - // function($val, $s = 1, $max = 1000) use ($count, $data) { - // if(stristr($val, 'count')) { - // return $count; - // } + public function testImport(): void + { + // Cache::spy(); + //Bus::fake(); + $data = $this->setUpTestData('customers'); + $count = count($data); + $this->mock->shouldReceive('Query')->andReturnUsing( + function($val, $s = 1, $max = 1000) use ($count, $data) { + if(stristr($val, 'count')) { + return $count; + } - // return Arr::take($data,$max); - // } - // ); - // $this->setUpTestData('customers'); - // // Perform the test - // $response = $this->withHeaders([ - // 'X-API-TOKEN' => $this->token, - // ])->post('/api/v1/import/quickbooks/preimport',[ - // 'import_type' => 'client' - // ]); - // $response->assertStatus(200); - // $response = json_decode( $response->getContent()); - // $this->assertNotNull($response->hash); - // $hash = $response->hash; - // $response = $this->withHeaders([ - // 'X-API-TOKEN' => $this->token, - // ])->post('/api/v1/import/quickbooks',[ - // 'import_type' => 'client', - // 'hash' => $response->hash - // ]); - // $response->assertStatus(200); + return Arr::take($data,$max); + } + ); + + // Perform the test + $response = $this->actingAs($this->user)->withHeaders([ + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/import/quickbooks',[ + 'import_types' => ['client'] + ]); + $response->assertStatus(200); - // Cache::shouldHaveReceived('has')->once()->with("{$hash}-client"); - // Bus::assertDispatched(\App\Jobs\Import\QuickbooksIngest::class); - // } + //Cache::shouldHaveReceived('has')->once()->with("{$hash}-client"); + //Bus::assertDispatched(\App\Jobs\Import\QuickbooksIngest::class); + } protected function setUpTestData($file) { $data = json_decode( file_get_contents(base_path("tests/Mock/Quickbooks/Data/$file.json")),true ); - $count = count($data); return $data; } diff --git a/tests/Feature/Jobs/Import/QuickbooksIngestTest.php b/tests/Feature/Jobs/Import/QuickbooksIngestTest.php index a2bbdd4974c0..0882d28c5b37 100644 --- a/tests/Feature/Jobs/Import/QuickbooksIngestTest.php +++ b/tests/Feature/Jobs/Import/QuickbooksIngestTest.php @@ -46,7 +46,7 @@ class QuickbooksIngestTest extends TestCase 'hash' => $hash, 'column_map' => ['client' => ['mapping' => []]], 'skip_header' => true, - 'import_type' => 'quickbooks', + 'import_types' => ['client'], ], $this->company )->handle(); $this->assertTrue(Client::withTrashed()->where(['company_id' => $this->company->id, 'name' => "Freeman Sporting Goods"])->exists()); }