Feat: Consumer-Side Contract Tests for OpenSID#1681
Open
pandigresik wants to merge 14 commits into
Open
Conversation
- Update config/scribe.php with proper auth, routes, and OpenAPI config - Add artisan command scribe:copy-openapi to copy spec to repo root - Add composer scripts: generate-openapi, validate-openapi - Add openapi.yaml (initial generated spec with 54 endpoints) - Add CI workflow: openapi.yml (generate & validate on PR/push) - Update test.yml to also copy & validate OpenAPI spec - Add docs/integration-testing.md with local dev instructions - Add SCRIBE_AUTH_KEY to .env.example
- Fix CekDesa rule: lazy-load DB query in message() instead of constructor - Add missing test() method to PendudukController - Regenerate openapi.yaml (now 61 paths, covering all api.php routes) - Remove outdated note about missing endpoints from docs
- Add @group and @bodyParam/response annotations to all api/v1 controllers - Add meaningful summaries to frontend API controllers - Fix AuthController login with proper Scribe annotations - Regenerate openapi.yaml with all 61 paths properly described - Each OpenSID submission endpoint now has documented body params & response
- Remove api/frontend/* from scribe route prefixes - Regenerate spec: 21 paths, focused on OpenSID endpoints only
- Add detailed ZIP column contracts to controller docblocks - Separate JSON vs ZIP endpoints with proper @bodyParam types - Add ZIP contract validation table to docs/integration-testing.md - Add sample ZIP generator script and Pest contract test example - Each file upload endpoint now documents expected internal file format
- Add Pest-based contract tests validating 11 request payloads vs OpenAPI spec - Create example JSON payloads for auth, penduduk, laporan, pesan, identitas-desa - Add contract.yml CI workflow (no DB needed, runs on PR to master/dev) - Fix laporan_apbdes & laporan_penduduk controller annotations for proper object[] schema - Add composer test:contract and npm run test:contract scripts - Document running contract tests locally in docs/integration-testing.md Issue: #1673
Contributor
|
🔄 AI PR Review sedang antri di server...
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request: Consumer-Side Contract Tests for OpenSID Request Validation
Description
Menambahkan consumer-side contract tests yang memvalidasi request payload OpenSID terhadap OpenAPI spec OpenDK (
openapi/openapi.yaml). Menggunakanjustinrainbow/json-schemauntuk validasi JSON Schema dari request body yang didefinisikan di spec. Jika spec berubah secara incompatible (misalnya field required dihapus atau tipe data berubah), CI akan gagal sehingga mencegah breaking changes pada integrasi OpenSID-OpenDK.Changes made:
Contract Test Suite:
tests/Contract/OpenApiContractTest.php— Pest test berbasis dataset yang memvalidasi 11 contoh request payload (7 success + 4 validation error) terhadap schema dari OpenAPI spec.Contoh Payload OpenSID: 11 file JSON di
tests/Contract/examples/mencakup skenario auth (login success, missing email, missing password), penduduk (hapus success, missing desa_id), laporan APBDes, laporan penduduk, pesan (kirim success, missing pesan, getpesan), dan identitas desa.CI Workflow:
.github/workflows/contract.yml— job ringan tanpa database yang menjalankan validasi OpenAPI spec dan contract tests pada setiap PR kemaster/rilis-dev/dev.Perbaikan Spec APBDes & Laporan Penduduk:
app/Http/Controllers/Api/LaporanApbdesController.phpdanLaporanPendudukController.php— annotation@bodyParamdiperbaiki dariarraymenjadiobject[]dengan properti child yang detail, sehingga Scribe menghasilkan schema yang benar (array of object, bukan array of string).Composer & npm Scripts:
composer.jsondanpackage.json— ditambahkan scripttest:contractuntuk menjalankan contract tests.Test Configuration:
phpunit.xml.distdantests/Pest.php— registrasi test suite Contract dan grupcontract.Dokumentasi:
docs/integration-testing.md— section 5 diperbarui dengan panduan lengkap menjalankan contract tests lokal, struktur direktori, CI pipeline, dan cara menambah contoh payload baru.Reason for change:
Impact of change:
✅ Deteksi dini breaking changes: Jika OpenDK mengubah schema request (misalnya menambah field required, mengubah tipe data), contract tests gagal di CI
✅ Source of truth ganda: OpenAPI spec sebagai kontrak + contoh payload sebagai konsumen — keduanya harus sinkron
✅ CI ringan: Contract tests tidak perlu database, selesai < 1 detik
✅ Onboarding lebih mudah: Developer OpenSID cukup lihat contoh payload JSON untuk memahami format request yang benar
Related Issue
#1673
Steps to Reproduce
Before (problem):
After (solution):
composer generate-openapiuntuk regenerate spec dari kodecomposer test:contractuntuk validasi contoh payloadTesting on related features:
.github/workflows/contract.ymlsiap dijalankanChecklist
Technical Details
Technical Explanation
Arsitektur Contract Tests:
Alur validasi:
dataset('contract_examples')membacaopenapi/openapi.yamldan semua file JSON contohgetRequestSchema()mengekstrak schema JSON daripaths[path][method].requestBody.content.application/json.schemaJsonSchema\Validator::validate()memvalidasi payload terhadap schema dengan modeCHECK_MODE_NORMALshould_succeed: true→ assertisValid() === true;should_succeed: false→ assertisValid() === falseScribe Annotation Fix:
Sebelumnya
@bodyParam laporan_apbdes arraymenghasilkanitems: type: stringdi spec. Diperbaiki menjadi@bodyParam laporan_apbdes object[]dengan child fields menggunakan dot notation, sehingga Scribe menghasilkanitems: type: objectdengan properti yang benar.Configuration changes
composer.json— tambah dev dependencyjustinrainbow/json-schemadan scripttest:contractphpunit.xml.dist— tambah test suiteContractpackage.json— tambah scripttest:contractDependencies added
justinrainbow/json-schema: ^6.10 — JSON Schema validation librarymarc-mabe/php-enum: ^4.4 — dependency dari justinrainbow/json-schemaTesting
Manual Testing
composer test:contract— 11 tests passed, 22 assertionsphp bin/validate-openapi.php— OpenAPI spec valid (3.0.3, 21 paths)composer generate-openapi— spec regenerate suksesAutomated Testing
.github/workflows/contract.yml(tanpa database)Screenshots / Video
Test Output:
Breaking Changes
None — semua perubahan bersifat additive (menambah test suite, memperbaiki completeness spec).
Migration Guide
Not required.
References