[Operator] Perbaikan Laman Portal -> Mahasiswa
This commit is contained in:
@@ -118,6 +118,25 @@ trait FakesLegacyDatabase
|
||||
$table->string('nmr_ijazah')->nullable();
|
||||
$table->string('nmr_transkrip')->nullable();
|
||||
$table->date('tgl_transkrip')->nullable();
|
||||
// Biodata (halaman detail mahasiswa); nullable agar insert banyak baris di tes lain tetap jalan.
|
||||
$table->smallInteger('agama')->nullable();
|
||||
$table->smallInteger('kewarganegaraan')->nullable();
|
||||
$table->smallInteger('stat_nikah')->nullable();
|
||||
$table->smallInteger('gol_darah')->nullable();
|
||||
$table->smallInteger('pekerjaan')->nullable();
|
||||
foreach (['no_id' => 20, 'no_kk' => 20, 'nisn' => 10, 'telepon' => 35, 'kodepos' => 5, 'alamat_mhs' => 255, 'asal_alamat' => 255,
|
||||
'namaayah' => 50, 'namaibu' => 50, 'alamat_ortu' => 255, 'nama_wali' => 50, 'alamat_wali' => 50, 'namaslta' => 60,
|
||||
'npsn' => 10, 'jurslta' => 30, 'thnlulusslta' => 4, 'cip_updated' => 20] as $column => $length) {
|
||||
$table->string($column, $length)->nullable();
|
||||
}
|
||||
foreach (['pend_ayah', 'pend_ibu', 'pekerjaan_ortu', 'pekerjaan_ibu', 'penghasilan_ortu', 'tanggungan_ortu', 'pend_wali', 'pekerjaan_wali'] as $column) {
|
||||
$table->smallInteger($column)->nullable();
|
||||
}
|
||||
$table->timestamp('last_updated')->nullable();
|
||||
});
|
||||
$schema->create('t_kewarganegaraan', function (Blueprint $table) {
|
||||
$table->smallInteger('idwarganegara')->primary();
|
||||
$table->string('kewarganegaraan');
|
||||
});
|
||||
$schema->create('t_skripsi', function (Blueprint $table) {
|
||||
$table->integer('idmahasiswa');
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Operator;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Portal > Mahasiswa > Lihat: halaman detail dengan biodata lengkap yang bisa diubah per bagian (data asli DB lama).
|
||||
* Akun staf fakultas memegang prodi 21 dan 22; mahasiswa 600 milik prodi 99 di luar cakupan.
|
||||
*/
|
||||
class LegacyStudentDetailTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
$this->seedLegacyOverview();
|
||||
$this->seedBiodata();
|
||||
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
||||
->assertRedirect(route('operator.dashboard'));
|
||||
}
|
||||
|
||||
private function db(): ConnectionInterface
|
||||
{
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
private function seedBiodata(): void
|
||||
{
|
||||
$this->db()->table('xs_agama')->insert([['idagama' => 1, 'agama' => 'Islam'], ['idagama' => 2, 'agama' => 'Katolik']]);
|
||||
$this->db()->table('t_kewarganegaraan')->insert([['idwarganegara' => 0, 'kewarganegaraan' => 'Salah Mengisi / Tidak Mengisi'], ['idwarganegara' => 1, 'kewarganegaraan' => 'Indonesia Asli']]);
|
||||
$this->db()->table('t_pekerjaan')->insert([['idpekerjaan' => 0, 'pekerjaan' => '-'], ['idpekerjaan' => 4, 'pekerjaan' => 'Swasta'], ['idpekerjaan' => 5, 'pekerjaan' => 'Wiraswasta']]);
|
||||
$this->db()->table('t_tingkat_pendidikan')->insert([['idtingkat' => 0, 'tingkatpendidikan' => 'Tidak Mengisi'], ['idtingkat' => 3, 'tingkatpendidikan' => 'SMA (Sekolah Menengah Atas)'], ['idtingkat' => 8, 'tingkatpendidikan' => 'Sarjana / S1']]);
|
||||
$this->db()->table('t_penghasilan')->insert([['idpenghasilan' => 0, 'kodepenghasilan' => '0', 'penghasilan' => 'Salah mengisi'], ['idpenghasilan' => 4, 'kodepenghasilan' => '4', 'penghasilan' => 'Rp. 1 Juta - Rp 2.5 Juta']]);
|
||||
$this->db()->table('t_pegawai')->insert(['idpegawai' => 55, 'nip' => '198712122012122055', 'nama' => 'Siti Aminah', 'gelardepan' => 'Dr.', 'gelarbelakang' => 'M.T.']);
|
||||
$this->db()->table('t_kurikulum')->insertOrIgnore(['idkurikulum' => 900, 'idprogdi' => 21, 'idprogram' => 1, 'namakurikulum' => 'Kurikulum 2020']);
|
||||
|
||||
$this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->update([
|
||||
'idprogram' => 1, 'jalur_masuk' => 1, 'idkurikulum' => 900, 'idpa' => 55, 'kelamin' => 2, 'tmplahir' => 'Pontianak', 'tgllahir' => '2001-09-22',
|
||||
'agama' => 1, 'kewarganegaraan' => 1, 'stat_nikah' => 1, 'gol_darah' => 2, 'no_id' => '6171000000000001', 'hp' => '081200000000',
|
||||
'alamat_mhs' => 'Jl. Ahmad Yani No. 1', 'namaayah' => 'Budi Santoso', 'pend_ayah' => 3, 'pekerjaan_ortu' => 4, 'namaibu' => 'Sri Wahyuni',
|
||||
'namaslta' => 'SMAN 1 Pontianak', 'thnlulusslta' => '2019',
|
||||
]);
|
||||
$this->db()->table('t_mahasiswa')->insert(['idmahasiswa' => 600, 'nim' => 'X600', 'nama' => 'Mahasiswa Luar', 'idprogdi' => 99, 'idangkatan' => 150]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function pribadi(array $override = []): array
|
||||
{
|
||||
return $override + [
|
||||
'nama' => 'Rina Lestari', 'kelamin' => 2, 'tmplahir' => 'Pontianak', 'tgllahir' => '2001-09-22', 'agama' => 1, 'kewarganegaraan' => 1,
|
||||
'stat_nikah' => 1, 'gol_darah' => 2, 'pekerjaan' => 0, 'no_id' => '6171000000000001', 'no_kk' => null, 'nisn' => null,
|
||||
];
|
||||
}
|
||||
|
||||
private function save(int $id, string $section, array $input)
|
||||
{
|
||||
return $this->putJson(route('operator.list-mahasiswa.biodata', [$id, $section]), $input);
|
||||
}
|
||||
|
||||
public function test_guests_and_other_roles_are_kept_out(): void
|
||||
{
|
||||
$this->post(route('logout'));
|
||||
$this->get(route('operator.list-mahasiswa.show', 500))->assertRedirect(route('login'));
|
||||
$this->put(route('operator.list-mahasiswa.biodata', [500, 'pribadi']))->assertRedirect(route('login'));
|
||||
|
||||
Auth::forgetGuards();
|
||||
config(['auth.guards.web.provider' => 'users']);
|
||||
$this->actingAs(User::factory()->dosen()->create());
|
||||
$this->get(route('operator.list-mahasiswa.show', 500))->assertForbidden();
|
||||
$this->save(500, 'pribadi', $this->pribadi(['nama' => 'Diubah']))->assertForbidden();
|
||||
$this->assertSame('Rina Lestari', $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->value('nama'));
|
||||
}
|
||||
|
||||
public function test_demo_operator_has_no_detail_page(): void
|
||||
{
|
||||
$this->post(route('logout'));
|
||||
Auth::forgetGuards();
|
||||
config(['auth.guards.web.provider' => 'users']);
|
||||
$this->actingAs(User::factory()->operator()->create());
|
||||
|
||||
$this->get(route('operator.list-mahasiswa.show', 500))->assertNotFound();
|
||||
$this->save(500, 'pribadi', $this->pribadi())->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_list_links_view_action_to_the_detail_page(): void
|
||||
{
|
||||
$this->get(route('operator.halaman', 'list_mahasiswa'))->assertOk()
|
||||
->assertSee('link(row)', false)
|
||||
->assertDontSee('startView(row)', false)
|
||||
->assertDontSee('Detail mahasiswa');
|
||||
}
|
||||
|
||||
public function test_detail_page_shows_the_full_biodata(): void
|
||||
{
|
||||
$this->get(route('operator.list-mahasiswa.show', 500))->assertOk()
|
||||
->assertSeeInOrder(['<h1', 'Detail Mahasiswa'], false)
|
||||
->assertSee('studentBiodata', false)
|
||||
->assertSee('Rina Lestari')->assertSee('D1041191001')->assertSee('Teknik Informatika')
|
||||
// Bagian dan isiannya
|
||||
->assertSee('Data pribadi')->assertSee('Kontak dan alamat')->assertSee('Orang tua')->assertSee('Wali')->assertSee('Asal sekolah')->assertSee('Data akademik')
|
||||
->assertSee('Tempat lahir')->assertSee('Pontianak')->assertSee('22 September 2001')->assertSee('Islam')->assertSee('Indonesia Asli')
|
||||
->assertSee('Budi Santoso')->assertSee('SMA (Sekolah Menengah Atas)')->assertSee('Swasta')->assertSee('SMAN 1 Pontianak')
|
||||
->assertSee('Jl. Ahmad Yani No. 1')
|
||||
// Data akademik: isian yang bisa diubah dan keterangan yang hanya dibaca
|
||||
->assertSee('Kurikulum 2020')->assertSee('SNMPTN')->assertSee('Reguler A')->assertSee('Dr. Siti Aminah')
|
||||
->assertSee('Masih kuliah')->assertSee('Jalur masuk')->assertSee('Dosen pembimbing akademik')
|
||||
->assertSee('x-on:submit.prevent="save()"', false);
|
||||
}
|
||||
|
||||
public function test_academic_section_is_editable_here_and_nowhere_else(): void
|
||||
{
|
||||
foreach (['store', 'update', 'destroy'] as $name) {
|
||||
$this->assertFalse(Route::has('operator.list-mahasiswa.'.$name), "Rute {$name} sudah dihapus.");
|
||||
}
|
||||
|
||||
$this->save(500, 'akademik', ['prodi' => 21, 'kurikulum' => 900, 'angkatan' => 160, 'program' => 2, 'jalur' => 3, 'status' => 3])
|
||||
->assertOk()->assertJsonPath('reload', true)->assertJsonPath('message', 'Data akademik diperbarui.')
|
||||
->assertSessionHas('status', 'Data akademik diperbarui.');
|
||||
|
||||
$row = $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->first();
|
||||
$this->assertSame([160, 2, 3, 3, 21, 900], [(int) $row->idangkatan, (int) $row->idprogram, (int) $row->jalur_masuk, (int) $row->stataktif, (int) $row->idprogdi, (int) $row->idkurikulum]);
|
||||
$this->assertSame(['SIAKAD', '198001012005011'], [$row->cname, $row->uname]);
|
||||
// NIM dan biodata tidak ikut berubah.
|
||||
$this->assertSame(['D1041191001', 'Rina Lestari', 'Pontianak'], [$row->nim, $row->nama, $row->tmplahir]);
|
||||
|
||||
$this->get(route('operator.list-mahasiswa.show', 500))->assertOk()->assertSee('Mengundurkan diri')->assertSee('MANDIRI')->assertSee('Reguler B');
|
||||
}
|
||||
|
||||
public function test_academic_section_is_validated_and_scoped(): void
|
||||
{
|
||||
$valid = ['prodi' => 21, 'kurikulum' => 900, 'angkatan' => 160, 'program' => 1, 'jalur' => 1, 'status' => 1];
|
||||
$this->save(500, 'akademik', [])->assertStatus(422)->assertJsonValidationErrors(['prodi', 'kurikulum', 'angkatan', 'program', 'status']);
|
||||
$this->save(500, 'akademik', ['status' => 9] + $valid)->assertStatus(422)->assertJsonValidationErrors(['status']);
|
||||
|
||||
foreach ([
|
||||
[['prodi' => 99], 'Program studi harus dipilih dari program studi Anda.'],
|
||||
[['kurikulum' => 999], 'Kurikulum harus dipilih dari program studi mahasiswa.'],
|
||||
[['angkatan' => 9999], 'Angkatan tidak ditemukan.'],
|
||||
[['program' => 9], 'Program kuliah tidak ditemukan.'],
|
||||
[['jalur' => 9], 'Jalur masuk tidak ditemukan.'],
|
||||
[['status' => 2], 'Status Lulus ditetapkan lewat yudisium, bukan di sini.'],
|
||||
] as [$override, $message]) {
|
||||
$this->save(500, 'akademik', $override + $valid)->assertStatus(422)->assertJsonPath('message', $message);
|
||||
}
|
||||
|
||||
$this->save(600, 'akademik', $valid)->assertNotFound();
|
||||
$this->assertSame([1, 150], [(int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->value('stataktif'), (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->value('idangkatan')]);
|
||||
}
|
||||
|
||||
public function test_detail_of_other_programs_or_unknown_students_is_not_found(): void
|
||||
{
|
||||
$this->get(route('operator.list-mahasiswa.show', 600))->assertNotFound();
|
||||
$this->get(route('operator.list-mahasiswa.show', 99999))->assertNotFound();
|
||||
$this->save(600, 'pribadi', $this->pribadi(['nama' => 'Diretas']))->assertNotFound();
|
||||
$this->save(500, 'rahasia', $this->pribadi())->assertNotFound();
|
||||
$this->assertSame('Mahasiswa Luar', $this->db()->table('t_mahasiswa')->where('idmahasiswa', 600)->value('nama'));
|
||||
}
|
||||
|
||||
public function test_saving_a_section_writes_only_changed_columns(): void
|
||||
{
|
||||
$response = $this->save(500, 'pribadi', $this->pribadi(['nama' => 'Rina Lestari Putri', 'tmplahir' => 'Sambas', 'agama' => 2, 'gol_darah' => 3, 'pekerjaan' => 4, 'nisn' => '0012345678']))
|
||||
->assertOk()->assertJsonPath('message', 'Biodata diperbarui.');
|
||||
|
||||
$row = $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->first();
|
||||
$this->assertSame(['Rina Lestari Putri', 'Sambas', 2, 3, 4, '0012345678'], [$row->nama, $row->tmplahir, (int) $row->agama, (int) $row->gol_darah, (int) $row->pekerjaan, $row->nisn]);
|
||||
// Kolom yang tidak berubah dibiarkan: kolom kosong tidak ikut ditulis 0 atau string kosong.
|
||||
$this->assertNull($row->no_kk);
|
||||
$this->assertSame('6171000000000001', $row->no_id);
|
||||
$this->assertSame(['SIAKAD', '198001012005011'], [$row->cname, $row->uname]);
|
||||
$this->assertNotNull($row->last_updated);
|
||||
|
||||
$response->assertJsonPath('display.nama', 'Rina Lestari Putri')->assertJsonPath('display.agama', 'Katolik')
|
||||
->assertJsonPath('display.tgllahir', '22 September 2001')->assertJsonPath('display.no_kk', '–')
|
||||
->assertJsonPath('values.agama', 2)->assertJsonPath('values.pekerjaan', 4);
|
||||
}
|
||||
|
||||
public function test_saving_without_changes_touches_nothing(): void
|
||||
{
|
||||
$before = $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->first();
|
||||
|
||||
$this->save(500, 'pribadi', $this->pribadi())->assertOk()->assertJsonPath('message', 'Tidak ada perubahan.');
|
||||
|
||||
$this->assertEquals($before, $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->first());
|
||||
}
|
||||
|
||||
public function test_each_section_can_be_saved(): void
|
||||
{
|
||||
$this->save(500, 'kontak', ['hp' => '081299999999', 'telepon' => null, 'email_mhs' => 'rina@student.untan.ac.id', 'kodepos' => '78124', 'alamat_mhs' => "Jl. Baru\nBlok C", 'asal_alamat' => null])->assertOk();
|
||||
$this->save(500, 'ortu', ['namaayah' => 'Budi S.', 'pend_ayah' => 8, 'pekerjaan_ortu' => 5, 'namaibu' => 'Sri W.', 'pend_ibu' => 3, 'pekerjaan_ibu' => 4, 'penghasilan_ortu' => 4, 'tanggungan_ortu' => 3, 'alamat_ortu' => 'Sambas'])->assertOk();
|
||||
$this->save(500, 'wali', ['nama_wali' => 'Paman', 'pend_wali' => 8, 'pekerjaan_wali' => 5, 'alamat_wali' => 'Singkawang'])->assertOk();
|
||||
$this->save(500, 'sekolah', ['namaslta' => 'SMAN 2', 'npsn' => '30100001', 'jurslta' => 'IPA', 'thnlulusslta' => '2020'])->assertOk();
|
||||
|
||||
$row = $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->first();
|
||||
$this->assertSame(['rina@student.untan.ac.id', '78124', "Jl. Baru\nBlok C"], [$row->email_mhs, $row->kodepos, $row->alamat_mhs]);
|
||||
$this->assertSame(['Budi S.', 8, 5, 'Sri W.', 3, 4, 4, 3], [$row->namaayah, (int) $row->pend_ayah, (int) $row->pekerjaan_ortu, $row->namaibu, (int) $row->pend_ibu, (int) $row->pekerjaan_ibu, (int) $row->penghasilan_ortu, (int) $row->tanggungan_ortu]);
|
||||
$this->assertSame(['Paman', 8, 5, 'Singkawang'], [$row->nama_wali, (int) $row->pend_wali, (int) $row->pekerjaan_wali, $row->alamat_wali]);
|
||||
$this->assertSame(['SMAN 2', '30100001', 'IPA', '2020'], [$row->namaslta, $row->npsn, $row->jurslta, $row->thnlulusslta]);
|
||||
// Bagian lain tidak terpengaruh.
|
||||
$this->assertSame(['Rina Lestari', 'Pontianak'], [$row->nama, $row->tmplahir]);
|
||||
|
||||
// Mengosongkan teks menjadi null.
|
||||
$this->save(500, 'sekolah', ['namaslta' => '', 'npsn' => '30100001', 'jurslta' => 'IPA', 'thnlulusslta' => '2020'])->assertOk();
|
||||
$this->assertNull($this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->value('namaslta'));
|
||||
}
|
||||
|
||||
public function test_input_is_validated(): void
|
||||
{
|
||||
$this->save(500, 'pribadi', [])->assertStatus(422)->assertJsonValidationErrors(['nama', 'kelamin', 'stat_nikah']);
|
||||
$this->save(500, 'pribadi', $this->pribadi(['nama' => str_repeat('A', 51)]))->assertStatus(422)->assertJsonValidationErrors(['nama']);
|
||||
$this->save(500, 'pribadi', $this->pribadi(['tgllahir' => 'kemarin', 'agama' => 9, 'kelamin' => 7]))->assertStatus(422)->assertJsonValidationErrors(['tgllahir', 'agama', 'kelamin']);
|
||||
$this->save(500, 'pribadi', $this->pribadi(['tgllahir' => now()->addDay()->toDateString()]))->assertStatus(422)->assertJsonValidationErrors(['tgllahir']);
|
||||
$this->save(500, 'pribadi', $this->pribadi(['no_kk' => '12-34 56']))->assertStatus(422)->assertJsonValidationErrors(['no_kk']);
|
||||
$this->save(500, 'kontak', ['email_mhs' => 'bukan-email'])->assertStatus(422)->assertJsonValidationErrors(['email_mhs']);
|
||||
$this->save(500, 'ortu', ['pend_ayah' => 77, 'tanggungan_ortu' => 99])->assertStatus(422)->assertJsonValidationErrors(['pend_ayah', 'tanggungan_ortu']);
|
||||
$this->save(500, 'sekolah', ['thnlulusslta' => '20x9'])->assertStatus(422)->assertJsonValidationErrors(['thnlulusslta']);
|
||||
|
||||
$this->assertSame('Rina Lestari', $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->value('nama'));
|
||||
}
|
||||
|
||||
public function test_unchanged_legacy_values_are_not_rejected(): void
|
||||
{
|
||||
// Data lama tidak selalu seragam: NIK berspasi dan kode pendidikan di luar tabel tidak menghalangi perubahan lain.
|
||||
$this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['no_id' => '6171 0000 0000 0001']);
|
||||
$this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->update(['pend_ayah' => 55]);
|
||||
|
||||
$this->save(500, 'pribadi', $this->pribadi(['no_id' => '6171 0000 0000 0001', 'tmplahir' => 'Mempawah']))->assertOk();
|
||||
$this->assertSame('Mempawah', $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->value('tmplahir'));
|
||||
|
||||
$this->get(route('operator.list-mahasiswa.show', 500))->assertOk()->assertSee('Kode 55');
|
||||
$this->save(500, 'ortu', ['namaayah' => 'Budi S.', 'pend_ayah' => 55])->assertOk();
|
||||
$this->assertSame(55, (int) $this->db()->table('t_mahasiswa')->where('idmahasiswa', 500)->value('pend_ayah'));
|
||||
}
|
||||
}
|
||||
@@ -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'));
|
||||
|
||||
@@ -61,16 +61,18 @@ class LegacyStudentListTest extends TestCase
|
||||
|
||||
// Kolom dan filter sama dengan halaman SATU list_mahasiswa.
|
||||
$headers = array_map(fn ($th): string => $this->textOf($th), iterator_to_array($xpath->query("{$panel}//thead/tr/th")));
|
||||
$this->assertSame(['', 'NIM', 'Nama', 'Jenjang', 'Program Studi', 'Masuk', 'Status', 'Smt', 'SKS', 'IPK', 'Aksi'], $headers);
|
||||
$this->assertSame(['NIM', 'Nama', 'Jenjang', 'Program Studi', 'Masuk', 'Status', 'Smt', 'SKS', 'IPK', 'Aksi'], $headers, 'Tanpa kotak centang: tidak ada aksi massal.');
|
||||
$labels = array_map(fn ($label): string => $this->textOf($label), iterator_to_array($xpath->query("//section[@aria-label='Filter data']//label")));
|
||||
$this->assertSame(['Unit / Program Studi', 'Angkatan', 'Status Mahasiswa', 'Sistem Kuliah', 'Jalur Pendaftaran'], $labels);
|
||||
|
||||
foreach (['Tambah', 'Hapus', 'Cetak'] as $label) {
|
||||
$this->assertSame(1, $xpath->query("{$panel}//div[contains(@class, 'satu-bar__tools')]//button[normalize-space()='{$label}']")->length, "Tombol {$label}");
|
||||
}
|
||||
foreach (['Lihat', 'Ubah', 'Hapus'] as $label) {
|
||||
$this->assertSame(1, $xpath->query("{$panel}//tbody/template//button[@aria-label='{$label}']")->length, "Aksi baris {$label}");
|
||||
// Daftar hanya untuk melihat: tanpa Tambah, Hapus, Cetak di bilah, dan tanpa Ubah/Hapus di baris.
|
||||
$this->assertSame(0, $xpath->query("{$panel}//div[contains(@class, 'satu-bar__tools')]//button")->length, 'Bilah tanpa tombol.');
|
||||
foreach (['Ubah', 'Hapus'] as $label) {
|
||||
$this->assertSame(0, $xpath->query("{$panel}//tbody/template//button[@aria-label='{$label}']")->length, "Tanpa aksi baris {$label}");
|
||||
}
|
||||
$response->assertDontSee('startInsert()', false)->assertDontSee('startEdit(row)', false)->assertDontSee('askRemove', false)->assertDontSee('window.print()', false);
|
||||
// Lihat membuka halaman detail mahasiswa (tautan), bukan modal.
|
||||
$this->assertSame(1, $xpath->query("{$panel}//tbody/template//a[@aria-label='Lihat']")->length, 'Aksi baris Lihat');
|
||||
$this->assertSame(1, $xpath->query("//nav[@aria-label='Halaman data']")->length);
|
||||
|
||||
// Tidak ada formulir: filter dan halaman tidak mengubah alamat halaman.
|
||||
|
||||
Reference in New Issue
Block a user