Skip to content

Tests untuk API Key lifecycle + integration tests (provider-side) di OpenDK #1675

Description

@analisopendesa

Tambahkan unit & integration tests di OpenDK yang men-cover seluruh lifecycle API key: pembuatan, validasi, revocation/disable, scope enforcement, dan audit logging; plus deterministic test fixtures/seeders untuk test data.

Ruang lingkup

  • Unit tests (Pest/PHPUnit) untuk services yang membuat/validasi API key.
  • Integration tests untuk controller + middleware + database (sqlite in-memory / docker).
  • Seeders & factories untuk test fixtures (API key owner, sample data payload, audit entries).
  • Tests untuk negative cases: missing key, invalid key, revoked key, insufficient scope.
  • Test untuk idempotency/duplicate submission case.

Acceptance criteria (terukur)

  • Test suite men-cover:
    • Create key -> assert DB record & attributes
    • Validate valid key -> passes middleware
    • Disabled/revoked key -> 403
    • Missing key -> 401
    • Scope restriction -> 403
    • Audit log record created per request
  • Tests run reliably in CI (sqlite in-memory) and total added coverage untuk module API-key minimal 80%.
  • Factories/seeders di database/factories & database/seeders tersedia untuk test use.

langkah spesifik

  • Tulis factories/seeders: ApiKeyFactory, UserFactory, SamplePayloadFactory.
  • Tulis unit tests untuk KeyService (create, revoke, validate).
  • Tulis integration tests yang menjalankan controller + middleware menggunakan in-memory DB.
  • Tambah negative tests (invalid/missing/revoked/scope).
  • Pastikan test teardown/DB rollback.

Metadata

Metadata

Assignees

Labels

Tingkat: T3Empat hingga lima hari kerja (satu sprint)Tipe: TeknisPerubahan teknis tanpa merubah tampilan/fungsionalitas

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions