From 4d431935e1678780c4cd21c230174280d9c432da Mon Sep 17 00:00:00 2001 From: karneaud Date: Mon, 15 Jul 2024 15:07:49 -0400 Subject: [PATCH] add test case for quickbooks import class --- .../Import/Quickbooks/QuickbooksTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/Feature/Import/Quickbooks/QuickbooksTest.php diff --git a/tests/Feature/Import/Quickbooks/QuickbooksTest.php b/tests/Feature/Import/Quickbooks/QuickbooksTest.php new file mode 100644 index 000000000000..65bc1dab15ff --- /dev/null +++ b/tests/Feature/Import/Quickbooks/QuickbooksTest.php @@ -0,0 +1,81 @@ +withoutMiddleware(ThrottleRequests::class); + config(['database.default' => config('ninja.db.default')]); + $this->makeTestData(); + // $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') + ->once() + ->with('client') + ->andReturn($this->data); + + // Mocking the dependencies used within the client method + + $this->quickbooks->import('client'); + + $this->assertArrayHasKey('clients', $this->quickbooks->entity_count); + $this->assertGreaterThan(0, $this->quickbooks->entity_count['clients']); + + $base_transformer = new BaseTransformer($this->company); + $this->assertTrue($base_transformer->hasClient('Sonnenschein Family Store')); + $contact = $base_transformer->getClient('Amy\'s Bird Sanctuary',''); + $contact = Client::where('name','Amy\'s Bird Sanctuary')->first(); + $this->assertEquals('(650) 555-3311',$contact->phone); + $this->assertEquals('Birds@Intuit.com',$contact->contacts()->first()->email); + } + + protected function tearDown(): void + { + Mockery::close(); + parent::tearDown(); + } +}