Skip to content

fix(mui-favorites): read favorites from unwrapped settings PUT response - #952

Merged
jordan-a-young merged 1 commit into
mainfrom
feature/favorites-put-response
Oct 29, 2026
Merged

jordan-a-young merged 1 commit into
mainfrom
feature/favorites-put-response

Conversation

@jordan-a-young

Copy link
Copy Markdown
Member

Summary

Fixes a crash on every add/remove of a favorite in @availity/mui-favorites 3.x (Cannot read properties of undefined (reading '0'), reported from clip-ui on TST).

The Settings API PUT returns the saved settings object directly, not wrapped in a settings array like GET:

{ "favorites": [ { "id": "123", "pos": 0 } ], "scope": { "applicationId": "Gateway-AvNavigation", ... } }

Verified against the service source (availity/onb/epum/settings-service/settings-service, SettingsController.putSettings, which returns the request body minus scope, plus scope).

3.0.0 (cc22bb4a2) read PUT as response.data.settings[0].favorites, and the MSW mock was changed to wrap the PUT body to match. The tests echoed the request, so they passed against the broken code.

Changes

  • utils.ts: separate FavoritesGetResponse (settings[]) and FavoritesPutResponse (favorites) types. submit() reads response.data.favorites.
  • handlers.ts (@availity/mock): PUT returns the body unwrapped, matching the real service.
  • Favorites.test.tsx: two regression tests that override the PUT with a hardcoded unwrapped response (add and remove). Both fail on main with the reported error.

Testing

  • nx run mui-favorites:test: 11/11 pass
  • nx run-many -t lint,build -p mui-favorites @availity/mock: pass
  • nx affected -t test lint --base=main: pass

Notes

  • Only the favorites package calls the settings PUT. avatar only uses GET.
  • The OpenAPI spec (docs/openapi.yaml) defines SettingsPutResponse only as { scope } plus additional properties, which is too loose to catch this. Worth raising with the ONB team.
  • After merge, a release should go out as a 3.0.5 patch. Consumers on 3.0.x (for example clip-ui on TST) are broken until then.

The Settings API PUT returns the saved settings object directly ({ favorites, scope }),
not wrapped in a settings array like GET. Read it with its own response type, and
return the unwrapped body from the MSW mock to match the real service.
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Preview deployed!

📖 View Storybook Preview

@jordan-a-young
jordan-a-young merged commit 757414c into main Oct 29, 2026
9 checks passed
github-actions Bot pushed a commit that referenced this pull request Oct 29, 2026
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.

2 participants