add school year model
This commit is contained in:
@@ -5,6 +5,7 @@ namespace Tests\Feature\Api\Administrator;
|
||||
use App\Models\User;
|
||||
use App\Services\Administrator\TeacherSubmissionNotificationService;
|
||||
use App\Services\Administrator\TeacherSubmissionReportService;
|
||||
use App\Http\Middleware\EnsurePrintRequestsAdminAccess;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Mockery;
|
||||
@@ -22,12 +23,14 @@ class AdministratorTeacherSubmissionControllerTest extends TestCase
|
||||
|
||||
public function test_can_get_teacher_submission_report(): void
|
||||
{
|
||||
$this->withoutMiddleware(EnsurePrintRequestsAdminAccess::class);
|
||||
$user = User::factory()->create();
|
||||
Sanctum::actingAs($user);
|
||||
Sanctum::actingAs($user, [], 'api');
|
||||
|
||||
$mock = Mockery::mock(TeacherSubmissionReportService::class);
|
||||
$mock->shouldReceive('report')
|
||||
->once()
|
||||
->with([])
|
||||
->andReturn([
|
||||
'rows' => [],
|
||||
'semester' => 'Fall',
|
||||
@@ -55,8 +58,9 @@ class AdministratorTeacherSubmissionControllerTest extends TestCase
|
||||
|
||||
public function test_notify_requires_notify_payload(): void
|
||||
{
|
||||
$this->withoutMiddleware(EnsurePrintRequestsAdminAccess::class);
|
||||
$user = User::factory()->create();
|
||||
Sanctum::actingAs($user);
|
||||
Sanctum::actingAs($user, [], 'api');
|
||||
|
||||
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', [
|
||||
'missing_items' => [],
|
||||
@@ -68,8 +72,9 @@ class AdministratorTeacherSubmissionControllerTest extends TestCase
|
||||
|
||||
public function test_notify_calls_service(): void
|
||||
{
|
||||
$this->withoutMiddleware(EnsurePrintRequestsAdminAccess::class);
|
||||
$user = User::factory()->create();
|
||||
Sanctum::actingAs($user);
|
||||
Sanctum::actingAs($user, [], 'api');
|
||||
|
||||
$payload = [
|
||||
'notify' => [
|
||||
@@ -105,4 +110,4 @@ class AdministratorTeacherSubmissionControllerTest extends TestCase
|
||||
'failed' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+96
-15
@@ -32,8 +32,8 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
|
||||
|
||||
public function test_notify_endpoint_requires_notify_payload(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
Sanctum::actingAs($admin);
|
||||
$admin = $this->seedAdminUser('admin.notify.required@example.com');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', [
|
||||
'missing_items' => [],
|
||||
@@ -47,13 +47,8 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$admin = User::factory()->create([
|
||||
'id' => 900,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'One',
|
||||
'email' => 'admin@test.com',
|
||||
]);
|
||||
Sanctum::actingAs($admin);
|
||||
$admin = $this->seedAdminUser('admin@test.com', 900, 'Admin', 'One');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
User::factory()->create([
|
||||
'id' => 100,
|
||||
@@ -117,12 +112,8 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$admin = User::factory()->create([
|
||||
'id' => 901,
|
||||
'firstname' => 'Admin',
|
||||
'lastname' => 'Two',
|
||||
]);
|
||||
Sanctum::actingAs($admin);
|
||||
$admin = $this->seedAdminUser('admin.two@test.com', 901, 'Admin', 'Two');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
User::factory()->create([
|
||||
'id' => 101,
|
||||
@@ -169,4 +160,94 @@ class AdministratorTeacherSubmissionNotifyApiTest extends TestCase
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_notify_endpoint_accepts_flat_teacher_ids_from_spa_payload(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$admin = $this->seedAdminUser('admin3@test.com', 902, 'Admin', 'Three');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
User::factory()->create([
|
||||
'id' => 102,
|
||||
'firstname' => 'Flat',
|
||||
'lastname' => 'Teacher',
|
||||
'email' => 'flat@test.com',
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
[
|
||||
'class_section_id' => 12,
|
||||
'class_section_name' => 'Grade 7A',
|
||||
'class_id' => 7,
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('teacher_class')->insert([
|
||||
'class_section_id' => 12,
|
||||
'teacher_id' => 102,
|
||||
'position' => 'main',
|
||||
'school_year' => '2025-2026',
|
||||
'semester' => 'Fall',
|
||||
]);
|
||||
|
||||
$payload = [
|
||||
'notify' => [102],
|
||||
'missing_items' => [
|
||||
102 => ['midterm scores', 'attendance'],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->postJson('/api/v1/administrator/teacher-submissions/notify', $payload);
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'sent' => 1,
|
||||
'failed' => 0,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('teacher_submission_notification_history', [
|
||||
'teacher_id' => 102,
|
||||
'class_section_id' => 12,
|
||||
'admin_id' => 902,
|
||||
'notification_category' => 'teacher_submissions',
|
||||
'status' => 'sent',
|
||||
]);
|
||||
}
|
||||
|
||||
private function seedAdminUser(string $email, ?int $id = null, string $firstname = 'Admin', string $lastname = 'User'): User
|
||||
{
|
||||
$roleId = DB::table('roles')->insertGetId([
|
||||
'name' => 'administrator',
|
||||
'slug' => 'administrator',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
$userId = DB::table('users')->insertGetId(array_filter([
|
||||
'id' => $id,
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'cellphone' => '5555555555',
|
||||
'email' => $email,
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'password' => bcrypt('secret'),
|
||||
'user_type' => 'primary',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Active',
|
||||
], static fn ($value) => $value !== null));
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => $userId,
|
||||
'role_id' => $roleId,
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail($userId);
|
||||
}
|
||||
}
|
||||
|
||||
+86
-10
@@ -4,7 +4,6 @@ namespace Tests\Feature\Api\Administrator;
|
||||
|
||||
use App\Models\AttendanceDay;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\ScoreComment;
|
||||
use App\Models\SemesterScore;
|
||||
use App\Models\TeacherSubmissionNotificationHistory;
|
||||
use App\Models\User;
|
||||
@@ -35,8 +34,8 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
|
||||
|
||||
public function test_teacher_submission_report_endpoint_returns_rows_summary_and_history(): void
|
||||
{
|
||||
$admin = User::factory()->create(['id' => 900, 'firstname' => 'Admin', 'lastname' => 'One']);
|
||||
Sanctum::actingAs($admin);
|
||||
$admin = $this->seedAdminUser('admin.report.one@test.com', 900, 'Admin', 'One');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
User::factory()->create([
|
||||
'id' => 100,
|
||||
@@ -114,8 +113,7 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
|
||||
'participation_score' => '9',
|
||||
]);
|
||||
|
||||
ScoreComment::unguard();
|
||||
ScoreComment::query()->create([
|
||||
DB::table('score_comments')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
@@ -123,7 +121,7 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
|
||||
'score_type' => 'midterm',
|
||||
'comment' => 'Good progress',
|
||||
]);
|
||||
ScoreComment::query()->create([
|
||||
DB::table('score_comments')->insert([
|
||||
'student_id' => 1,
|
||||
'class_section_id' => 10,
|
||||
'school_year' => '2025-2026',
|
||||
@@ -199,8 +197,8 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
|
||||
|
||||
public function test_teacher_submission_report_returns_no_students_status_for_empty_section(): void
|
||||
{
|
||||
$admin = User::factory()->create();
|
||||
Sanctum::actingAs($admin);
|
||||
$admin = $this->seedAdminUser('admin.report.empty@test.com');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
User::factory()->create([
|
||||
'id' => 200,
|
||||
@@ -246,8 +244,8 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
|
||||
|
||||
public function test_teacher_submission_report_limits_history_to_three_entries(): void
|
||||
{
|
||||
$admin = User::factory()->create(['id' => 901, 'firstname' => 'Admin', 'lastname' => 'Two']);
|
||||
Sanctum::actingAs($admin);
|
||||
$admin = $this->seedAdminUser('admin.report.two@test.com', 901, 'Admin', 'Two');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
User::factory()->create([
|
||||
'id' => 300,
|
||||
@@ -298,4 +296,82 @@ class AdministratorTeacherSubmissionReportApiTest extends TestCase
|
||||
$history = $response->json('notificationHistory.12.300');
|
||||
$this->assertCount(3, $history);
|
||||
}
|
||||
|
||||
public function test_teacher_submission_report_honors_school_year_and_semester_query_filters(): void
|
||||
{
|
||||
$admin = $this->seedAdminUser('admin.report.filters@test.com');
|
||||
Sanctum::actingAs($admin, [], 'api');
|
||||
|
||||
User::factory()->create([
|
||||
'id' => 400,
|
||||
'firstname' => 'Yearly',
|
||||
'lastname' => 'Teacher',
|
||||
'email' => 'yearly@test.com',
|
||||
]);
|
||||
|
||||
DB::table('classSection')->insert([
|
||||
[
|
||||
'class_section_id' => 20,
|
||||
'class_section_name' => 'Grade 8A',
|
||||
'class_id' => 8,
|
||||
'semester' => 'Spring',
|
||||
'school_year' => '2024-2025',
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('teacher_class')->insert([
|
||||
[
|
||||
'class_section_id' => 20,
|
||||
'teacher_id' => 400,
|
||||
'position' => 'main',
|
||||
'school_year' => '2024-2025',
|
||||
'semester' => 'Spring',
|
||||
],
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/v1/administrator/teacher-submissions?school_year=2024-2025&semester=Spring');
|
||||
|
||||
$response->assertOk()
|
||||
->assertJson([
|
||||
'semester' => 'Spring',
|
||||
'schoolYear' => '2024-2025',
|
||||
'currentSemester' => 'Fall',
|
||||
'currentSchoolYear' => '2025-2026',
|
||||
])
|
||||
->assertJsonCount(1, 'rows');
|
||||
}
|
||||
|
||||
private function seedAdminUser(string $email, ?int $id = null, string $firstname = 'Admin', string $lastname = 'User'): User
|
||||
{
|
||||
$roleId = DB::table('roles')->insertGetId([
|
||||
'name' => 'administrator',
|
||||
'slug' => 'administrator',
|
||||
'is_active' => 1,
|
||||
]);
|
||||
|
||||
$userId = DB::table('users')->insertGetId(array_filter([
|
||||
'id' => $id,
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'cellphone' => '5555555555',
|
||||
'email' => $email,
|
||||
'address_street' => '123 Main',
|
||||
'city' => 'City',
|
||||
'state' => 'ST',
|
||||
'zip' => '12345',
|
||||
'accept_school_policy' => 1,
|
||||
'password' => bcrypt('secret'),
|
||||
'user_type' => 'primary',
|
||||
'semester' => 'Fall',
|
||||
'school_year' => '2025-2026',
|
||||
'status' => 'Active',
|
||||
], static fn ($value) => $value !== null));
|
||||
|
||||
DB::table('user_roles')->insert([
|
||||
'user_id' => $userId,
|
||||
'role_id' => $roleId,
|
||||
]);
|
||||
|
||||
return User::query()->findOrFail($userId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user