test: run the package suites on the supabase_test helpers - #1827
Conversation
… bodies Adds the pieces a test needed a hand-rolled `BaseClient` for: - `stubError` throws instead of answering, so offline and retry handling can be exercised, and `times` limits it to the first requests. - `stubStall` never answers, so only a timeout or an abort ends the request. - `stubStatuses` answers a sequence of statuses, one per request, and repeats the last one once they run out. - `stubText` answers with a body that is not JSON, under its own content type and reason phrase. - `RecordedRequest.request` holds the request the client received, so a multipart upload can be asserted on through its `files`. - The auth shorthands now answer their endpoint at the root as well, where a bare `AuthClient` addresses it, not just under the `/auth/v1` prefix. - `getSessionData` takes the user the session belongs to. Also moves the typed api test off `TableColumn`, which was removed in #1796, so the package suite runs again.
Replaces the hand-rolled `BaseClient` subclasses of the package suites with `MockSupabaseHttpClient` and the fixtures of `supabase_test`, which is what the package tells app authors to use. - 28 mock clients across postgrest, supabase, supabase_auth, supabase_storage, supabase_flutter and supabase_typegen are gone, along with `supabase_storage/test/custom_http_client.dart` and `supabase_auth/test/mocks/sso_mock_client.dart`. - Request assertions run on `requests`, `requestsTo` and `RecordedRequest` instead of per-mock `lastRequest` and `receivedRequests` fields. - `signedTestJwt` replaces `dart_jsonwebtoken` in the three tests that minted their own access tokens, and `testUserJson`, `testSessionResponseJson` and `getSessionData` replace the inline copies of those payloads. - supabase_typegen gains supabase_test as a dev dependency and drops http.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (36)
💤 Files with no reviewable changes (3)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe test suites replace custom HTTP clients with ChangesPostgREST tests
Supabase tests
Authentication tests
Flutter integration tests
Storage tests
Type generation tests
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: Merge Risk: ⚪ Minimal · up to The test-mock migration is mergeable with no active production or test-contract risk identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
… bodies (#1825) Adds the stubbing pieces that the package suites of this repo still hand-roll a `BaseClient` for. Each one comes from a test that could not be expressed with the current surface. ## What is new | Helper | Replaces | |---|---| | `stubError(error, {times})` | clients that `throw ClientException('Offline')` for the first N requests | | `stubStall()` | clients that never answer, so a timeout or an abort ends the request | | `stubStatuses([503, 503, 200])` | clients that walk a retry through a sequence of statuses | | `stubText(body, {statusCode, contentType, reasonPhrase})` | clients returning a non-JSON body, an HTML gateway error for example | | `RecordedRequest.request` | assertions on what does not survive the wire format, such as `MultipartRequest.files` | Two smaller changes in the same vein: - The auth shorthands (`stubSignIn`, `stubSignUp`, `stubSignOut`, `stubUser`) now answer their endpoint at the root too, where a bare `AuthClient` addresses it, and not only under the `/auth/v1` prefix a `SupabaseClient` uses. The bare path is matched exactly, so a table named `user` is not caught by `stubUser`. - `getSessionData` in the internal library takes the user the session belongs to, instead of being pinned to one id. ## Also in here `test/typed_api_test.dart` still used `TableColumn`, which #1796 removed, so `dart analyze` and `dart test` were failing on `main` for this package. It now uses `PostgrestColumn`, which is what the rest of the repo moved to. ## Notes - Everything is additive except the auth shorthand matching, which widens what those four stubs answer. - `supabase_test` is in `.sdk-parse-ignore`, so none of the new symbols need registering in `sdk-compliance.yaml`. - #1827, stacked on this one, moves the package suites onto these helpers and deletes the hand-rolled clients. ## Test plan - `dart test` in `packages/supabase_test`: 88 pass, with new groups covering each helper. - `dart test` in `packages/supabase_auth` (549) and `packages/supabase` (170) pass, covering the `getSessionData` and shorthand matching changes. - `dart analyze` and `dart format` clean.
Stacked on #1825. Review that one first; this PR targets its branch.
supabase_testtells app authors to test against a real client with a stubbed HTTP layer, while the package suites of this repo still hand-rolled aBaseClientper test file. This moves them onto the same helpers, which is both a smaller diff to maintain and a continuous check that the published helpers actually cover real testing needs. Net -604 lines.What changed
28 hand-rolled mock clients removed, replaced by
MockSupabaseHttpClient:filter_escape_test,maybe_single_test,stack_trace_test,typed_query_testapi_key_test,trace_propagation_test,postgrest_options_testadmin_delete_user_test,admin_list_users_test,auto_refresh_dispose_test,client_test,custom_http_client,fetch_test,get_session_test,header_isolation_test,mfa_challenge_mock_test,mfa_enroll_test,refresh_retry_test,refresh_token_race_test,src/set_session_test,sso_mock_testbasic_test,client_test,fetch_test,path_encoding_test,path_normalization_test,vector_testwidget_test_stubs,deep_link_test,initialization_testgenerated_schema_behavior_testTwo shared helper files are deleted outright:
supabase_storage/test/custom_http_client.dartandsupabase_auth/test/mocks/sso_mock_client.dart.supabase_auth/test/custom_http_client.dartlosesMockedHttpClientandRawBodyHttpClient.Assertions move from per-mock
lastRequest,lastRequestBody,receivedRequestsandrequestCountfields ontorequests,requestsToandRecordedRequest, sojsonDecode((request as Request).body)becomesrequest.jsonBody.Fixtures replace inline copies:
signedTestJwtreplacesdart_jsonwebtokenin the three tests that minted access tokens, andtestUserJson,testSessionResponseJsonandgetSessionDatareplace hand-written user and session payloads.Behaviour worth a second look
auto_refresh_dispose_testused a client that calledfail()on any request. It now uses a stubless mock, which throws on an unexpected request, plus an explicitexpect(httpClient.requests, isEmpty)intearDown.header_isolation_testusesstubUser, and its admin case stubs/admin/users/<id>explicitly, since the admin API reads a user through its own endpoint.supabase_typegengainssupabase_testas a dev dependency and dropshttp.Test plan
Per package, against the local stack: supabase_test 88, supabase 170, postgrest 346, supabase_auth 549, supabase_storage 272, supabase_typegen 64, supabase_flutter 85. All pass except
client_test.dart: Signed upload URL cannot upload to a signed url twicein supabase_storage, which fails onmaintoo on a local CLI newer than the pinned 2.109.1 (KeyAlreadyExistsinstead ofDuplicate).dart analyzeanddart formatclean across all packages.Summary by CodeRabbit
Tests
Chores