Skip to content

refactor: introduce IHttpClient seam for testable auth#22

Merged
Taure merged 1 commit into
mainfrom
feat/http-client-seam
Jul 14, 2026
Merged

refactor: introduce IHttpClient seam for testable auth#22
Taure merged 1 commit into
mainfrom
feat/http-client-seam

Conversation

@Taure

@Taure Taure commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Introduces an IHttpClient seam so AsobiAuth can be unit-tested without a live backend, and adds the first network-free auth tests.

Why

AsobiAuth called a concrete HttpClient (UnityWebRequest) with no injection point, so the only coverage of auth request shape + token-storage side effects was the live-backend PlayMode SmokeTest. There was no way to assert "login stores the returned tokens" or "an error status does not store tokens" in CI without a server.

What

  • New internal interface IHttpClient declaring the exact public surface HttpClient already exposes (Get/Post/PostJson/Put/PutJson/GetRaw/PutRaw/Delete + AccessToken). HttpClient now implements it.
  • AsobiClient.Http is typed IHttpClient; a new internal AsobiClient(AsobiConfig, IHttpClient) constructor lets tests inject a fake. The public constructor delegates to it with the real HttpClient, so nothing changes for consumers.
  • The 16 Asobi* API classes are untouched - they already call methods that live on the interface.
  • Tests/Runtime/AsobiAuthTests.cs (EditMode): a FakeHttpClient records the last path/body and returns canned responses. Covers login credential shape + token storage + token propagation to the HTTP layer, register display-name defaulting, OAuth token storage, and that a 401 aborts without storing tokens.

Notes

  • These are Unity EditMode tests (they use PlayerPrefs via AsobiClient), so CI's EditMode runner executes them with no backend - unlike the PlayMode smoke. They are not headless-dotnet runnable because the runtime depends on UnityEngine.
  • InternalsVisibleTo("Asobi.Tests") was already present, so the fake sees the internal interface.
  • Independent of the guest-auth PR (feat: add guest auth (device create-or-resume + upgrade) #21); both follow the identical auth pattern and compose cleanly.

Local validation

Unity/IL2CPP can't build headless in this environment; verified by careful review that the interface matches HttpClient's signatures exactly and that no .Http. member used anywhere falls outside it. CI validates the full build + EditMode run.

@Taure
Taure merged commit 8c46a6a into main Jul 14, 2026
3 checks passed
@Taure
Taure deleted the feat/http-client-seam branch July 14, 2026 19:20
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