Skip to content

refactor(supabase_test)!: take HttpMethod for method matching and align names with supabase_flutter's testing helpers - #2025

Merged
spydon merged 4 commits into
mainfrom
lukasklingsbo/sdk-2358-refactorsupabase_test-take-httpmethod-for-method-matching
Oct 23, 2026
Merged

spydon merged 4 commits into
mainfrom
lukasklingsbo/sdk-2358-refactorsupabase_test-take-httpmethod-for-method-matching

Conversation

@spydon

@spydon spydon commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Linear: https://linear.app/supabase/issue/SDK-2358/refactorsupabase-test-take-httpmethod-for-method-matching-and-align

Changes

  • method: takes HttpMethod. stub, stubText, stubError, stubStall, stubStatuses, stubHandler, stubTable and requestsTo now take HttpMethod? instead of a raw String, so a typo no longer compiles. Every call site in the workspace, the README, the example, the skill and AGENTS.md moved from HttpMethod.post.value (or 'POST') to HttpMethod.post. RecordedRequest.method stays a String, since it is what went over the wire. package:supabase_test re-exports HttpMethod, so a test that imports only supabase_test and, for example, supabase_storage can still call these methods.
  • testSupabaseClient and initializeTestSupabase take the same parameter names. apiKey became publishableKey, and realtime: MockRealtimeTransport became realtimeTransport: WebSocketTransport, matching initializeTestSupabase. A mock transport is passed as realtimeTransport: realtime.call in both places.
  • The default key is an sb_publishable_ key in both helpers (testPublishableKey in supabase_flutter/testing.dart is now a const). Signed-out requests now carry the headers a production publishable key produces. publishableKey stays nullable in both, and null falls back to the default.
  • MIGRATION.md gets a short "Testing" section covering the renames and the new default key.

Notes for review

  • Decision: realtimeTransport is typed WebSocketTransport in both helpers. supabase_flutter cannot depend on supabase_test, and the core implicit_call_tearoffs lint flags passing the mock object directly. Keeping MockRealtimeTransport in testSupabaseClient would leave the two signatures different, so both now take WebSocketTransport and callers write realtime.call in both places. The trade-off is that .call is now also needed with testSupabaseClient.
  • The ticket's claim about the Authorization header is only partly right. SupabaseClient sets omitNewApiKeyAsBearer only on the functions HTTP client (packages/supabase/lib/src/supabase_client.dart:129-134). PostgREST, storage and auth requests still send Authorization: Bearer <publishable key> when signed out. The new default still makes header assertions match production, and the regression tests pin both behaviors: REST sends the bearer, functions leave it out.
  • supabase_test and supabase_flutter/testing.dart are excluded from the compliance scan, so sdk-compliance.yaml is unchanged.
  • Left out on purpose: supabase_test keeps its default key private, because a public testPublishableKey would clash with the one supabase_flutter/testing.dart exports when a test imports both.

Tests

  • A stub registered for one method does not answer another, and the error names both.
  • HttpMethod is usable with only package:supabase_test imported.
  • testSupabaseClient defaults to an sb_publishable_ key: REST sends it as the bearer token, a function invocation does not. A custom publishableKey and a realtimeTransport are passed through.
  • initializeTestSupabase sends a signed-out function call with the key only as apikey.

Summary by CodeRabbit

  • New Features
    • Test utilities now support HTTP method enums for configuring and matching requests, and expose HttpMethod through the testing package.
    • Test client helpers now use publishable test keys and accept configurable realtime transports.
  • Documentation
    • Updated testing guides with the new request-mocking, key, and realtime transport examples.
  • Bug Fixes
    • Clarified signed-out Edge Function request behavior: publishable keys are sent without an Authorization header.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 875ea12 and b9791d1.

📒 Files selected for processing: 34
  • AGENTS.md
  • MIGRATION.md
  • packages/supabase/test/client_authorization_test.dart
  • packages/supabase/test/realtime_access_token_test.dart
  • packages/supabase/test/stream_insert_test.dart
  • packages/supabase/test/stream_order_test.dart
  • packages/supabase/test/stream_select_test.dart
  • packages/supabase/test/typed_postgres_changes_test.dart
  • packages/supabase/test/typed_table_schema_test.dart
  • packages/supabase_auth/test/admin_sso_test.dart
  • packages/supabase_auth/test/admin_update_factor_test.dart
  • packages/supabase_auth/test/refresh_token_ownership_test.dart
  • packages/supabase_auth/test/refresh_transient_failure_test.dart
  • packages/supabase_auth/test/update_user_race_test.dart
  • packages/supabase_flutter/lib/testing.dart
  • packages/supabase_flutter/test/restore_credential_test.dart
  • packages/supabase_flutter/test/supabase_flutter_test.dart
  • packages/supabase_flutter/test/testing_test.dart
  • packages/supabase_storage/test/basic_test.dart
  • packages/supabase_storage/test/fetch_test.dart
  • packages/supabase_storage/test/resumable_upload_test.dart
  • packages/supabase_test/README.md
  • packages/supabase_test/example/supabase_test_example.dart
  • packages/supabase_test/lib/src/mock_realtime_transport.dart
  • packages/supabase_test/lib/src/mock_supabase_http_client.dart
  • packages/supabase_test/lib/src/test_supabase_client.dart
  • packages/supabase_test/lib/supabase_test.dart
  • packages/supabase_test/skills/supabase-test-testing/SKILL.md
  • packages/supabase_test/test/exports_test.dart
  • packages/supabase_test/test/mock_realtime_transport_test.dart
  • packages/supabase_test/test/mock_supabase_http_client_test.dart
  • packages/supabase_test/test/test_supabase_client_test.dart
  • packages/supabase_test/test/typed_api_test.dart
  • skills_src/testing/SKILL.md.tmpl
