update emergency contact student controller
This commit is contained in:
@@ -54,7 +54,7 @@ class EmergencyContactControllerTest extends TestCase
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
$response = $this->getJson('/api/v1/administrator/emergency-contacts');
|
||||
|
||||
$response->assertOk();
|
||||
@@ -79,12 +79,15 @@ class EmergencyContactControllerTest extends TestCase
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
$response = $this->patchJson('/api/v1/administrator/emergency-contacts/' . $contact->id, [
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
$response = $this->patch('/api/v1/administrator/emergency-contacts/' . $contact->id, [
|
||||
'parent_id' => $parent->id,
|
||||
'name' => 'New Name',
|
||||
'cellphone' => '5555555555',
|
||||
'email' => 'new@example.com',
|
||||
'relation' => 'Neighbor',
|
||||
], [
|
||||
'Accept' => 'application/json',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
@@ -112,8 +115,12 @@ class EmergencyContactControllerTest extends TestCase
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($admin);
|
||||
$response = $this->deleteJson('/api/v1/administrator/emergency-contacts/' . $contact->id);
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
$response = $this->delete('/api/v1/administrator/emergency-contacts/' . $contact->id, [
|
||||
'parent_id' => $parent->id,
|
||||
], [
|
||||
'Accept' => 'application/json',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJson(['ok' => true]);
|
||||
@@ -121,4 +128,92 @@ class EmergencyContactControllerTest extends TestCase
|
||||
'id' => $contact->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_show_returns_single_contact_for_parent(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$parent = User::factory()->create();
|
||||
|
||||
$contact = EmergencyContact::query()->create([
|
||||
'parent_id' => $parent->id,
|
||||
'emergency_contact_name' => 'Single Contact',
|
||||
'cellphone' => '7777777777',
|
||||
'email' => 'single@example.com',
|
||||
'relation' => 'Friend',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
$response = $this->get('/api/v1/administrator/emergency-contacts/' . $contact->id . '?parent_id=' . $parent->id, [
|
||||
'Accept' => 'application/json',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertJsonPath('contact.id', $contact->id);
|
||||
$response->assertJsonPath('contact.parent_id', $parent->id);
|
||||
}
|
||||
|
||||
public function test_update_requires_matching_parent_id(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$parent = User::factory()->create();
|
||||
$otherParent = User::factory()->create();
|
||||
|
||||
$contact = EmergencyContact::query()->create([
|
||||
'parent_id' => $parent->id,
|
||||
'emergency_contact_name' => 'Old Name',
|
||||
'cellphone' => '8888888888',
|
||||
'email' => 'old@example.com',
|
||||
'relation' => 'Friend',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
$response = $this->patch('/api/v1/administrator/emergency-contacts/' . $contact->id, [
|
||||
'parent_id' => $otherParent->id,
|
||||
'name' => 'New Name',
|
||||
'cellphone' => '9999999999',
|
||||
'email' => 'new@example.com',
|
||||
'relation' => 'Neighbor',
|
||||
], [
|
||||
'Accept' => 'application/json',
|
||||
]);
|
||||
|
||||
$response->assertNotFound();
|
||||
$this->assertDatabaseHas('emergency_contacts', [
|
||||
'id' => $contact->id,
|
||||
'emergency_contact_name' => 'Old Name',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_destroy_requires_matching_parent_id(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
$parent = User::factory()->create();
|
||||
$otherParent = User::factory()->create();
|
||||
|
||||
$contact = EmergencyContact::query()->create([
|
||||
'parent_id' => $parent->id,
|
||||
'emergency_contact_name' => 'Delete Name',
|
||||
'cellphone' => '1010101010',
|
||||
'email' => 'delete@example.com',
|
||||
'relation' => 'Friend',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
]);
|
||||
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
$response = $this->delete('/api/v1/administrator/emergency-contacts/' . $contact->id, [
|
||||
'parent_id' => $otherParent->id,
|
||||
], [
|
||||
'Accept' => 'application/json',
|
||||
]);
|
||||
|
||||
$response->assertNotFound();
|
||||
$this->assertDatabaseHas('emergency_contacts', [
|
||||
'id' => $contact->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user