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 { use FakesLegacyDatabase; use RefreshDatabase; protected function setUp(): void { parent::setUp(); $this->useLegacyDatabase(); $this->seedLegacyOverview(); $this->seedLegacyEmployees(); $this->seedLegacyCurriculum(); $this->seedLegacyPortal(); $this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf']) ->assertRedirect(route('operator.dashboard')); } private function db(): ConnectionInterface { return DB::connection('untan'); } /** @return array */ private function employee(array $override = []): array { return $override + [ 'nip' => '199201012020121001', 'nama' => 'Hendra Saputra', 'gelardepan' => 'Dr.', 'gelarbelakang' => 'M.Kom.', 'kelamin' => 1, 'nidn' => '0001019201', 'hp' => '08111111', 'telepon' => '0561-7777', 'email' => 'hendra@untan.ac.id', 'status' => 2, 'aktif' => 1, ]; } public function test_guests_and_other_roles_cannot_write(): void { $this->post(route('logout')); 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()->mahasiswa()->create())->put(route('operator.list-pegawai.update', 11), $this->employee())->assertForbidden(); } public function test_pages_wire_the_real_buttons(): void { $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_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')); $this->assertSame( ['nip' => '197501012000031002', 'nama' => 'Siti Aminah', 'gelardepan' => '', 'gelarbelakang' => 'M.Pd.', 'kelamin' => 2, 'nidn' => '0001017501', 'hp' => '081234567890', 'telepon' => '', 'email' => 'siti@untan.ac.id', 'status' => 2, 'aktif' => 1], $rows->firstWhere('id', 11)['form'], ); $this->assertSame(0, $rows->firstWhere('id', 20)['form']['aktif']); $this->assertFalse(Route::has('operator.list-pegawai.store')); } public function test_employee_update_is_scoped_and_keeps_activity_code(): void { $url = fn (int $id): string => route('operator.list-pegawai.update', $id); $this->putJson($url(11), $this->employee(['nip' => '197501012000031002', 'nama' => 'Siti Aminah Baru', 'nidn' => '', 'status' => null])) ->assertOk()->assertJsonPath('message', 'Data pegawai diperbarui.'); $p = $this->db()->table('t_pegawai')->where('idpegawai', 11)->first(); $this->assertSame(['Siti Aminah Baru', null, null, 'M.Kom.'], [$p->nama, $p->nidn, $p->idstatuspegawai, $p->gelarbelakang]); $this->assertSame(21, (int) $this->db()->table('t_dosen')->where('idpegawai', 11)->value('idprogdi')); // Kode aktif lain (3) dipertahankan saat tetap aktif; Tidak aktif menjadi 0; aktif kembali menjadi 1. $this->putJson($url(24), $this->employee(['nip' => 'lina']))->assertOk(); $this->assertSame(3, (int) $this->db()->table('t_pegawai')->where('idpegawai', 24)->value('statusaktif')); $this->putJson($url(24), $this->employee(['nip' => 'lina', 'aktif' => 0]))->assertOk(); $this->assertSame(0, (int) $this->db()->table('t_pegawai')->where('idpegawai', 24)->value('statusaktif')); $this->putJson($url(24), $this->employee(['nip' => 'lina', 'aktif' => 1]))->assertOk(); $this->assertSame(1, (int) $this->db()->table('t_pegawai')->where('idpegawai', 24)->value('statusaktif')); $this->putJson($url(21), $this->employee(['nip' => '197501012000031002']))->assertStatus(422)->assertJsonPath('message', 'NIP 197501012000031002 sudah terdaftar.'); // Pegawai di luar cakupan (home base prodi 99, jabatan tidak aktif) dan ID tidak ada. $this->putJson($url(22), $this->employee(['nip' => '197001012000011099']))->assertStatus(422)->assertJsonPath('message', 'Pegawai tidak ditemukan.'); $this->putJson($url(23), $this->employee(['nip' => '196501011990011023']))->assertStatus(422)->assertJsonPath('message', 'Pegawai tidak ditemukan.'); $this->putJson($url(9999), $this->employee())->assertStatus(422)->assertJsonPath('message', 'Pegawai tidak ditemukan.'); $this->assertSame('Joko Prodi Lain', $this->db()->table('t_pegawai')->where('idpegawai', 22)->value('nama')); } public function test_employee_delete_only_when_unreferenced(): void { $url = route('operator.list-pegawai.destroy'); $new = 30; $this->db()->table('t_pegawai')->insert(['idpegawai' => $new, 'nip' => '199201012020121001', 'nama' => 'Hendra Saputra']); $this->db()->table('t_dosen')->insert(['idpegawai' => $new, 'idprogdi' => 21]); // 11 membimbing mahasiswa (idpa), 21 memegang jabatan aktif: ditolak, baris yang boleh ikut batal. $this->postJson($url, ['ids' => [$new, 11]])->assertStatus(422)->assertJsonPath('message', 'Pegawai Siti Aminah masih dirujuk jabatan, jadwal, bimbingan, skripsi, atau akun login sehingga tidak boleh dihapus.'); $this->assertSame(1, $this->db()->table('t_pegawai')->where('idpegawai', $new)->count()); $this->postJson($url, ['ids' => [21]])->assertStatus(422); $this->db()->table('t_account')->insert(['iduser' => 901, 'username' => 'p', 'passwd' => 'q', 'identitas' => 24, 'jenis' => 0]); $this->postJson($url, ['ids' => [24]])->assertStatus(422); $this->assertSame(3, $this->db()->table('t_pegawai')->whereIn('idpegawai', [11, 21, 24])->count()); // Di luar cakupan atau tidak ada. $this->postJson($url, ['ids' => [22, 9999]])->assertStatus(422)->assertJsonPath('message', 'Pegawai tidak ditemukan.'); $this->assertSame(1, $this->db()->table('t_pegawai')->where('idpegawai', 22)->count()); $this->postJson($url, [])->assertStatus(422)->assertJsonValidationErrors('ids'); $this->postJson($url, ['ids' => [$new]])->assertOk()->assertJsonPath('message', '1 pegawai dihapus.'); $this->assertSame(0, $this->db()->table('t_pegawai')->where('idpegawai', $new)->count()); $this->assertSame(0, $this->db()->table('t_dosen')->where('idpegawai', $new)->count()); } }