mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 19:37:32 -05:00 
			
		
		
		
	update test case for import invoice feature
This commit is contained in:
		
							parent
							
								
									7520b6318d
								
							
						
					
					
						commit
						473f9ea0a0
					
				@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Cache;
 | 
			
		||||
use Mockery;
 | 
			
		||||
use App\Models\Client;
 | 
			
		||||
use App\Models\Product;
 | 
			
		||||
use App\Models\Invoice;
 | 
			
		||||
use Illuminate\Support\Str;
 | 
			
		||||
use ReflectionClass;
 | 
			
		||||
use Illuminate\Support\Facades\Auth;
 | 
			
		||||
@ -34,6 +35,7 @@ class QuickbooksTest extends TestCase
 | 
			
		||||
        $this->withoutMiddleware(ThrottleRequests::class);
 | 
			
		||||
        config(['database.default' => config('ninja.db.default')]);
 | 
			
		||||
        $this->makeTestData();
 | 
			
		||||
        // 
 | 
			
		||||
        $this->withoutExceptionHandling();
 | 
			
		||||
        Auth::setUser($this->user);
 | 
			
		||||
        
 | 
			
		||||
@ -102,6 +104,33 @@ class QuickbooksTest extends TestCase
 | 
			
		||||
        $this->assertLessThanOrEqual(0, $product->quantity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function testImportCallsGetDataOnceForInvoices()
 | 
			
		||||
    {
 | 
			
		||||
        $data = (json_decode( file_get_contents( base_path('tests/Feature/Import/invoices.json') ), true))['Invoice'];
 | 
			
		||||
        $hash = Str::random(32);
 | 
			
		||||
        Cache::put($hash.'-invoice', base64_encode(json_encode($data)), 360);
 | 
			
		||||
        $quickbooks = Mockery::mock(Quickbooks::class,[[
 | 
			
		||||
            'hash' => $hash,
 | 
			
		||||
            'column_map' => ['invoice' => ['mapping' => []]],
 | 
			
		||||
            'skip_header' => true,
 | 
			
		||||
            'import_type' => 'quickbooks',
 | 
			
		||||
        ], $this->company ])->makePartial();
 | 
			
		||||
        $quickbooks->shouldReceive('getData')
 | 
			
		||||
            ->once()
 | 
			
		||||
            ->with('invoice')
 | 
			
		||||
            ->andReturn($data);
 | 
			
		||||
        $quickbooks->import('invoice');
 | 
			
		||||
        $this->assertArrayHasKey('invoices', $quickbooks->entity_count);
 | 
			
		||||
        $this->assertGreaterThan(0, $quickbooks->entity_count['invoices']);
 | 
			
		||||
        $base_transformer = new BaseTransformer($this->company);
 | 
			
		||||
        $this->assertTrue($base_transformer->hasInvoice(1007));
 | 
			
		||||
        $invoice = Invoice::where('number',1012)->first();
 | 
			
		||||
        $data = collect($data)->where('DocNumber','1012')->first();
 | 
			
		||||
        $this->assertGreaterThanOrEqual( $data['TotalAmt'], $invoice->amount);
 | 
			
		||||
        $this->assertEquals( count($data['Line']) - 1 , count((array)$invoice->line_items));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    protected function tearDown(): void
 | 
			
		||||
    {
 | 
			
		||||
        Mockery::close();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user