Skip to content

fix: three Portal and API-Manager calls to endpoints OBP-API does not serve - #6

Open
hongwei1 wants to merge 2 commits into
OpenBankProject:mainfrom
hongwei1:fix/portal-manager-endpoint-mismatches
Open

fix: three Portal and API-Manager calls to endpoints OBP-API does not serve#6
hongwei1 wants to merge 2 commits into
OpenBankProject:mainfrom
hongwei1:fix/portal-manager-endpoint-mismatches

Conversation

@hongwei1

Copy link
Copy Markdown
Contributor

Three calls in Portal and API-Manager went to endpoints OBP-API does not serve. Each one
failed silently in a different way, which is why none of them had been noticed:

1. user-invitation accepted with PUT, and swallowed the result.
obp_requests.put was called against /banks/{id}/user-invitations, which OBP-API serves
as POST only. The response was never checked, and the redirect sat inside the try, so
SvelteKit's control-flow redirect was caught by the same catch that handled the API error.
The user saw a success page after a failed request. Fixed the verb and moved the redirect
out of the try.

2. Chat reaction removal put the emoji in the body.
DELETE .../messages/{id}/reactions with { emoji } as a JSON body. The API serves the
emoji as the last path segment — .../reactions/{emoji} — and .../reactions is POST and
GET only. The UI removed the reaction optimistically and never checked res.ok, so a 4xx
left the reaction gone from the screen, still in the database, and back again on reload,
with nothing logged. Fixed the path and added the res.ok revert.

3. API-Manager had a proxy route for an endpoint that does not exist.
backend/obp/banks/[bank_id]/views/+server.ts proxied GET /banks/{id}/views. OBP-API has
no such endpoint — views are per-account (/banks/{id}/accounts/{id}/views) or system-wide
(/system-views). Nothing in the app called this route. Removed.

Tests

Added coverage for the two behavioural fixes:

  • apps/portal/src/routes/user-invitation/page.server.test.ts — asserts the verb, not
    just the URL, and that a failing API call does not produce a success redirect.
  • apps/portal/test/unit/routes/chat.reactions.svelte.test.ts — asserts the emoji is a path
    segment, that no body is sent, and that a 4xx reverts the optimistic removal.

npm run test:unit in apps/portal: 89 passed / 11 files, on top of current main.

These three were found by diffing the front ends' actual call sites against OBP-API's
resource-docs surface, so each is a real mismatch against what the API advertises rather
than a suspected one.

Each was found by resolving every call site in this repository against OBP-API's
published resource-docs, and each was confirmed against a live develop-obp
(3df73fe11) with the verb held constant, so none of them is the
404-for-a-wrong-verb ambiguity.

Portal, accepting a user invitation (#5)
  obp_requests.put -> post. /obp/v4.0.0/banks/{id}/user-invitation is POST-only at
  v4.0.0 and v6.0.0 alike; PUT answers 404 OBP-10404 while POST answers 401. The
  same file already POSTs the sibling /user-invitations path correctly, and
  API-Manager POSTs this one correctly, so the convention was established in two
  other places and only this call site diverged.

  Fixing the verb alone did not make the flow work, which the new test caught: the
  redirect was thrown inside the try, and the catch-all below it turns anything
  that is not an OBPRequestError into "Failed to create account: Unknown error".
  redirect() signals by throwing, so a successful account creation reported
  failure. The redirect now returns after the try/catch, matching what the
  register action already does.

Portal, removing a chat reaction (#6)
  The emoji moves from the DELETE body into the path: OBP-API serves
  .../reactions/{emoji} for DELETE and only POST/GET on .../reactions. The
  response is now checked with res.ok, mirroring the add branch immediately below
  it. fetch does not reject on 4xx, so the old try/catch could not see the failure
  -- the reaction vanished from the UI, stayed in the database, and returned on
  reload with nothing logged. The add path was already correct and is untouched.

API-Manager, creating a custom view (#7)
  routes/backend/obp/banks/[bank_id]/views/+server.ts is deleted rather than
  repaired. It targets /obp/v6.0.0/banks/{id}/views, which OBP-API does not serve
  at any verb -- every view endpoint is account-scoped -- and nothing calls it: the
  custom-view page posts to the account-scoped route next to it, which builds the
  correct URL. It was a copy of a working route with the account segment dropped.

Adds apps/portal/src/routes/user-invitation/page.server.test.ts, following the
pattern of the register action's test. It asserts the verb rather than only the
URL, which is what lets it fail if this regresses, and it is what surfaced the
swallowed redirect.

Verified: portal 86/86 unit tests pass, api-manager 15/15. svelte-check is
unchanged against the base commit on both apps (portal 21 errors/70 warnings,
api-manager 22/332), so no new type errors. Both apps build.
The reaction fix shipped without a test, which left the least visible of the three
defects the least protected: fetch resolves on a 4xx, so the failure it guards
against produces no error anywhere -- the reaction vanishes from the UI, stays in
the database, and returns on reload.

Three cases, rendered against the real component:

  * removal sends the emoji as the last path segment and no body;
  * a failed removal restores the badge, which is the res.ok check;
  * addition still POSTs with the emoji in the body, unchanged -- that path was
    already correct and the test exists to keep it that way.

Both new cases were run against the pre-fix code and fail there: the first on the
URL, the second on the badge staying gone. The third passes either way, as it
should, since the add path was not touched. A test that has not been shown to fail
does not establish anything when it passes.

$env/dynamic/public is mocked because the component pulls in $lib/avatar/generate,
which reads it at module scope and throws under vitest otherwise.

portal is now 89/89 across 11 files.
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