Skip to content

fix(profiles): getUser declared a bare body for a route that wraps, and #26 lost its mock - #29

Merged
thinkclay merged 1 commit into
mainfrom
fix/744-getuser-envelope
Sep 11, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/744-getuser-envelope

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Two things, one of them mine to own.

#26's mock correction never landed

That PR changed four files; src/__tests__/mocks/server.ts was not among them.

While proving the new assertions actually bite, I temporarily reverted industry to a string, ran the suite, and restored the file with git checkout -- — which restores from HEAD, not from my edit. So it discarded the correction rather than the experiment. I then committed without re-running the full suite.

The result has been sitting on main. With no changes at all:

$ npx vitest run src/__tests__/profiles.test.ts
Tests  6 failed | 3 passed (9)

The corrected assertions have been running against the old bare mock. The organization handler is restored here — wrapped in { data }, description a rich-text document, industry the embedded row, address structured, no size/location/founded_year.

I should have re-run the suite after a destructive git checkout --; that is the lesson, and it is why the envelope assertion below exists.

getUser had the same defect as getOrganization

GET /v1/profiles/{username} wraps its payload in { data }, and the http client returns the body verbatim, so the method resolves to { data: UserProfile } while declaring the profile bare. Its msw handler returned the payload bare too — so the suite agreed with the type, and neither was checked against the wire.

Confirmed against the running api rather than inferred: the live response is { data: { … } }.

Corrected: the method signature, the hook generic, the mock, and the assertions. tsc rejected the old UseQueryOptions<UserProfile> the moment the method stopped lying — the same way it caught getOrganization.

One new assertion checks the envelope itself:

expect(Object.keys(res)).toEqual(['data'])
expect(res).not.toHaveProperty('username')

so a silent revert to a bare body fails loudly instead of yielding undefined.

A correction to what I wrote on Scaffald/SaaS#744

I said getUser "has consumers" and that any of them would be reading undefined. It does not. The screens that import a hook named useUserProfile import it from user-profiles-sdk-hooks — a different resource (/v1/user-profiles) that happens to export a same-named hook. The only importer of profiles-sdk-hooks is the barrel.

So this is latent, not live. The issue is being updated.

Verified

tsc --noEmit clean; 777 tests across 36 files pass.

Refs Scaffald/SaaS#744

#26 lost its mock

Two things, one of them mine to own.

**The mock correction from #26 never landed.** That PR changed four files;
src/__tests__/mocks/server.ts was not among them. While proving the new
assertions actually bite, I temporarily reverted `industry` to a string, ran the
suite, and restored the file with `git checkout --` — which restores from HEAD,
not from my edit, so it discarded the correction rather than the experiment. I
committed without re-running the full suite.

The result has been sitting on main: the corrected assertions run against the
old bare mock, and `vitest run src/__tests__/profiles.test.ts` is 6 failed |
3 passed with no changes at all. The organization handler is restored here —
wrapped in `{ data }`, `description` a rich-text document, `industry` the
embedded row, `address` structured, and no size/location/founded_year.

**getUser had the same defect getOrganization did.** `GET /v1/profiles/{username}`
wraps its payload in `{ data }` and the http client returns the body verbatim,
so the method resolves to `{ data: UserProfile }` while declaring the profile
bare. Its msw handler returned the payload bare too, so the suite agreed with
the type and neither was checked against the wire.

Confirmed against the running api rather than inferred — the live response is
`{ data: { ... } }`.

Corrected here: the method signature, the hook generic (tsc rejected the old
`UseQueryOptions<UserProfile>` the moment the method stopped lying), the mock,
and the assertions. One new assertion checks the envelope itself —
`Object.keys(res)` is exactly `['data']` — so a silent revert to a bare body
fails loudly instead of yielding undefined.

A correction to what I wrote on Scaffald/SaaS#744: I said getUser "has
consumers" and that any of them would be reading undefined. It does not. The
screens that import a hook named `useUserProfile` import it from
`user-profiles-sdk-hooks`, which is a different resource (`/v1/user-profiles`).
The only importer of `profiles-sdk-hooks` is the barrel. This is latent, not
live.

tsc clean; 777 tests across 36 files pass.

Refs Scaffald/SaaS#744

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay force-pushed the fix/744-getuser-envelope branch from 6f47ebe to 221e72d Compare September 11, 2026 16:24
@thinkclay

Copy link
Copy Markdown
Contributor Author

Rebased onto #28, which fixed the org mock independently — I took that version wholesale. What remains here is only the getUser half: the method signature, the hook generic, the mock wrap, and the assertions, plus the Object.keys(res) check on the envelope itself.

The #26 lost its mock section of the description is now historical rather than something this PR fixes. 777/777.

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