mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:40:09 -05:00 
			
		
		
		
	* Fixes for tests * add additional fields for company settings * fixes for travis * update company settings schema * Disable client portal * Client Portal middleware * Working on client portal * hide portal * Implement notification channgels for User and ClientContact models * Push notifications onto queue * Force authentication if client portal is password protected
		
			
				
	
	
		
			181 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			181 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace Tests\Feature;
 | 
						|
 | 
						|
use App\DataMapper\ClientSettings;
 | 
						|
use App\DataMapper\CompanySettings;
 | 
						|
use App\Factory\InvoiceFactory;
 | 
						|
use App\Models\Account;
 | 
						|
use App\Models\Client;
 | 
						|
use App\Models\Invoice;
 | 
						|
use App\Utils\Traits\MakesHash;
 | 
						|
use Illuminate\Database\Eloquent\Model;
 | 
						|
use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
						|
use Illuminate\Foundation\Testing\RefreshDatabase;
 | 
						|
use Illuminate\Foundation\Testing\WithFaker;
 | 
						|
use Illuminate\Support\Facades\Log;
 | 
						|
use Illuminate\Support\Facades\Session;
 | 
						|
use Tests\MockAccountData;
 | 
						|
use Tests\TestCase;
 | 
						|
 | 
						|
/**
 | 
						|
 * @test
 | 
						|
 * @covers App\Http\Controllers\InvoiceController
 | 
						|
 */
 | 
						|
    
 | 
						|
class InvoiceTest extends TestCase
 | 
						|
{
 | 
						|
 | 
						|
    use MakesHash;
 | 
						|
    use DatabaseTransactions;
 | 
						|
    use MockAccountData;
 | 
						|
 | 
						|
    public function setUp() :void
 | 
						|
    {
 | 
						|
 | 
						|
        parent::setUp();
 | 
						|
 | 
						|
        Session::start();
 | 
						|
 | 
						|
        $this->faker = \Faker\Factory::create();
 | 
						|
 | 
						|
        Model::reguard();
 | 
						|
 | 
						|
        $this->makeTestData();
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
    public function testInvoiceList()
 | 
						|
    {
 | 
						|
        $data = [
 | 
						|
            'first_name' => $this->faker->firstName,
 | 
						|
            'last_name' => $this->faker->lastName,
 | 
						|
            'name' => $this->faker->company,
 | 
						|
            'email' => $this->faker->unique()->safeEmail,
 | 
						|
            'password' => 'ALongAndBrilliantPassword123',
 | 
						|
            '_token' => csrf_token(),
 | 
						|
            'privacy_policy' => 1,
 | 
						|
            'terms_of_service' => 1
 | 
						|
        ];
 | 
						|
 | 
						|
 | 
						|
        $response = $this->withHeaders([
 | 
						|
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
						|
            ])->post('/api/v1/signup?include=account', $data);
 | 
						|
 | 
						|
        $acc = $response->json();
 | 
						|
 | 
						|
        $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));                
 | 
						|
 | 
						|
        $company_token = $account->default_company->tokens()->first();
 | 
						|
        $token = $company_token->token;
 | 
						|
        $company = $company_token->company;
 | 
						|
 | 
						|
        $user = $company_token->user;
 | 
						|
 | 
						|
        $this->assertNotNull($company_token);
 | 
						|
        $this->assertNotNull($token);
 | 
						|
        $this->assertNotNull($user);
 | 
						|
        $this->assertNotNull($company);
 | 
						|
        //$this->assertNotNull($user->token->company);
 | 
						|
 | 
						|
        factory(\App\Models\Client::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
 | 
						|
 | 
						|
            factory(\App\Models\ClientContact::class,1)->create([
 | 
						|
                'user_id' => $user->id,
 | 
						|
                'client_id' => $c->id,
 | 
						|
                'company_id' => $company->id,
 | 
						|
                'is_primary' => 1
 | 
						|
            ]);
 | 
						|
 | 
						|
            factory(\App\Models\ClientContact::class,1)->create([
 | 
						|
                'user_id' => $user->id,
 | 
						|
                'client_id' => $c->id,
 | 
						|
                'company_id' => $company->id
 | 
						|
            ]);
 | 
						|
 | 
						|
        });
 | 
						|
        $client = Client::all()->first();
 | 
						|
 | 
						|
        factory(\App\Models\Invoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
 | 
						|
 | 
						|
 | 
						|
        $response = $this->withHeaders([
 | 
						|
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
						|
                'X-API-TOKEN' => $token,
 | 
						|
            ])->get('/api/v1/invoices');
 | 
						|
 | 
						|
        $response->assertStatus(200);
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
    public function testInvoiceRESTEndPoints()
 | 
						|
    {
 | 
						|
        
 | 
						|
        $response = $this->withHeaders([
 | 
						|
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
						|
                'X-API-TOKEN' => $this->token,
 | 
						|
            ])->get('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id));
 | 
						|
 | 
						|
        $response->assertStatus(200);
 | 
						|
 | 
						|
        $response = $this->withHeaders([
 | 
						|
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
						|
                'X-API-TOKEN' => $this->token,
 | 
						|
            ])->get('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id).'/edit');
 | 
						|
 | 
						|
        $response->assertStatus(200);
 | 
						|
 | 
						|
        $invoice_update = [
 | 
						|
            'tax_name1' => 'dippy',
 | 
						|
        ];
 | 
						|
 | 
						|
        $this->assertNotNull($this->invoice);
 | 
						|
        $this->assertNotNull($this->invoice->settings);
 | 
						|
 | 
						|
        $this->assertTrue(property_exists($this->invoice->settings, 'custom_invoice_taxes1'));
 | 
						|
 | 
						|
        $response = $this->withHeaders([
 | 
						|
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
						|
                'X-API-TOKEN' => $this->token,
 | 
						|
            ])->put('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id), $invoice_update)
 | 
						|
            ->assertStatus(200);
 | 
						|
 | 
						|
    }
 | 
						|
 | 
						|
    public function testPostNewInvoice()
 | 
						|
    {
 | 
						|
        $invoice = [
 | 
						|
            'status_id' => 1,
 | 
						|
            'invoice_number' => 'dfdfd', 
 | 
						|
            'discount' => 0,
 | 
						|
            'is_amount_discount' => 1,
 | 
						|
            'po_number' => '3434343',
 | 
						|
            'public_notes' => 'notes',
 | 
						|
            'is_deleted' => 0,
 | 
						|
            'custom_value1' => 0,
 | 
						|
            'custom_value2' => 0,
 | 
						|
            'custom_value3' => 0,
 | 
						|
            'custom_value4' => 0,
 | 
						|
            'status' => 1,
 | 
						|
            'client_id' => $this->encodePrimaryKey($this->client->id),
 | 
						|
        ];
 | 
						|
 | 
						|
            $response = $this->withHeaders([
 | 
						|
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
						|
                'X-API-TOKEN' => $this->token,
 | 
						|
            ])->post('/api/v1/invoices/', $invoice)
 | 
						|
            ->assertStatus(200);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testDeleteInvoice()
 | 
						|
    {
 | 
						|
            $response = $this->withHeaders([
 | 
						|
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
						|
                'X-API-TOKEN' => $this->token,
 | 
						|
            ])->delete('/api/v1/invoices/'.$this->encodePrimaryKey($this->invoice->id));
 | 
						|
 | 
						|
        $response->assertStatus(200);
 | 
						|
    }
 | 
						|
 | 
						|
} |