Comments & Discussion
In the tests of this section: Wouldn't it be more explicit to check, if the company owner can edit a guide and not himself?
Before:
public function test_company_owner_can_edit_guide_for_his_company(){ $company = Company::factory()->create(); $user = User::factory()->companyOwner()->create(['company_id' => $company->id]); $response = $this->actingAs($user)->put(route('companies.guides.update', [$company->id, $user->id]), [ 'name' => 'updated user', 'email' => 'test@update.com', ]); $response->assertRedirect(route('companies.guides.index', $company->id)); $this->assertDatabaseHas('users', [ 'name' => 'updated user', 'email' => 'test@update.com', 'company_id' => $company->id, ]);}
After:
public function test_company_owner_can_edit_guide_for_his_company(){ $company = Company::factory()->create(); $user = User::factory()->companyOwner()->create(['company_id' => $company->id]); $guide = User::factory()->guide()->create(['company_id' => $company->id]); $response = $this->actingAs($user)->put(route('companies.guides.update', [$company->id, $guide->id]), [ 'name' => 'updated user', 'email' => 'test@update.com', ]); $response->assertRedirect(route('companies.guides.index', $company->id)); $this->assertDatabaseHas('users', [ 'name' => 'updated user', 'email' => 'test@update.com', 'company_id' => $company->id, ]);}
The same for the other. Plus and an additional point: It should be tested, if the actual data of the user/guide is removed, that was created with the factory. With assertDatabaseMissing() the test would would always pass, because the given data was never in the database. And because auf the introduction of soft deletes a few chapters back, it should also be replaced by assertSoftDeleted() .
Before:
public function test_company_owner_can_delete_guide_for_his_company(){ $company = Company::factory()->create(); $user = User::factory()->companyOwner()->create(['company_id' => $company->id]); $response = $this->actingAs($user)->delete(route('companies.guides.update', [$company->id, $user->id])); $response->assertRedirect(route('companies.guides.index', $company
Hi, is there a different in using:
$response = $this->actingAs($user)->get(route('companies.guides.index', $company->id));
or
$response = $this->actingAs($user)->get(route('companies.guides.index', $company));
in both cases the test passes without errors, how laravel interprets them? thanks
This is a weird one at least for me 7 passed and 1 failed that one was the first one. Any suggestions?
PS the /n goes on for quite a wile like 20 to 30 lines.
could the problem be the fact that I don't have a second user? but would't that be supplied by the UserFactory or the CompanyFactory ?
In CompanyGuideController index method
should query the guide role id like this:
$guides = $company->users()->where('role_id', RoleEnum::GUIDE->value)->get();
Either its me, or shouldnt the last two tests be written like this?
public function test_company_owner_can_delete_guides_from_their_company() { $company = Company::factory()->create();