supabase_test library
Test helpers for apps and packages built on the Supabase clients.
Holds the mock HTTP clients, JWT builders, auth fixtures and realtime frames that the test suites of the client packages themselves run on, published so that apps can test code that talks to Supabase without a running stack.
Everything here is annotated with @visibleForTesting, so the analyzer
warns when a helper leaks outside of test code.
Classes
- FailingHttpClient
- A mock HTTP client that answers every request with an empty body and the recognizable status code 420, so a test can assert this client was the one used.
- JsonResponseMockClient
- A mock HTTP client that answers every request with the same JSON body.
- MockSupabaseHttpClient
- A mock HTTP client that answers Supabase requests from stubs registered per endpoint, and records every request it answered in requests.
- RecordedRequest
- A request a MockSupabaseHttpClient has answered, with its body already read, so a test can assert on what the code under test sent.
Constants
- sessionDataUserId → const String
- User id embedded in the session produced by getSessionData.
- testUserId → const String
- Id of the user testUserJson describes.
-
todoColumns
→ const List<
Map< String, Object> > -
Column description of the
todosfixture table, as the realtime server reports it in apostgres_changesevent.
Functions
-
decodeTestJwtClaims(
String jwt) → Map< String, dynamic> -
Decodes the claims of
jwtwithout verifying its signature, for asserting on tokens the code under test produced or sent. -
getSessionData(
DateTime expireDateTime) → ({String accessToken, String sessionString}) - Constructs session data for a given expiration date.
-
jsonStreamedResponse(
Object? body, {int statusCode = 200, BaseRequest? request, Map< String, String> headers = const {}, String? reasonPhrase}) → StreamedResponse -
A
StreamedResponsewithbodyencoded as JSON and a matching content type. -
postgresChangesFrame(
Object? topic, {required List< int> ids, required Map<String, dynamic> data}) → String -
A protocol 2.0.0
postgres_changestext frame, which is a positional array of[join_ref, ref, topic, event, payload], encoded as JSON. -
signedTestJwt(
Map< String, dynamic> claims, {required String secret}) → String -
Crafts an HS256 JWT carrying exactly
claims, signed withsecret. -
signInTestUser(
AuthClient auth, {String userId = testUserId, String email = 'fake1@email.com', String role = 'authenticated', Map< String, dynamic> claims = const {}, DateTime? expiresAt}) → Future<Session> -
Puts
authinto a signed-in state without any network traffic, and returns the resulting session. -
stallUntilAborted(
BaseRequest request) → Future< StreamedResponse> -
Never answers, so only completing
request's abort trigger, which surfaces as aRequestAbortedException, ends the request. -
testSessionResponseJson(
{required String accessToken, String refreshToken = 'tDoDnvj5MKLuZOQ65KyVfQ', Map< String, dynamic> ? user}) → Map<String, dynamic> -
The JSON form of a token endpoint response carrying
accessTokenanduser, which defaults to testUserJson. -
testSupabaseClient(
{Client? httpClient, String url = 'http://localhost:54321', String? apiKey, bool autoRefreshToken = false}) → SupabaseClient -
A
SupabaseClientwired for tests. -
testUserJson(
{String id = testUserId, String email = 'fake1@email.com', String phone = '166600000000'}) → Map< String, dynamic> - The JSON form of a fixed test user carrying an unverified TOTP factor and an email identity, as the auth server would return it.
-
unsignedTestJwt(
Map< String, dynamic> claims) → String -
Crafts a JWT by base64url-encoding
claimsdirectly.