Skip to content

Full-CRUD subscription API + set-subscription script#128

Open
pmanko wants to merge 4 commits into
mainfrom
claude/confident-goldstine
Open

Full-CRUD subscription API + set-subscription script#128
pmanko wants to merge 4 commits into
mainfrom
claude/confident-goldstine

Conversation

@pmanko

@pmanko pmanko commented Apr 15, 2026

Copy link
Copy Markdown
Member

Summary

Adds modern REST/JSON CRUD to the lnsp-mediator subscription API and a bash script to repoint a subscription at a new target URL. Preserves the legacy XML POST /subscription path used by OpenHIM's /dsub channel.

What changes

  • POST /subscription — accepts JSON {targetAddress} OR the existing parsed SOAP XML (body-sniffed on soap:envelope key)
  • GET /subscription/:id — get by id (404 if missing, 400 if invalid ObjectId)
  • PATCH /subscription/:id — partial update (same error contract)
  • DELETE /subscription/:id — delete (same error contract)
  • Fixes a pre-existing bug: handleSubscription fired the DB write without await, so the XML path answered 200 even on DB failure. Now awaited.
  • New projects/lnsp-mediator/scripts/set-subscription.sh — delete-by-URL then POST-JSON-create, for repointing subscriptions.

TDD checklist

  • Step 0: scaffold commit, draft PR open
  • Step 1: service unit tests (red) — 17 specs
  • Step 2: controller unit tests (red) — 7 specs
  • Step 3: integration test w/ mongodb-memory-server (red) — 4 specs
  • Step 4: implement service → service tests green
  • Step 5: implement controller → controller + integration tests green
  • Step 6: UpdateSubscriptionDto wired into PATCH
  • Step 7: yarn test (40 passed / 40 total), yarn build green
  • Step 8: bash script + scripts/README.md
  • Step 9: manual smoke — script repointed subscription end-to-end against a local mediator + Docker Mongo; PATCH, 400 on invalid id, 404 on missing id all verified

Test plan

  • cd projects/lnsp-mediator && yarn test — service + controller unit specs, integration spec all green (10 suites, 40 tests)
  • yarn build clean
  • Manual smoke: seed subscription, run scripts/set-subscription.sh OLD NEW, confirm via GET /subscription the list is repointed ✅
  • Backward-compat: handleSubscription preserved at the service layer. XML dispatch in the controller covered by the body-sniff unit test. The root / SOAP dispatcher in app.controller.ts is untouched.

Pre-existing issues noted (not fixed here)

  • test/app.e2e-spec.ts has a stale supertest import style and requires a real Mongo. CI runs only yarn test (unit), so this has been silently broken.
  • The body-parser order in main.ts means express-xml-bodyparser is a no-op (text parser consumes the body first). An HTTP POST of raw XML to /subscription has never produced a parsed object; the XML branch is exercised only when a pre-parsed object is passed in. Out of scope for this PR.

Out of scope

  • No ValidationPipe added (none exists today)
  • No auth on the new endpoints (consistent with current API)
  • No changes to the OpenHIM /dsub channel or the root / SOAP dispatcher
  • No delete-by-targetAddress or bulk-delete endpoints
  • No XML support on PATCH/DELETE

🤖 Generated with Claude Code

pmanko and others added 4 commits April 15, 2026 11:47
Scaffold for the upcoming full-CRUD subscription work. Wired up in
subsequent commits alongside the new PATCH /subscription/:id handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Unit tests (service, controller) and an integration test exercise the
not-yet-implemented full-CRUD surface: createFromDto, getById, update,
delete, plus body-sniffed POST dispatch. Also adds a regression test
that fails until handleSubscription properly awaits the DB write.

Adds mongodb-memory-server as a devDep for the integration spec; it
stands up a SubscriptionModule-only test app (no AppModule, no Agenda).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Service: add createFromDto, getById, update, delete with ObjectId
validation (BadRequestException on bad id, NotFoundException on
missing row). Make handleSubscription async and await the DAO write
so the XML path now correctly reports failure when the write rejects.

Controller: POST /subscription now sniffs body shape — parsed SOAP XML
(body contains 'soap:envelope' key) still routes to handleSubscription
for backward compat with OpenHIM /dsub; plain JSON routes to
createFromDto. Add GET /subscription/:id, PATCH /subscription/:id,
DELETE /subscription/:id.

All 40 tests pass (17 service, 7 controller, 4 integration against an
in-memory MongoDB, plus the pre-existing suite).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Takes OLD_URL + NEW_URL (plus optional BASE_URL), finds the
subscription whose targetAddress matches OLD_URL via the modern JSON
list endpoint, deletes it by id, then creates a new subscription
pointing at NEW_URL. Idempotent if OLD_URL is absent.

Smoke-tested end-to-end against a local mediator + Dockerized Mongo:

  POST {targetAddress: http://old.example/cb}    -> 201 new doc
  set-subscription.sh http://old.example http://new.example
  GET /subscription                              -> [{targetAddress: http://new.example}]

Also verified PATCH /:id, 400 on invalid id, 404 on missing id.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pmanko pmanko marked this pull request as ready for review April 15, 2026 19:06
@cursor

cursor Bot commented Apr 15, 2026

Copy link
Copy Markdown

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant