mirror of
https://github.com/10h30/Test-Eloquent-Relationships.git
synced 2026-06-05 15:07:42 +09:00
Task 8 - belongstomany add
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Tests\Feature;
|
||||
use App\Models\Attachment;
|
||||
use App\Models\Comment;
|
||||
use App\Models\Country;
|
||||
use App\Models\Project;
|
||||
use App\Models\Role;
|
||||
use App\Models\Task;
|
||||
use App\Models\Team;
|
||||
@@ -133,4 +134,23 @@ class RelationshipsTest extends TestCase
|
||||
$response->assertSee('Task');
|
||||
$response->assertSee('Comment');
|
||||
}
|
||||
|
||||
// TASK: add a record to belongstomany relationship
|
||||
public function test_belongstomany_add()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$project = Project::create(['name' => 'Some project']);
|
||||
|
||||
$response = $this->actingAs($user)->post('/projects', [
|
||||
'project_id' => $project->id,
|
||||
'start_date' => now()->toDateString()
|
||||
]);
|
||||
$response->assertStatus(200);
|
||||
|
||||
$this->assertDatabaseHas('project_user', [
|
||||
'project_id' => $project->id,
|
||||
'user_id' => $user->id,
|
||||
'start_date' => now()->toDateString()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user