[ARCHIVE] feat: introduce BetterGov.ph Project Registry with schema validation, GET API, and test suite#637
Closed
zelkim wants to merge 7 commits into
Closed
[ARCHIVE] feat: introduce BetterGov.ph Project Registry with schema validation, GET API, and test suite#637zelkim wants to merge 7 commits into
zelkim wants to merge 7 commits into
Conversation
Member
|
Feel free to Reopen this PR when this topic comes back in the future. |
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.
Important
This is an archive of a more extensive projects API, that has, for now, been simplified to a static
projects.json. This will be revisited in the future, see referenced discussion below:Summary
This PR introduces a centralized, JSON-based Project Registry for all officially recognized BetterGov.ph projects, along with a public GET API to serve the data, pre-commit schema validation to guard data integrity, and a full test suite covering unit, integration, and live scenarios.
Motivation
As BetterGov.ph grows into an ecosystem of projects — not all of which live within the
bettergovphGitHub organization — there was no single source of truth for which projects are officially recognized. This registry solves that by:Changes
1. Project Registry —
src/data/projects.jsonA new JSON file seeded with all 16 currently recognized BetterGov.ph projects (sourced from the existing
ourProjectslist innavigation.ts, enriched with descriptions and repository URLs fetched from thebettergovphGitHub org).Each entry contains:
slugtitledescriptionrepositoryUrlsprojectUrlstatusactive|development|archived2. JSON Schema —
src/data/schema/projects.schema.jsonA JSON Schema Draft-07 file that enforces the registry structure:
additionalProperties: falseslugvalidated as kebab-case via regex (^[a-z0-9]+(?:-[a-z0-9]+)*$)projectUrland eachrepositoryUrlvalidated as HTTPS URLsstatusvalidated as an enum3. Pre-commit Validation —
.lintstagedrc.jsSchema validation is wired into the existing husky → lint-staged pre-commit pipeline. Whenever
src/data/projects.jsonis staged, the existingvalidate-json-schema.jsscript runs automatically and blocks the commit if any entry violates the schema.This also fixes a pre-existing bug in
validate-json-schema.jswhere Ajv v8's strict mode caused schemas usingformatkeywords (including the existingservices.schema.jsonandpopulation-2020.schema.json) to fail to compile. Fixed by passingstrict: falseto the Ajv instance.4. GET API —
functions/api/projects.ts+functions/index.tsA new Cloudflare Worker endpoint:
GET /api/projectsThe data is bundled statically at build time (JSON import) — no KV or D1 bindings required. Filtering and pagination are done in-memory, which is appropriate for a registry of this scale.
Query parameters:
searchtitleanddescriptionstatusactive,development, orarchivedpage1limit20100)Response shape:
{ "data": [ ...projects ], "meta": { "total": 16, "page": 1, "limit": 20, "totalPages": 1, "hasNextPage": false, "hasPrevPage": false } }CORS headers (
Access-Control-Allow-Origin: *) and OPTIONS preflight are handled byindex.tsconsistently with all other endpoints. The new route is also listed in/api/status.5. TypeScript —
functions/types.tsAdded a
Projectinterface mirroring the schema shape, used to type the bundled import and the API response.6. Test Suite
Three layers of tests, all runnable without external services:
Unit tests —
functions/api/projects.test.ts(23 tests)Call
onRequestdirectly with constructedRequestobjects. Cover:hasNextPage/hasPrevPage, out-of-range clamping, NaN inputs)Run:
npm run test:functionsIn-process integration tests —
functions/integration/projects.integration.test.ts(9 tests)Call the full
index.tsfetch handler directly (no server). Cover routing, CORS header injection, OPTIONS preflight, and end-to-end query param handling through the complete worker pipeline.Run:
npm run test:functionsLive integration tests —
functions/integration/projects.live.test.ts(21 tests)Start a real Wrangler dev server via
unstable_devand make actual HTTPfetch()calls against it. Cover every scenario above plus wire-level CORS header verification and the full network stack.Run:
npm run test:functions:live7. Dev Server Fix —
wrangler.test.jsonc+functions:devscriptnpm run functions:devpreviously failed if./distdid not exist (the production wrangler config requires a built assets directory). A newwrangler.test.jsoncprovides a functions-only config (with KV bindings preserved for weather/forex) so functions can be developed and tested without a prior frontend build.New npm scripts
npm run test:functionsnpm run test:functions:watchnpm run test:functions:liveFiles changed
src/data/projects.jsonsrc/data/schema/projects.schema.jsonfunctions/api/projects.tsfunctions/api/projects.test.tsfunctions/integration/projects.integration.test.tsfunctions/integration/projects.live.test.tsfunctions/vitest.config.tsfunctions/vitest.live.config.tswrangler.test.jsoncfunctions/types.tsProjectinterfacefunctions/index.ts/api/projectsroute and updated status/404 docs.lintstagedrc.jsprojects.jsoncommitscripts/validate-json-schema.jsstrict: falseon Ajv to supportformatkeywords in existing schemaspackage.jsonvitestdev dependency and new test scripts