💤 Files with no reviewable changes: 2
  • packages/supabase_storage/test/fetch_test.dart
  • packages/supabase_storage/test/basic_test.dart

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

📝 Walkthrough

The test utilities now use HttpMethod values for mock registration and request filtering. testSupabaseClient now accepts a publishable key and a realtime transport callback. Its default key and signed-out request headers are covered by tests and updated guidance.

Changes: Supabase test utilities

Layer / File(s) Summary
Typed HTTP method matching
packages/supabase_test/lib/src/mock_supabase_http_client.dart, packages/supabase_test/lib/supabase_test.dart, packages/supabase_test/test/*, packages/supabase*/test/*, packages/supabase_flutter/test/*, packages/supabase_storage/test/*, packages/supabase_test/example/*, packages/supabase_test/README.md, AGENTS.md, skills_src/testing/*, packages/supabase_test/skills/*
Mock stub registration and request filtering now accept HttpMethod values. The package re-exports HttpMethod, and tests and examples use enum values for method matching.
Test client key and transport setup
packages/supabase_test/lib/src/test_supabase_client.dart, packages/supabase_flutter/lib/testing.dart, packages/supabase*/test/*, packages/supabase_flutter/test/testing_test.dart, packages/supabase_test/test/*, packages/supabase_test/README.md, packages/supabase_test/skills/*, skills_src/testing/*, MIGRATION.md
testSupabaseClient replaces apiKey with publishableKey and realtime with realtimeTransport. Its default key uses the sb_publishable_ prefix. Tests check REST and Edge Function request headers and the realtime URL. Documentation describes the updated parameters and behavior.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to b9791

The updated test helpers and their callers are consistent, with no identified issue that needs resolution before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main API refactor: method matching now uses HttpMethod, and testing helper names are aligned with supabase_flutter. It is specific and related to the changeset.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (32 skipped: 32 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@spydon
spydon force-pushed the lukasklingsbo/sdk-2358-refactorsupabase_test-take-httpmethod-for-method-matching branch from e48fcbc to b9791d1 Compare October 23, 2026 09:29
@spydon
spydon merged commit 941320d into main Oct 23, 2026
50 checks passed
@spydon
spydon deleted the lukasklingsbo/sdk-2358-refactorsupabase_test-take-httpmethod-for-method-matching branch October 23, 2026 09:40
spydon added a commit that referenced this pull request Oct 23, 2026
…#2045)

#2025 changed the `method:` parameter of
`MockSupabaseHttpClient.requestsTo` and the stub helpers to take an
`HttpMethod`. #2018 and #2019 were tested against main without that
change and pass `HttpMethod.x.value`, so after all three merged, main no
longer analyzes in `supabase_storage` and `supabase_flutter_web_auth`.
This passes the enum value at those five call sites.

Related: https://linear.app/supabase/issue/SDK-2358

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

- **Tests**
- Updated request-method checks in authentication and storage test
coverage to use consistent method representations. These changes affect
test validation only; application behavior, supported operations, and
expected request outcomes remain unchanged. The existing scenarios
continue to verify the same requests and outcomes. No end-user-facing
functionality or interface changes are included in this update.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
spydon added a commit that referenced this pull request Oct 23, 2026
…anges met (#2046)

Three combinations of PRs that were each green on their own broke main.

- `supabase_auth`: #2027 added `pkce_failed_request_test.dart` passing
`HttpMethod.x.value`, but #2025 changed `requestsTo` and the stub
helpers to take an `HttpMethod`, so the package no longer analyzes.
- `supabase_test`: since #2027, a local `signOut()` revokes the session
in the background. The `stubSignOut` test looked for the `/logout`
request right after `signOut()` returned, so it now waits for the event
queue first.
- `supabase_typegen`: #2020 added a `badge` table to the hostile
fixture, and #2044 suffixes generated names that clash with Flutter
types, so the class is now `BadgeTable`. The hostile golden is
regenerated, and the tests that reference the class use the new name.
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