[Operator] Perbaikan Laman Portal -> Konsultasi
This commit is contained in:
@@ -7,13 +7,12 @@ 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;
|
||||
|
||||
/**
|
||||
* CRUD Portal > Pegawai (t_pegawai + t_dosen) berdata asli lewat modal remote-list. Portal > Mahasiswa hanya baca (ubah di
|
||||
* halaman detail: LegacyStudentDetailTest).
|
||||
* Hapus pegawai (t_pegawai + t_dosen) berdata asli di Portal > Pegawai. Tambah dan ubah: LegacyEmployeeDetailTest; 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
|
||||
@@ -39,70 +38,23 @@ class LegacyStudentEmployeeCrudTest extends TestCase
|
||||
return DB::connection('untan');
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
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'));
|
||||
}
|
||||
$this->post(route('operator.list-pegawai.destroy'))->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();
|
||||
$this->actingAs(User::factory()->mahasiswa()->create())->post(route('operator.list-pegawai.destroy'), ['ids' => [11]])->assertForbidden();
|
||||
$this->assertSame(1, $this->db()->table('t_pegawai')->where('idpegawai', 11)->count());
|
||||
}
|
||||
|
||||
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'));
|
||||
->assertSee('Hapus pegawai?')->assertSee('askRemove([row.id])', false)->assertSee('startInsert()', false)->assertSee('link(row)', false)
|
||||
->assertDontSee('startEdit(row)', false)->assertDontSee('startView(row)', false)->assertDontSee('window.print()', false)
|
||||
->assertDontSee("demo('", false)->assertDontSee('Aksi'.': tampilan prototipe');
|
||||
}
|
||||
|
||||
public function test_employee_delete_only_when_unreferenced(): void
|
||||
|
||||
Reference in New Issue
Block a user