mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 08:17:32 -05:00 
			
		
		
		
	Client Tests
This commit is contained in:
		
							parent
							
								
									ebddf93353
								
							
						
					
					
						commit
						08e4f9724f
					
				@ -89,7 +89,6 @@ class ClientController extends Controller
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $data = [
 | 
					        $data = [
 | 
				
			||||||
        'client' => $client,
 | 
					        'client' => $client,
 | 
				
			||||||
        'settings' => collect(ClientSettings::buildClientSettings($client->company()->settings_object, $client->client_settings_object)),
 | 
					 | 
				
			||||||
        'hashed_id' => $this->encodePrimarykey($client->id),
 | 
					        'hashed_id' => $this->encodePrimarykey($client->id),
 | 
				
			||||||
        'company' => $client->company(),
 | 
					        'company' => $client->company(),
 | 
				
			||||||
        'sizes' => Size::all(),
 | 
					        'sizes' => Size::all(),
 | 
				
			||||||
 | 
				
			|||||||
@ -185,4 +185,9 @@ class Company extends BaseModel
 | 
				
			|||||||
        return $this->hasMany(CompanyToken::class);
 | 
					        return $this->hasMany(CompanyToken::class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function company_users()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->hasMany(CompanyUser::class);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -76,7 +76,7 @@ class UsersTableSeeder extends Seeder
 | 
				
			|||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        factory(\App\Models\Client::class, 50)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
 | 
					        factory(\App\Models\Client::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            factory(\App\Models\ClientContact::class,1)->create([
 | 
					            factory(\App\Models\ClientContact::class,1)->create([
 | 
				
			||||||
                'user_id' => $user->id,
 | 
					                'user_id' => $user->id,
 | 
				
			||||||
 | 
				
			|||||||
@ -4,6 +4,8 @@ namespace Tests\Feature;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use App\Models\Account;
 | 
					use App\Models\Account;
 | 
				
			||||||
use App\Models\Company;
 | 
					use App\Models\Company;
 | 
				
			||||||
 | 
					use App\Models\User;
 | 
				
			||||||
 | 
					use App\Utils\Traits\MakesHash;
 | 
				
			||||||
use Faker\Factory;
 | 
					use Faker\Factory;
 | 
				
			||||||
use Illuminate\Database\Eloquent\Model;
 | 
					use Illuminate\Database\Eloquent\Model;
 | 
				
			||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
					use Illuminate\Foundation\Testing\DatabaseTransactions;
 | 
				
			||||||
@ -15,7 +17,7 @@ use Tests\TestCase;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class ClientTest extends TestCase
 | 
					class ClientTest extends TestCase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    use MakesHash;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setUp()
 | 
					    public function setUp()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -57,7 +59,7 @@ class ClientTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $account = Account::find($acc['id']);
 | 
					        $account = Account::find($acc['id']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $token = $this->account->default_company->tokens()->first()->token;
 | 
					        $token = $account->default_company->tokens()->first()->token;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = $this->withHeaders([
 | 
					        $response = $this->withHeaders([
 | 
				
			||||||
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
					                'X-API-SECRET' => config('ninja.api_secret'),
 | 
				
			||||||
@ -70,17 +72,65 @@ class ClientTest extends TestCase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function testClientShow()
 | 
					    public function testClientShow()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $account = Account::all()->first();
 | 
					
 | 
				
			||||||
 | 
					        $data = [
 | 
				
			||||||
 | 
					            'first_name' => $this->faker->firstName,
 | 
				
			||||||
 | 
					            'last_name' => $this->faker->lastName,
 | 
				
			||||||
 | 
					            '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', $data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $acc = $response->json();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $account = Account::find($acc['id']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $token = $account->default_company->tokens()->first()->token;
 | 
					        $token = $account->default_company->tokens()->first()->token;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $company = $account->default_company;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $company_user = $company->company_users()->first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $user = User::find($company_user->user_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        factory(\App\Models\Client::class, 20)->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,10)->create([
 | 
				
			||||||
 | 
					                'user_id' => $user->id,
 | 
				
			||||||
 | 
					                'client_id' => $c->id,
 | 
				
			||||||
 | 
					                'company_id' => $company->id
 | 
				
			||||||
 | 
					            ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $client = $account->default_company->clients()->first();
 | 
					        $client = $account->default_company->clients()->first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->assertEquals(var_dump($account->default_company->clients->first()),1);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response = $this->withHeaders([
 | 
					        $response = $this->withHeaders([
 | 
				
			||||||
                'X-API-SECRET' => config('ninja.api_secret'),
 | 
					                'X-API-SECRET' => config('ninja.api_secret'),
 | 
				
			||||||
                'X-API-TOKEN' => $token,
 | 
					                'X-API-TOKEN' => $token,
 | 
				
			||||||
            ])->get('/api/v1/clients/'.$client->id);
 | 
					            ])->get('/api/v1/clients/'.$this->encodePrimaryKey($client->id));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $response->assertStatus(302);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $response = $this->withHeaders([
 | 
				
			||||||
 | 
					                'X-API-SECRET' => config('ninja.api_secret'),
 | 
				
			||||||
 | 
					                'X-API-TOKEN' => $token,
 | 
				
			||||||
 | 
					            ])->get('/api/v1/clients/'.$this->encodePrimaryKey($client->id).'/edit');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $response->assertStatus(200);
 | 
					        $response->assertStatus(200);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user