diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index cd2ee614c591..81a36a166c33 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -89,7 +89,6 @@ class ClientController extends Controller $data = [ 'client' => $client, - 'settings' => collect(ClientSettings::buildClientSettings($client->company()->settings_object, $client->client_settings_object)), 'hashed_id' => $this->encodePrimarykey($client->id), 'company' => $client->company(), 'sizes' => Size::all(), diff --git a/app/Models/Company.php b/app/Models/Company.php index ae2eb41c8383..72bb567d94b3 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -185,4 +185,9 @@ class Company extends BaseModel return $this->hasMany(CompanyToken::class); } + public function company_users() + { + return $this->hasMany(CompanyUser::class); + } + } diff --git a/database/seeds/UsersTableSeeder.php b/database/seeds/UsersTableSeeder.php index cae3f9d4040a..dd98293662b8 100644 --- a/database/seeds/UsersTableSeeder.php +++ b/database/seeds/UsersTableSeeder.php @@ -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([ 'user_id' => $user->id, diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 36cd065cf410..0383af77ec92 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -4,6 +4,8 @@ namespace Tests\Feature; use App\Models\Account; use App\Models\Company; +use App\Models\User; +use App\Utils\Traits\MakesHash; use Faker\Factory; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -15,7 +17,7 @@ use Tests\TestCase; class ClientTest extends TestCase { - + use MakesHash; public function setUp() { @@ -57,7 +59,7 @@ class ClientTest extends TestCase $account = Account::find($acc['id']); - $token = $this->account->default_company->tokens()->first()->token; + $token = $account->default_company->tokens()->first()->token; $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), @@ -70,17 +72,65 @@ class ClientTest extends TestCase 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; + $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(); - $this->assertEquals(var_dump($account->default_company->clients->first()),1); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), '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); }