Update Kelompok Tani
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Web\Produktivitas\SurveyKelompokTaniController;
|
||||
use App\Http\Requests\Produktivitas\IndexKelompokTaniRequest;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ViewErrorBag;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
beforeEach(function () {
|
||||
@@ -27,6 +30,9 @@ beforeEach(function () {
|
||||
$table->string('nama_responden')->nullable();
|
||||
$table->integer('desa_kelurahan_id');
|
||||
$table->string('jenis_kelompok')->nullable();
|
||||
$table->string('status_legalitas')->nullable();
|
||||
$table->boolean('pernah_mendapatkan_bantuan')->nullable();
|
||||
$table->integer('created_by')->nullable();
|
||||
$table->json('komoditas_id')->nullable();
|
||||
foreach (['jumlah_pengurus', 'jumlah_pengurus_aktif', 'jumlah_anggota_terdaftar', 'jumlah_anggota_aktif'] as $field) {
|
||||
$table->integer($field)->nullable();
|
||||
@@ -34,6 +40,17 @@ beforeEach(function () {
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->softDeletes();
|
||||
});
|
||||
DB::table('users')->insert(['id' => 7, 'name' => 'Enumerator Uji']);
|
||||
$user = new User(['name' => 'Admin Uji', 'email' => 'admin@example.test', 'role' => 'admin']);
|
||||
$user->id = 7;
|
||||
$this->be($user);
|
||||
Event::forget('composing: *');
|
||||
view()->share('errors', new ViewErrorBag());
|
||||
|
||||
DB::table('master_kabupaten_kota')->insert([
|
||||
['id' => 1, 'nama' => 'Kabupaten Ngada'], ['id' => 2, 'nama' => 'Kabupaten Lain'],
|
||||
@@ -53,11 +70,11 @@ beforeEach(function () {
|
||||
['id' => 1, 'nama' => 'Kakao'], ['id' => 2, 'nama' => 'Kopi'], ['id' => 11, 'nama' => 'Vanili'],
|
||||
]);
|
||||
foreach ([
|
||||
[1, 'Alpha', 'Budi', 1, 'Poktan', ['1', '2'], 3, 2, 30, 25, null],
|
||||
[2, 'Beta', 'Siti', 2, 'KWT', [1], 5, 4, 40, 35, null],
|
||||
[3, 'Citra', 'Ani', 3, 'Poktan', [2, 11], null, null, 0, 0, null],
|
||||
[4, 'Diluar', 'Toni', 4, 'Poktan', [1], 99, 99, 900, 900, null],
|
||||
[5, 'Dihapus', 'Dewi', 1, 'Poktan', [1], 99, 99, 900, 900, '2026-01-01'],
|
||||
[1, 'Alpha', 'Budi', 1, 'Kelompok Tani (Poktan)', ['1', '2'], 3, 2, 30, 25, null],
|
||||
[2, 'Beta', 'Siti', 2, 'Kelompok Wanita Tani (KWT)', [1], 5, 4, 40, 35, null],
|
||||
[3, 'Citra', 'Ani', 3, 'Kelompok Tani (Poktan)', [2, 11], null, null, 0, 0, null],
|
||||
[4, 'Diluar', 'Toni', 4, 'Kelompok Tani (Poktan)', [1], 99, 99, 900, 900, null],
|
||||
[5, 'Dihapus', 'Dewi', 1, 'Kelompok Tani (Poktan)', [1], 99, 99, 900, 900, '2026-01-01'],
|
||||
] as [$id, $nama, $responden, $desa, $jenis, $komoditas, $pengurus, $pengurusAktif, $anggota, $anggotaAktif, $deletedAt]) {
|
||||
DB::table('survey_kelompok_tani')->insert([
|
||||
'id' => $id, 'nama_kelompok' => $nama, 'nama_responden' => $responden,
|
||||
@@ -65,12 +82,22 @@ beforeEach(function () {
|
||||
'komoditas_id' => json_encode($komoditas), 'jumlah_pengurus' => $pengurus,
|
||||
'jumlah_pengurus_aktif' => $pengurusAktif, 'jumlah_anggota_terdaftar' => $anggota,
|
||||
'jumlah_anggota_aktif' => $anggotaAktif, 'created_at' => "2026-01-0{$id}", 'deleted_at' => $deletedAt,
|
||||
'status_legalitas' => match ($id) {
|
||||
1 => 'Sudah ada SK dari desa/kecamatan',
|
||||
2 => 'Sedang proses pengajuan',
|
||||
4, 5 => 'Sudah ada SK dan terdaftar di Dinas/Kabupaten',
|
||||
default => null,
|
||||
},
|
||||
'pernah_mendapatkan_bantuan' => match ($id) { 1 => true, 2 => false, default => null },
|
||||
'created_by' => 7,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->listKelompok = function (array $filters = []) {
|
||||
$request = Request::create('/survey/kelompok-tani', 'GET', $filters);
|
||||
$request = IndexKelompokTaniRequest::create('/survey/kelompok-tani', 'GET', $filters);
|
||||
$request->setContainer($this->app)->setRedirector(app('redirect'));
|
||||
$this->app->instance('request', $request);
|
||||
$request->validateResolved();
|
||||
|
||||
return app(SurveyKelompokTaniController::class)->index($request)->getData();
|
||||
};
|
||||
@@ -86,6 +113,8 @@ test('kelompok cards summarize the default region and exclude deleted groups', f
|
||||
->and((int) $data['summary']->pengurus_aktif)->toBe(6)
|
||||
->and((int) $data['summary']->total_anggota)->toBe(70)
|
||||
->and((int) $data['summary']->anggota_aktif)->toBe(60);
|
||||
expect((int) $data['summary']->total_desa)->toBe(3);
|
||||
expect((int) $data['summary']->memiliki_sk)->toBe(1);
|
||||
expect($data['kecamatanOptions']->pluck('id')->all())->toBe([1, 2]);
|
||||
});
|
||||
|
||||
@@ -102,8 +131,8 @@ test('kelompok commodity filter matches string and numeric JSON ids exactly', fu
|
||||
$data = ($this->listKelompok)(['komoditas_id' => '1']);
|
||||
expect($data['kelompokTani']->pluck('id')->all())->toBe([2, 1]);
|
||||
expect((int) $data['summary']->total_kelompok)->toBe(2);
|
||||
expect(($this->listKelompok)(['komoditas_id' => 2, 'jenis_kelompok' => 'Poktan'])['kelompokTani']->pluck('id')->all())->toBe([3, 1]);
|
||||
expect(($this->listKelompok)(['jenis_kelompok' => 'KWT'])['kelompokTani']->pluck('id')->all())->toBe([2]);
|
||||
expect(($this->listKelompok)(['komoditas_id' => 2, 'jenis_kelompok' => 'Kelompok Tani (Poktan)'])['kelompokTani']->pluck('id')->all())->toBe([3, 1]);
|
||||
expect(($this->listKelompok)(['jenis_kelompok' => 'Kelompok Wanita Tani (KWT)'])['kelompokTani']->pluck('id')->all())->toBe([2]);
|
||||
});
|
||||
|
||||
test('kelompok search matches group and respondent names without escaping region filters', function () {
|
||||
@@ -128,7 +157,7 @@ test('kelompok totals cover every result and pagination preserves all filters',
|
||||
for ($index = 0; $index < 12; $index++) {
|
||||
DB::table('survey_kelompok_tani')->insert([
|
||||
'nama_kelompok' => 'Kelompok tambahan ' . $index, 'desa_kelurahan_id' => 1,
|
||||
'jenis_kelompok' => 'Poktan', 'komoditas_id' => '["1"]', 'jumlah_anggota_terdaftar' => 10,
|
||||
'jenis_kelompok' => 'Kelompok Tani (Poktan)', 'komoditas_id' => '["1"]', 'jumlah_anggota_terdaftar' => 10,
|
||||
]);
|
||||
}
|
||||
$data = ($this->listKelompok)(['komoditas_id' => 1, 'sort_by' => 'nama_asc', 'page' => 2, 'per_page' => '10']);
|
||||
@@ -144,4 +173,111 @@ test('kelompok filters reject malformed ids and unsupported page sizes', functio
|
||||
expect(fn () => ($this->listKelompok)($filters))->toThrow(ValidationException::class);
|
||||
})->with([
|
||||
[['kecamatan_id' => 'invalid']], [['komoditas_id' => 999]], [['per_page' => 0]], [['search' => ['invalid']]],
|
||||
[['status_legalitas' => ['invalid']]],
|
||||
]);
|
||||
|
||||
test('legal status filters keep cards and rows consistent', function () {
|
||||
$sk = ($this->listKelompok)(['status_legalitas' => 'Sudah ada SK dari desa/kecamatan']);
|
||||
expect($sk['kelompokTani']->pluck('id')->all())->toBe([1]);
|
||||
expect((int) $sk['summary']->memiliki_sk)->toBe(1);
|
||||
expect((int) $sk['summary']->total_pengurus)->toBe(3);
|
||||
$proses = ($this->listKelompok)(['status_legalitas' => 'Sedang proses pengajuan']);
|
||||
expect($proses['kelompokTani']->pluck('id')->all())->toBe([2]);
|
||||
expect((int) $proses['summary']->total_anggota)->toBe(40);
|
||||
expect((int) $proses['summary']->memiliki_sk)->toBe(0);
|
||||
});
|
||||
|
||||
test('group summaries resolve commodities locations and legal status from recorded data', function () {
|
||||
$data = ($this->listKelompok)();
|
||||
expect($data['ringkasanKelompok'][1]['komoditas'])->toBe(['Kakao', 'Kopi']);
|
||||
expect($data['ringkasanKelompok'][3]['komoditas'])->toBe(['Kopi', 'Vanili']);
|
||||
expect($data['ringkasanKelompok'][1]['lokasi'])->toBe('Desa A · Kecamatan A');
|
||||
expect($data['ringkasanKelompok'][1]['legalitas'])->toBe(['label' => 'Sudah ada SK', 'warna' => 'success']);
|
||||
expect($data['ringkasanKelompok'][3]['legalitas']['label'])->toBe('Belum terisi');
|
||||
expect($data['kelompokTani']->first()->creator->name)->toBe('Enumerator Uji');
|
||||
expect(($this->listKelompok)(['search' => 'Desa B'])['kelompokTani']->pluck('id')->all())->toBe([2]);
|
||||
expect(($this->listKelompok)(['search' => 'Kecamatan B'])['kelompokTani']->pluck('id')->all())->toBe([3]);
|
||||
});
|
||||
|
||||
test('new filters survive pagination and filtered page totals cover every matching group', function () {
|
||||
$filters = ['status_legalitas' => 'Sedang proses pengajuan', 'jenis_kelompok' => 'Kelompok Wanita Tani (KWT)', 'komoditas_id' => 1, 'sort_by' => 'anggota_desc', 'per_page' => 25];
|
||||
$data = ($this->listKelompok)($filters);
|
||||
parse_str(parse_url($data['kelompokTani']->url(2), PHP_URL_QUERY), $params);
|
||||
foreach ($filters as $field => $value) expect((string) $params[$field])->toBe((string) $value);
|
||||
expect((int) $data['summary']->total_kelompok)->toBe(1);
|
||||
});
|
||||
|
||||
test('list cards filters columns and permissions match the group data', function (string $role, bool $showEnumerator) {
|
||||
$user = new User(['name' => 'Pengguna Uji', 'email' => 'user@example.test', 'role' => $role]);
|
||||
$user->id = 7;
|
||||
$this->be($user);
|
||||
$data = ($this->listKelompok)(['status_legalitas' => 'Sedang proses pengajuan']);
|
||||
$html = view('produktivitas.survey-kelompok-tani.index', $data)->render();
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML($html);
|
||||
libxml_clear_errors();
|
||||
$xpath = new DOMXPath($dom);
|
||||
expect($xpath->query('//div[@id="kelompok-overview"]/div')->length)->toBe(4);
|
||||
foreach (['Kelompok Tani', 'Komoditas', 'Status SK', 'Pengurus', 'Anggota', 'Nama Responden'] as $heading) {
|
||||
expect($xpath->query('//th[normalize-space()="'.$heading.'"]')->length)->toBe(1);
|
||||
}
|
||||
expect($xpath->query('//th[normalize-space()="Nama Enumerator"]')->length)->toBe($showEnumerator ? 1 : 0);
|
||||
expect($data['showEnumerator'])->toBe($showEnumerator);
|
||||
expect($xpath->query('//*[@name="pernah_mendapatkan_bantuan"]')->length)->toBe(0);
|
||||
expect($xpath->query('//form[@id="kelompok-filter-form"]')->item(0)->getAttribute('data-desa-url'))->toContain(':id');
|
||||
expect($xpath->query('//button[contains(@class,"delete-record")]')->item(0)->getAttribute('data-delete-url'))->toBe(route('kelompok-tani.destroy', 2));
|
||||
expect($html)->toContain('kelompok-tani.js');
|
||||
})->with([['admin', true], ['super_admin', true], ['enumerator', false]]);
|
||||
|
||||
test('roles outside group management cannot request the list', function () {
|
||||
$user = new User(['name' => 'Fasilitator Uji', 'email' => 'fasilitator@example.test', 'role' => 'fasilitator']);
|
||||
$this->be($user);
|
||||
expect(fn () => ($this->listKelompok)())->toThrow(\Illuminate\Auth\Access\AuthorizationException::class);
|
||||
});
|
||||
|
||||
test('all standard type and SK choices remain available with no matching or recorded groups', function () {
|
||||
$data = ($this->listKelompok)(['search' => 'Tidak ada kelompok']);
|
||||
expect($data['kelompokTani']->total())->toBe(0);
|
||||
expect($data['jenisKelompokOptions']->all())->toBe([
|
||||
'Kelompok Tani (Poktan)', 'Kelompok Wanita Tani (KWT)', 'Gabungan Kelompok Tani (Gapoktan)',
|
||||
'Kelompok Pemuda Tani', 'Asosiasi Petani', 'Lainnya',
|
||||
]);
|
||||
expect($data['statusLegalitasOptions']->all())->toBe([
|
||||
'Belum ada SK/dokumen apa pun', 'Sedang proses pengajuan', 'Sudah ada SK dari desa/kecamatan',
|
||||
'Sudah ada SK dan terdaftar di Dinas/Kabupaten', 'Tidak tahu',
|
||||
]);
|
||||
DB::table('survey_kelompok_tani')->update(['deleted_at' => now()]);
|
||||
$empty = ($this->listKelompok)();
|
||||
expect($empty['jenisKelompokOptions']->all())->toBe($data['jenisKelompokOptions']->all());
|
||||
expect($empty['statusLegalitasOptions']->all())->toBe($data['statusLegalitasOptions']->all());
|
||||
$html = view('produktivitas.survey-kelompok-tani.index', $empty)->render();
|
||||
expect($html)->toContain('Gabungan Kelompok Tani (Gapoktan)', 'Tidak tahu');
|
||||
});
|
||||
|
||||
test('Lainnya type filter includes custom descriptions and literal Lainnya', function () {
|
||||
DB::table('survey_kelompok_tani')->where('id', 3)->update(['jenis_kelompok' => 'Komunitas Petani Lokal']);
|
||||
DB::table('survey_kelompok_tani')->where('id', 2)->update(['jenis_kelompok' => 'Lainnya']);
|
||||
$data = ($this->listKelompok)(['jenis_kelompok' => 'Lainnya']);
|
||||
expect($data['kelompokTani']->pluck('id')->all())->toBe([3, 2]);
|
||||
expect((int) $data['summary']->total_kelompok)->toBe(2);
|
||||
});
|
||||
|
||||
test('removed aid filter neither constrains results nor persists in pagination', function () {
|
||||
$data = ($this->listKelompok)(['pernah_mendapatkan_bantuan' => '0']);
|
||||
expect($data['kelompokTani']->pluck('id')->all())->toBe([3, 2, 1]);
|
||||
expect($data['filters'])->not->toHaveKey('pernah_mendapatkan_bantuan');
|
||||
expect($data['kelompokTani']->url(2))->not->toContain('pernah_mendapatkan_bantuan');
|
||||
});
|
||||
|
||||
test('unfilled membership totals remain distinct from a recorded zero in the table', function () {
|
||||
$data = ($this->listKelompok)(['search' => 'Citra']);
|
||||
$html = view('produktivitas.survey-kelompok-tani.index', $data)->render();
|
||||
$dom = new DOMDocument();
|
||||
libxml_use_internal_errors(true);
|
||||
$dom->loadHTML($html);
|
||||
libxml_clear_errors();
|
||||
$xpath = new DOMXPath($dom);
|
||||
expect(trim($xpath->query('//tr[contains(@class,"kelompok-tani-row")]/td[5]/div')->item(0)->textContent))->toBe('Belum terisi');
|
||||
expect(trim($xpath->query('//tr[contains(@class,"kelompok-tani-row")]/td[6]/div')->item(0)->textContent))->toBe('0');
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Pertanian\KelompokTani;
|
||||
use App\Models\Pertanian\AsetKelompokTani;
|
||||
use App\Models\Pertanian\BantuanKelompokTani;
|
||||
use App\Models\User;
|
||||
use App\Services\Produktivitas\KelompokTaniService;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -17,6 +18,17 @@ use Illuminate\Support\ViewErrorBag;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
beforeEach(function () {
|
||||
Schema::create('activity_log', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('log_name')->nullable();
|
||||
$table->text('description');
|
||||
$table->nullableMorphs('subject');
|
||||
$table->nullableMorphs('causer');
|
||||
$table->string('event')->nullable();
|
||||
$table->json('properties')->nullable();
|
||||
$table->uuid('batch_uuid')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
foreach ([
|
||||
'master_provinsi' => null,
|
||||
'master_kabupaten_kota' => 'provinsi_id',
|
||||
@@ -126,6 +138,10 @@ beforeEach(function () {
|
||||
return $request;
|
||||
};
|
||||
$this->profileDom = function ($view) {
|
||||
$data = $view->getData();
|
||||
if (!array_key_exists('ringkasanProfil', $data)) {
|
||||
$view->with('ringkasanProfil', app(KelompokTaniService::class)->profileSummary($data['kelompokTani'] ?? null));
|
||||
}
|
||||
$dom = new DOMDocument();
|
||||
$previous = libxml_use_internal_errors(true);
|
||||
$dom->loadHTML($view->render());
|
||||
@@ -159,6 +175,85 @@ test('profile saves identity and membership together on creation and update', fu
|
||||
expect($response->getTargetUrl())->toBe(route('kelompok-tani.edit', $group->id) . '#section-pengurus');
|
||||
});
|
||||
|
||||
test('profile summary uses saved group details and preserves recorded zero totals', function () {
|
||||
DB::table('master_komoditas')->insert([
|
||||
['id' => 1, 'nama' => 'Kopi'], ['id' => 2, 'nama' => 'Kakao'], ['id' => 3, 'nama' => 'Vanili'],
|
||||
]);
|
||||
$group = ($this->kelompok)([
|
||||
'jumlah_pengurus' => 0, 'jumlah_anggota_terdaftar' => null, 'komoditas_id' => [1, '2', 3, 1],
|
||||
'status_legalitas' => 'Sudah ada SK dari desa/kecamatan',
|
||||
'jabatan_responden' => 'Ketua', 'kontak_responden' => '08123456789', 'tahun_berdiri' => 2020,
|
||||
]);
|
||||
$summary = app(KelompokTaniService::class)->profileSummary($group);
|
||||
expect($summary['judul'])->toBe('Kelompok A');
|
||||
expect($summary['lokasi'])->toBe('Desa A · Kecamatan A · Ngada');
|
||||
expect($summary['jenis'])->toBe('Kelompok Tani (Poktan)');
|
||||
expect($summary['pengurus'])->toBe('0');
|
||||
expect($summary['anggota'])->toBe('Belum terisi');
|
||||
expect($summary['komoditas'])->toBe(['Kakao', 'Kopi', 'Vanili']);
|
||||
expect($summary['legalitas']['label'])->toBe('Sudah ada SK');
|
||||
expect($summary['legalitas']['detail'])->toBe('Sudah ada SK dari desa/kecamatan');
|
||||
expect($summary['kontak'])->toBe('08123456789');
|
||||
});
|
||||
|
||||
test('all profile tabs receive the same saved summary with expandable commodities', function () {
|
||||
DB::table('master_komoditas')->insert([
|
||||
['id' => 1, 'nama' => 'Kopi'], ['id' => 2, 'nama' => 'Kakao'], ['id' => 3, 'nama' => 'Vanili'],
|
||||
]);
|
||||
$group = ($this->kelompok)(['jumlah_pengurus' => 4, 'jumlah_anggota_terdaftar' => 5, 'komoditas_id' => [1, 2, 3]]);
|
||||
$controller = app(SurveyKelompokTaniController::class);
|
||||
$expected = app(KelompokTaniService::class)->profileSummary($group);
|
||||
foreach (['identitas', 'kelembagaan', 'aktivitas-fungsi', 'sosial-konflik'] as $section) {
|
||||
$view = $controller->edit(($this->profileRequest)(['section' => $section], 'GET'), $group);
|
||||
expect($view->getData()['ringkasanProfil'])->toEqual($expected);
|
||||
$dom = ($this->profileDom)($view);
|
||||
expect($dom->query('//div[@id="kelompok-tani-summary"]/div[contains(@class,"card-footer")]')->length)->toBe(1);
|
||||
expect($dom->query('//div[contains(@class,"card-footer") and contains(@class,"border-top")]')->length)->toBe(1);
|
||||
expect($dom->query('//div[@id="kelompok-tani-summary"]/div[contains(@class,"card-body")]//*[@data-summary-field="tahun_berdiri"]')->length)->toBe(1);
|
||||
expect($dom->query('//div[contains(@class,"card-footer")]//*[@data-summary-field="tahun_berdiri"]')->length)->toBe(0);
|
||||
expect($dom->query('//div[contains(@class,"card-footer")]//*[@data-summary-field="diperbarui"]/time')->length)->toBe(1);
|
||||
expect($dom->query('//*[@data-summary-field="pengurus"]')->item(0)->textContent)->toBe('4');
|
||||
expect($dom->query('//*[@data-summary-field="anggota"]')->item(0)->textContent)->toBe('5');
|
||||
expect(trim($dom->query('//button[@data-bs-target="#kelompok-summary-extra-komoditas"]')->item(0)->textContent))->toBe('+1 lainnya');
|
||||
}
|
||||
});
|
||||
|
||||
test('new group summary is empty and rendering the header performs no database queries', function () {
|
||||
($this->profileRequest)([], 'GET');
|
||||
$summary = app(KelompokTaniService::class)->profileSummary();
|
||||
expect($summary['judul'])->toBe('Profil Kelompok Tani Baru');
|
||||
expect($summary['pengurus'])->toBe('Belum terisi');
|
||||
expect($summary['anggota'])->toBe('Belum terisi');
|
||||
expect($summary['komoditas'])->toBe([]);
|
||||
DB::enableQueryLog();
|
||||
DB::flushQueryLog();
|
||||
$html = view('produktivitas.survey-kelompok-tani.header', ['kelompokTani' => null, 'ringkasanProfil' => $summary])->render();
|
||||
expect(DB::getQueryLog())->toBe([]);
|
||||
expect($html)->toContain('Belum tersimpan');
|
||||
DB::disableQueryLog();
|
||||
});
|
||||
|
||||
test('summary update time includes changes to group sections and removal of a recorded aid', function () {
|
||||
$group = ($this->kelompok)();
|
||||
DB::table('survey_kelompok_tani')->where('id', $group->id)->update([
|
||||
'created_at' => '2026-01-01 08:00:00', 'updated_at' => '2026-01-01 08:00:00',
|
||||
]);
|
||||
$group->refresh();
|
||||
$service = app(KelompokTaniService::class);
|
||||
expect($service->profileSummary($group)['diperbarui']->format('Y-m-d H:i:s'))->toBe('2026-01-01 08:00:00');
|
||||
|
||||
foreach ([
|
||||
['survey_pengurus_kelompok_tani', ['nama_pengurus' => 'Ketua', 'jabatan' => 'Ketua', 'kontak' => '08123456789', 'status' => true, 'updated_at' => null], '2026-01-02 09:00:00'],
|
||||
['survey_aset_kelompok_tani', ['jenis_aset' => 'Timbangan', 'status_aset' => true, 'status_pengelolaan_aset' => 'Swadaya', 'kondisi_aset' => 'Berfungsi', 'updated_at' => '2026-01-03 10:00:00'], '2026-01-03 10:00:00'],
|
||||
['survey_bantuan_kelompok_tani', ['nama_program' => 'Program A', 'penyelenggara' => 'Dinas', 'bentuk_bantuan' => 'Bibit', 'updated_at' => '2026-01-04 11:00:00', 'deleted_at' => '2026-01-04 11:00:00'], '2026-01-04 11:00:00'],
|
||||
] as [$table, $attributes, $expected]) {
|
||||
DB::table($table)->insert(['uid' => 'TEST-UPDATED', 'survey_kelompok_tani_id' => $group->id, 'created_at' => $expected, ...$attributes]);
|
||||
expect($service->profileSummary($group)['diperbarui']->format('Y-m-d H:i:s'))->toBe($expected);
|
||||
}
|
||||
DB::table('survey_kelompok_tani')->where('id', $group->id)->update(['updated_at' => '2026-01-05 12:00:00']);
|
||||
expect($service->profileSummary($group->refresh())['diperbarui']->format('Y-m-d H:i:s'))->toBe('2026-01-05 12:00:00');
|
||||
});
|
||||
|
||||
test('invalid membership prevents partial profile saves', function () {
|
||||
$group = ($this->kelompok)(['jumlah_anggota_terdaftar' => 20]);
|
||||
$request = ($this->profileRequest)([
|
||||
|
||||
Reference in New Issue
Block a user