faker = \Faker\Factory::create(); Model::reguard(); } public function testClientList() { $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); $response->assertStatus(200) ->assertJson([ 'first_name' => $data['first_name'], ]); $acc = $response->json(); $account = Account::find($acc['id']); $token = $account->default_company->tokens()->first()->token; $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, ])->get('/api/v1/clients'); $response->assertStatus(200); } /* * @covers ClientController */ public function testClientRestEndPoints() { $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); $this->assertTrue($user->isAdmin()); 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->load('contacts'); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, ])->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); $client_update = [ 'name' => 'A Funky Name' ]; $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, ])->put('/api/v1/clients/'.$this->encodePrimaryKey($client->id), $client_update) ->assertJson([ 'name' => 'A Funky Name' ]); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, ])->delete('/api/v1/clients/'.$this->encodePrimaryKey($client->id)); $response->assertStatus(200); $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $token, ])->post('/api/v1/clients/', ['name' => 'New Client']) ->assertJson([ 'name' => 'New Client' ]); $response->assertStatus(200); } }