refactor: introduce IHttpClient seam for testable auth#22
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces an
IHttpClientseam soAsobiAuthcan be unit-tested without a live backend, and adds the first network-free auth tests.Why
AsobiAuthcalled a concreteHttpClient(UnityWebRequest) with no injection point, so the only coverage of auth request shape + token-storage side effects was the live-backend PlayModeSmokeTest. 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
internal interface IHttpClientdeclaring the exact public surfaceHttpClientalready exposes (Get/Post/PostJson/Put/PutJson/GetRaw/PutRaw/Delete+AccessToken).HttpClientnow implements it.AsobiClient.Httpis typedIHttpClient; a newinternal AsobiClient(AsobiConfig, IHttpClient)constructor lets tests inject a fake. The public constructor delegates to it with the realHttpClient, so nothing changes for consumers.Asobi*API classes are untouched - they already call methods that live on the interface.Tests/Runtime/AsobiAuthTests.cs(EditMode): aFakeHttpClientrecords 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
PlayerPrefsviaAsobiClient), so CI's EditMode runner executes them with no backend - unlike the PlayMode smoke. They are not headless-dotnetrunnable because the runtime depends on UnityEngine.InternalsVisibleTo("Asobi.Tests")was already present, so the fake sees the internal interface.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.