[Operator] Perbaikan Periode Aktif Kuliah per Prodi
This commit is contained in:
@@ -384,6 +384,10 @@ trait FakesLegacyDatabase
|
||||
$schema->create('t_periodekuliahaktif', function (Blueprint $table) {
|
||||
$table->integer('idprogdi');
|
||||
$table->integer('idperiode');
|
||||
$table->string('cname')->nullable();
|
||||
$table->string('cip')->nullable();
|
||||
$table->string('uname')->nullable();
|
||||
$table->timestamp('tanggal')->nullable();
|
||||
});
|
||||
$schema->create('t_periodelirs', function (Blueprint $table) {
|
||||
$table->increments('idperiodelirs');
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature\Operator;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Perkuliahan > Data Kelas > Periode Kuliah Aktif dari DB lama: periode aktif tiap prodi akun (t_periodekuliahaktif),
|
||||
* ubah per prodi seperti Setup Periode Kuliah Aktif SIAKAD lama yang dibatasi unit akun.
|
||||
*/
|
||||
class LegacyPeriodeAktifTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
use InspectsHtml;
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->useLegacyDatabase();
|
||||
$this->seedLegacyOverview();
|
||||
// Prodi di luar unit akun dengan periode aktif lama: tidak tampil dan tidak boleh diubah.
|
||||
DB::connection('untan')->table('t_bagian')->insert(['idbagian' => 23, 'idbagian_induk' => 5, 'idjenisbagian' => 3, 'namabagian' => 'Prodi Lain']);
|
||||
DB::connection('untan')->table('t_periodekuliahaktif')->insert(['idprogdi' => 23, 'idperiode' => 365]);
|
||||
}
|
||||
|
||||
private function login(): void
|
||||
{
|
||||
$this->post(route('login.store'), ['username' => '198001012005011001', 'password' => 'rahasia-staf'])
|
||||
->assertRedirect(route('operator.dashboard'));
|
||||
}
|
||||
|
||||
/** @return list<array{0: int, 1: string, 2: string, 3: string, 4: int|string}> */
|
||||
private function rows(array $query = []): array
|
||||
{
|
||||
return array_map(
|
||||
fn (array $r): array => [$r['id'], $r['prodi'], $r['periode'], $r['kode'], $r['form']['periode']],
|
||||
$this->getJson(route('operator.periode-aktif.data', $query))->assertOk()->json('rows'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_daftar_periode_aktif_prodi_akun(): void
|
||||
{
|
||||
$this->login();
|
||||
$page = $this->get(route('operator.halaman', 'set_periodeaktif'))->assertOk()
|
||||
->assertSee('Periode kuliah aktif asli')->assertSee('Ubah periode kuliah aktif');
|
||||
$this->assertSame(
|
||||
['Program Studi', 'Periode Aktif', 'Kode', 'Diperbarui', 'Oleh', 'Aksi'],
|
||||
array_map(fn ($th): string => $this->textOf($th), iterator_to_array($this->dom($page)->query("//*[@aria-label='Daftar Periode Kuliah Aktif']//thead/tr/th"))),
|
||||
);
|
||||
$this->assertSame(0, $this->dom($page)->query("//*[@aria-label='Daftar Periode Kuliah Aktif']//button[contains(., 'Tambah')]")->length, 'Tanpa Tambah: baris adalah prodi akun.');
|
||||
$this->assertSame(1, $this->dom($page)->query("//dialog//select[@name='form_periode']/option[@value='371']")->length, 'Pilihan periode di modal.');
|
||||
|
||||
$this->assertSame([
|
||||
[21, 'Teknik Informatika', '2020/2021 Ganjil', '20201', 368],
|
||||
[22, 'Teknik Sipil', '2020/2021 Ganjil', '20201', 368],
|
||||
], $this->rows(), 'Hanya prodi akun; prodi 23 tidak tampil.');
|
||||
$this->assertSame([[22, 'Teknik Sipil', '2020/2021 Ganjil', '20201', 368]], $this->rows(['q' => 'sipil']));
|
||||
}
|
||||
|
||||
public function test_ubah_periode_aktif_prodi_sendiri(): void
|
||||
{
|
||||
$this->login();
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$this->putJson(route('operator.periode-aktif.update', 21), ['periode' => 371])
|
||||
->assertOk()->assertJsonPath('message', 'Periode aktif Teknik Informatika diperbarui.');
|
||||
$row = $db->table('t_periodekuliahaktif')->where('idprogdi', 21)->first();
|
||||
$this->assertSame(371, (int) $row->idperiode);
|
||||
$this->assertSame('SIAKAD', $row->cname);
|
||||
$this->assertSame('198001012005011', $row->uname, 'uname dipotong 15 karakter seperti aplikasi lama.');
|
||||
$this->assertNotNull($row->tanggal);
|
||||
$this->assertSame(368, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 22)->value('idperiode'), 'Prodi lain tidak berubah.');
|
||||
$this->assertSame([21, 'Teknik Informatika', '2020/2021 Genap', '20202', 371], $this->rows()[0]);
|
||||
|
||||
// Prodi akun tanpa baris aktif tampil "–" dan disisipkan saat diubah (periode pendek juga boleh).
|
||||
$db->table('t_periodekuliahaktif')->where('idprogdi', 22)->delete();
|
||||
$this->assertSame([22, 'Teknik Sipil', '–', '–', ''], $this->rows()[1]);
|
||||
$this->putJson(route('operator.periode-aktif.update', 22), ['periode' => 366])->assertOk();
|
||||
$this->assertSame(366, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 22)->value('idperiode'));
|
||||
$this->assertSame([22, 'Teknik Sipil', '2019/2020 Genap (pendek)', '20193', 366], $this->rows()[1]);
|
||||
}
|
||||
|
||||
public function test_tolak_prodi_lain_dan_periode_tidak_dikenal(): void
|
||||
{
|
||||
$this->login();
|
||||
$db = DB::connection('untan');
|
||||
|
||||
$this->putJson(route('operator.periode-aktif.update', 23), ['periode' => 371])->assertNotFound();
|
||||
$this->assertSame(365, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 23)->value('idperiode'), 'Prodi di luar unit akun tidak tersentuh.');
|
||||
$this->putJson(route('operator.periode-aktif.update', 21), ['periode' => 999])->assertStatus(422)->assertJsonPath('message', 'Periode tidak ditemukan.');
|
||||
$this->putJson(route('operator.periode-aktif.update', 21), [])->assertStatus(422);
|
||||
$this->assertSame(368, (int) $db->table('t_periodekuliahaktif')->where('idprogdi', 21)->value('idperiode'));
|
||||
}
|
||||
|
||||
public function test_akun_demo_role_lain_dan_tamu(): void
|
||||
{
|
||||
$this->get(route('operator.halaman', 'set_periodeaktif'))->assertRedirect(route('login'));
|
||||
$this->actingAs(User::factory()->operator()->create())->getJson(route('operator.periode-aktif.data'))->assertNotFound();
|
||||
$this->actingAs(User::factory()->dosen()->create())->getJson(route('operator.periode-aktif.data'))->assertForbidden();
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use Tests\Concerns\FakesLegacyDatabase;
|
||||
use Tests\Concerns\InspectsHtml;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** Periode Akademik (hanya Superuser) dari DB lama: daftar t_periodekuliah (aktif = aktif di setidaknya satu prodi), tambah, ubah, hapus. */
|
||||
/** Periode Akademik (hanya Superuser) dari DB lama: daftar t_periodekuliah (aktif = satu periode berjalan universitas), tambah, ubah, hapus. */
|
||||
class LegacyPeriodeAkademikTest extends TestCase
|
||||
{
|
||||
use FakesLegacyDatabase;
|
||||
@@ -25,6 +25,9 @@ class LegacyPeriodeAkademikTest extends TestCase
|
||||
$this->seedLegacyOverview();
|
||||
DB::connection('untan')->table('t_periodekuliah')->where('idperiode', 371)->update(['mulai' => '2021-02-01', 'selesai' => '2021-07-31']);
|
||||
DB::connection('untan')->table('t_angkatanmhs')->insert(['idangkatan' => 990, 'tahun' => 2024, 'semester' => 1]);
|
||||
// Prodi lama yang masih menunjuk periode sebelumnya tidak boleh membuat periode itu tampil "Ya".
|
||||
DB::connection('untan')->table('t_bagian')->insert(['idbagian' => 23, 'idbagian_induk' => 5, 'idjenisbagian' => 3, 'namabagian' => 'Prodi Lama']);
|
||||
DB::connection('untan')->table('t_periodekuliahaktif')->insert(['idprogdi' => 23, 'idperiode' => 365]);
|
||||
$this->post(route('login.store'), ['username' => '197001011995011001', 'password' => 'rahasia-super'])
|
||||
->assertRedirect(route('superuser.dashboard'));
|
||||
}
|
||||
@@ -46,7 +49,7 @@ class LegacyPeriodeAkademikTest extends TestCase
|
||||
['20201', '2020/2021 Ganjil', '–', '–', 'Ya'],
|
||||
['20193', '2019/2020 Genap (pendek)', '–', '–', 'Tidak'],
|
||||
['20192', '2019/2020 Genap', '–', '–', 'Tidak'],
|
||||
], $this->rows($this->getJson(route('superuser.periode.data'))->assertOk()->json()), 'Ya = periode aktif di setidaknya satu prodi.');
|
||||
], $this->rows($this->getJson(route('superuser.periode.data'))->assertOk()->json()), 'Ya hanya periode berjalan universitas; 2019/2020 Genap milik prodi lama tetap Tidak.');
|
||||
}
|
||||
|
||||
public function test_tambah_ubah_hapus(): void
|
||||
|
||||
Reference in New Issue
Block a user