[Operator] Perbaikan Laman Portal -> Mahasiswa

This commit is contained in:
Ariyutta
2026-11-11 08:46:29 +07:00
parent ef46b84da8
commit 52d49cdb41
15 changed files with 1153 additions and 390 deletions
@@ -12,7 +12,8 @@ use Tests\Concerns\FakesLegacyDatabase;
use Tests\TestCase;
/**
* CRUD Portal > Mahasiswa (t_mahasiswa) dan Portal > Pegawai (t_pegawai + t_dosen) berdata asli lewat modal remote-list.
* CRUD Portal > Pegawai (t_pegawai + t_dosen) berdata asli lewat modal remote-list. Portal > Mahasiswa hanya baca (ubah di
* halaman detail: LegacyStudentDetailTest).
* Akun staf fakultas memegang prodi 21 dan 22 (fakultas 5); prodi 99 di luar cakupan.
*/
class LegacyStudentEmployeeCrudTest extends TestCase
@@ -38,15 +39,6 @@ class LegacyStudentEmployeeCrudTest extends TestCase
return DB::connection('untan');
}
/** @return array<string, mixed> */
private function student(array $override = []): array
{
return $override + [
'nim' => 'd1041211001', 'nama' => 'Siti Rahma', 'prodi' => 21, 'kurikulum' => 900, 'angkatan' => 160, 'program' => 1, 'jalur' => 3,
'kelamin' => 2, 'tmplahir' => 'Pontianak', 'tgllahir' => '2003-05-17', 'hp' => '081200000000', 'email' => 'siti.rahma@student.untan.ac.id', 'status' => 1,
];
}
/** @return array<string, mixed> */
private function employee(array $override = []): array
{
@@ -56,123 +48,25 @@ class LegacyStudentEmployeeCrudTest extends TestCase
];
}
private function studentRow(int $id): ?array
{
return collect($this->getJson(route('operator.mahasiswa.data', ['per' => 25]))->assertOk()->json('rows'))->firstWhere('id', $id);
}
public function test_guests_and_other_roles_cannot_write(): void
{
$this->post(route('logout'));
foreach ([['post', route('operator.list-mahasiswa.store')], ['put', route('operator.list-mahasiswa.update', 500)], ['post', route('operator.list-mahasiswa.destroy')],
['put', route('operator.list-pegawai.update', 11)], ['post', route('operator.list-pegawai.destroy')]] as [$method, $url]) {
foreach ([['put', route('operator.list-pegawai.update', 11)], ['post', route('operator.list-pegawai.destroy')]] as [$method, $url]) {
$this->{$method}($url)->assertRedirect(route('login'));
}
Auth::forgetGuards();
config(['auth.guards.web.provider' => 'users']);
$this->actingAs(User::factory()->dosen()->create())->post(route('operator.list-mahasiswa.store'), $this->student())->assertForbidden();
$this->actingAs(User::factory()->mahasiswa()->create())->put(route('operator.list-pegawai.update', 11), $this->employee())->assertForbidden();
$this->assertSame(0, $this->db()->table('t_mahasiswa')->where('nim', 'D1041211001')->count());
}
public function test_pages_wire_the_real_buttons(): void
{
$this->get(route('operator.halaman', 'list_mahasiswa'))->assertOk()
->assertSee('startInsert()', false)->assertSee('Tambah mahasiswa')->assertSee('Program kuliah')->assertSee('Hapus mahasiswa?')
->assertDontSee("demo('Tambah')", false);
$this->get(route('operator.halaman', 'list_pegawai'))->assertOk()
->assertSee('startEdit(row)', false)->assertSee('Status kepegawaian')->assertSee('Hapus pegawai?')->assertSee('askRemove([row.id])', false)
->assertSee('startView(row)', false)->assertSee('Detail pegawai')->assertDontSee("demo('", false)->assertDontSee('Aksi'.': tampilan prototipe');
}
public function test_student_create_and_rows(): void
{
$id = $this->postJson(route('operator.list-mahasiswa.store'), $this->student())->assertCreated()->assertJsonPath('message', 'Mahasiswa ditambahkan.')->json('id');
$m = $this->db()->table('t_mahasiswa')->where('idmahasiswa', $id)->first();
$this->assertSame(['D1041211001', 'Siti Rahma', 21, 900, 160, 1, 3, 2, 1], [$m->nim, $m->nama, (int) $m->idprogdi, (int) $m->idkurikulum, (int) $m->idangkatan, (int) $m->idprogram, (int) $m->jalur_masuk, (int) $m->kelamin, (int) $m->stataktif]);
$this->assertSame(['SIAKAD', '198001012005011'], [$m->cname, $m->uname]);
$row = $this->studentRow($id);
$this->assertSame('D1041211001', $row['nim']);
$this->assertSame(
['nim' => 'D1041211001', 'nama' => 'Siti Rahma', 'prodi' => 21, 'kurikulum' => 900, 'angkatan' => 160, 'program' => 1, 'jalur' => 3, 'kelamin' => 2,
'tmplahir' => 'Pontianak', 'tgllahir' => '2003-05-17', 'hp' => '081200000000', 'email' => 'siti.rahma@student.untan.ac.id', 'status' => 1],
$row['form'],
);
// Jalur masuk boleh kosong pada tambah (bawaan 1).
$other = $this->postJson(route('operator.list-mahasiswa.store'), $this->student(['nim' => 'D1041211002', 'jalur' => null]))->assertCreated()->json('id');
$this->assertSame(1, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', $other)->value('jalur_masuk'));
}
public function test_student_create_is_validated_and_guarded(): void
{
$url = route('operator.list-mahasiswa.store');
$this->postJson($url, [])->assertStatus(422)->assertJsonValidationErrors(['nim', 'nama', 'prodi', 'kurikulum', 'angkatan', 'program', 'kelamin', 'status']);
$this->postJson($url, $this->student(['email' => 'bukan-email', 'tgllahir' => 'kemarin', 'kelamin' => 7]))->assertStatus(422)->assertJsonValidationErrors(['email', 'tgllahir', 'kelamin']);
$this->postJson($url, $this->student(['prodi' => 99, 'kurikulum' => 901]))->assertStatus(422)->assertJsonPath('message', 'Program studi harus dipilih dari program studi Anda.');
// Kurikulum prodi 22 untuk mahasiswa prodi 21 ditolak.
$this->postJson($url, $this->student(['kurikulum' => 902]))->assertStatus(422)->assertJsonPath('message', 'Kurikulum harus dipilih dari program studi mahasiswa.');
$this->postJson($url, $this->student(['angkatan' => 9999]))->assertStatus(422)->assertJsonPath('message', 'Angkatan tidak ditemukan.');
$this->postJson($url, $this->student(['program' => 9]))->assertStatus(422)->assertJsonPath('message', 'Program kuliah tidak ditemukan.');
$this->postJson($url, $this->student(['jalur' => 9]))->assertStatus(422)->assertJsonPath('message', 'Jalur masuk tidak ditemukan.');
$this->postJson($url, $this->student(['nim' => 'a b!']))->assertStatus(422)->assertJsonPath('message', 'NIM hanya boleh huruf dan angka (5 sampai 15 karakter).');
$this->postJson($url, $this->student(['nim' => 'd1041191001']))->assertStatus(422)->assertJsonPath('message', 'NIM D1041191001 sudah terdaftar.');
$this->postJson($url, $this->student(['status' => 2]))->assertStatus(422)->assertJsonPath('message', 'Status Lulus ditetapkan lewat yudisium, bukan di sini.');
$this->assertSame(0, $this->db()->table('t_mahasiswa')->where('nim', 'D1041211001')->count());
}
public function test_student_update_keeps_scope_and_nim(): void
{
$url = fn (int $id): string => route('operator.list-mahasiswa.update', $id);
$payload = $this->student(['nim' => 'X501', 'nama' => 'Nama Baru', 'prodi' => 22, 'kurikulum' => 902, 'status' => 3, 'jalur' => null]);
$this->putJson($url(501), $payload)->assertOk()->assertJsonPath('message', 'Data mahasiswa diperbarui.');
$m = $this->db()->table('t_mahasiswa')->where('idmahasiswa', 501)->first();
$this->assertSame(['Nama Baru', 22, 902, 3, 1], [$m->nama, (int) $m->idprogdi, (int) $m->idkurikulum, (int) $m->stataktif, (int) $m->jalur_masuk]);
$this->assertSame('198001012005011', $m->uname);
$this->putJson($url(502), $this->student(['nim' => 'X999']))->assertStatus(422)->assertJsonPath('message', 'NIM tidak dapat diubah. Buat mahasiswa baru dengan NIM yang sesuai.');
$this->putJson($url(502), $this->student(['nim' => 'X502', 'status' => 2]))->assertStatus(422)->assertJsonPath('message', 'Status Lulus ditetapkan lewat yudisium, bukan di sini.');
// Mahasiswa yang sudah lulus boleh disunting tanpa mengubah status.
$this->putJson($url(505), $this->student(['nim' => 'X505', 'status' => 2]))->assertOk();
// Mahasiswa prodi 99 dan ID yang tidak ada ditolak.
$this->putJson($url(600), $this->student(['nim' => 'X600']))->assertStatus(422)->assertJsonPath('message', 'Mahasiswa tidak ditemukan.');
$this->putJson($url(9999), $this->student())->assertStatus(422)->assertJsonPath('message', 'Mahasiswa tidak ditemukan.');
$this->assertSame('Mahasiswa Luar', $this->db()->table('t_mahasiswa')->where('idmahasiswa', 600)->value('nama'));
// Pindah ke prodi di luar cakupan ditolak.
$this->putJson($url(502), $this->student(['nim' => 'X502', 'prodi' => 99, 'kurikulum' => 901]))->assertStatus(422)->assertJsonPath('message', 'Program studi harus dipilih dari program studi Anda.');
}
public function test_student_delete_only_without_dependents(): void
{
$url = route('operator.list-mahasiswa.destroy');
$new = $this->postJson(route('operator.list-mahasiswa.store'), $this->student())->assertCreated()->json('id');
$this->db()->table('t_evaluasi_rekap')->insert(['idmahasiswa' => $new]);
// Punya KRS (500), akun login, atau pembayaran: ditolak, dan tidak ada yang terhapus walau dicampur baris yang boleh.
$this->postJson($url, ['ids' => [$new, 500]])->assertStatus(422)->assertJsonPath('message', 'Mahasiswa D1041191001 sudah punya data akademik, keuangan, atau akun login sehingga tidak boleh dihapus.');
$this->assertSame(1, $this->db()->table('t_mahasiswa')->where('idmahasiswa', $new)->count());
$this->db()->table('t_account')->insert(['iduser' => 900, 'username' => 'x', 'passwd' => 'y', 'identitas' => 503, 'jenis' => 1]);
$this->postJson($url, ['ids' => [503]])->assertStatus(422)->assertJsonPath('message', 'Mahasiswa X503 sudah punya data akademik, keuangan, atau akun login sehingga tidak boleh dihapus.');
$this->db()->table('t_keuanganmhs')->insert(['idmahasiswa' => 504, 'jenis' => 1, 'idperiode' => 368, 'jumlah' => 1000]);
$this->postJson($url, ['ids' => [504]])->assertStatus(422);
$this->assertSame(2, $this->db()->table('t_mahasiswa')->whereIn('idmahasiswa', [503, 504])->count());
// Di luar cakupan prodi atau tidak ada.
$this->postJson($url, ['ids' => [600]])->assertStatus(422)->assertJsonPath('message', 'Mahasiswa tidak ditemukan.');
$this->postJson($url, ['ids' => []])->assertStatus(422)->assertJsonValidationErrors('ids');
$this->assertSame(1, $this->db()->table('t_mahasiswa')->where('idmahasiswa', 600)->count());
$this->postJson($url, ['ids' => [$new]])->assertOk()->assertJsonPath('message', '1 mahasiswa dihapus.');
$this->assertSame(0, $this->db()->table('t_mahasiswa')->where('idmahasiswa', $new)->count());
$this->assertSame(0, $this->db()->table('t_evaluasi_rekap')->where('idmahasiswa', $new)->count());
}
public function test_employee_rows_carry_the_edit_form_and_have_no_create_route(): void
{
$rows = collect($this->getJson(route('operator.pegawai.data', ['per' => 25]))->assertOk()->json('rows'));