Client Tests

This commit is contained in:
David Bomba 2019-03-27 17:22:27 +11:00
parent ebddf93353
commit 08e4f9724f
4 changed files with 61 additions and 7 deletions

View File

@ -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(),

View File

@ -185,4 +185,9 @@ class Company extends BaseModel
return $this->hasMany(CompanyToken::class);
}
public function company_users()
{
return $this->hasMany(CompanyUser::class);
}
}

View File

@ -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,

View File

@ -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);
}