Skip to content

test(examples): add full e2e suite for Edge Functions#1633

Merged
spydon merged 1 commit into
mainfrom
examples/edge-functions-e2e
Jul 22, 2026
Merged

test(examples): add full e2e suite for Edge Functions#1633
spydon merged 1 commit into
mainfrom
examples/edge-functions-e2e

Conversation

@spydon

@spydon spydon commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1632. Review and merge that first; this PR targets its branch and the diff below is only the test suite.

What

Adds a full end-to-end integration test suite for the edge_functions example, covering the entire surface of functions.invoke.

integration_test/invoke_test.dart exercises:

Request

  • POST with a JSON body (decoded on the round trip)
  • GET with query parameters
  • Every HttpMethod (GET, POST, PUT, DELETE, PATCH)
  • Custom headers
  • String body sent as text/plain
  • Uint8List body sent as binary
  • MultipartFile uploads (files:) with form fields
  • region (adds the forceFunctionRegion query and x-region header)

Response

  • JSON decoded to a Map
  • text/plain as a String
  • application/octet-stream as a Uint8List
  • text/event-stream as a readable ByteStream (SSE)
  • Non-200 success status on FunctionResponse.status

Errors

  • FunctionsHttpException on a non-2xx JSON response (Map in details)
  • FunctionsHttpException on a non-2xx text response (String in details)
  • FunctionsFetchException when the function is unreachable

Abort

  • An already-completed abortSignal cancels the request (RequestAbortedException)
  • An abortSignal used as a request timeout

How

The suite drives a new echo test-support function (examples/supabase/functions/echo) that reflects the request back in whatever shape a query parameter asks for (JSON reflection, text, binary, SSE, or a chosen status code). It is not used by the example UI and has verify_jwt = false like the other demo functions.

Testing

  • dart format . and flutter analyze are clean.
  • The suite was run against the local stack (supabase start) on web (Chrome 150) via flutter drive: all tests passed, including the binary, multipart, SSE ByteStream and abort cases.

Summary by CodeRabbit

  • Tests

    • Added comprehensive end-to-end coverage for Edge Function invocation, including request methods, payload formats, headers, regions, response types, errors, timeouts, and cancellation.
    • Updated integration test documentation and commands to run the full test suite.
  • New Features

    • Added an echo Edge Function for validating JSON, text, binary, multipart, streaming, and error responses.
    • Added configuration for the new echo function.

@spydon
spydon requested a review from a team as a code owner July 22, 2026 09:07
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a3232c92-768d-4efd-a3ee-5b7e34119500

📥 Commits

Reviewing files that changed from the base of the PR and between 0b44b5a and 3d9c10a.

📒 Files selected for processing (4)
  • examples/edge_functions/README.md
  • examples/edge_functions/integration_test/invoke_test.dart
  • examples/supabase/config.toml
  • examples/supabase/functions/echo/index.ts

📝 Walkthrough

Walkthrough

Adds a local echo Edge Function and a Dart integration suite covering functions.invoke request encoding, response decoding, errors, region routing, and abort behavior. Documentation now runs all integration tests.

Changes

Edge Functions invocation coverage

Layer / File(s) Summary
Echo function test support
examples/supabase/config.toml, examples/supabase/functions/echo/index.ts
Registers an unauthenticated echo function that reflects requests and produces JSON, text, binary, SSE, and error responses.
Invocation setup and request coverage
examples/edge_functions/integration_test/invoke_test.dart
Initializes the local Supabase client and tests HTTP methods, body formats, multipart uploads, custom headers, and region routing.
Response, error, and abort validation
examples/edge_functions/integration_test/invoke_test.dart, examples/edge_functions/README.md
Tests response decoding, status propagation, exception payloads, unreachable endpoints, abort behavior, and execution of the complete integration-test directory.

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

Sequence Diagram(s)

sequenceDiagram
  participant TestSuite
  participant FunctionsClient
  participant LocalSupabase
  participant EchoFunction
  TestSuite->>FunctionsClient: invoke echo with request options
  FunctionsClient->>LocalSupabase: send encoded request
  LocalSupabase->>EchoFunction: forward method, headers, query, and body
  EchoFunction-->>LocalSupabase: return encoded response or error
  LocalSupabase-->>FunctionsClient: return decoded response or exception
  FunctionsClient-->>TestSuite: expose result, status, stream, or abort error
Loading

Possibly related PRs

  • supabase/supabase-flutter#1632: Extends the same edge functions example setup with the echo function, invocation integration tests, and documentation updates.

Suggested labels: functions

Suggested reviewers: tr00d

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: a full end-to-end test suite for the Edge Functions example.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch examples/edge-functions-e2e

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 examples/edge-functions-e2e branch 3 times, most recently from b3d9dfe to aecde9a Compare July 22, 2026 09:36
spydon added a commit that referenced this pull request Jul 22, 2026
## What

Adds an `edge_functions` example under `examples/`, following the same
structure as `database_crud` and `storage_transforms`. It demonstrates
invoking Supabase Edge Functions with `supabase.functions.invoke(...)`:

- **JSON body over POST**, reading the JSON response back
(`invoke('greet', body: {...})`).
- **GET with query parameters** instead of a body (`method:
HttpMethod.get, queryParameters: {...}`).
- **Custom headers** sent to the function and echoed back (`headers:
{...}`).
- **Plain text in and out**: a `String` body is sent as `text/plain` and
the `text/plain` response arrives as a `String` (`invoke('shout', body:
text)`).
- **Error handling**: a non-2xx response throws a `FunctionException`
whose `details` carry the response body (`invoke('word-count', ...)`).

## How it's structured

- All Edge Function access lives in `lib/functions_repository.dart`
(`FunctionsRepository`), kept separate from the UI so the calls are easy
to read and to drive from tests. Models with `factory fromJson` live in
`lib/models.dart`. The Material 3 UI in `lib/main.dart` stays thin.
- Three demo functions ship under `examples/supabase/functions/`:
`greet`, `shout` and `word-count`.
- The Edge Runtime is enabled in `examples/supabase/config.toml`;
`supabase start` serves the functions automatically. The demo functions
set `verify_jwt = false` so the example can call them with just the
publishable key, matching the other examples which run unauthenticated.
- The new package is registered in the workspace `pubspec.yaml` and
listed in `examples/README.md`.

## Testing

- `dart format .` and `flutter analyze` are clean.
- `integration_test/functions_test.dart` was run against the local stack
(`supabase start`) on web (Chrome 150) via `flutter drive`: **all tests
passed**. It covers the repository flow (JSON greeting over POST and
GET, plain-text transform, and a 400 validation error surfacing as a
`FunctionException`) plus a UI smoke test.

A stacked PR (#1633) adds a full end-to-end suite covering the entire
`functions.invoke` surface.

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

## Summary by CodeRabbit

- **New Features**
  - Added a Flutter example demonstrating Supabase Edge Functions.
- Added greeting, plain-text transformation, and word-count function
examples.
- Added support for POST requests, query parameters, custom headers, and
error handling.
- Enabled the example to run in the browser and against the local stack.

- **Documentation**
- Added setup, usage, project structure, and integration testing
instructions.

- **Tests**
- Added end-to-end coverage for function responses, validation errors,
and UI interactions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Base automatically changed from examples/edge-functions to main July 22, 2026 09:42
Add integration_test/invoke_test.dart covering the whole surface of
functions.invoke: every HTTP method, query parameters, custom headers,
JSON/text/binary/multipart request bodies and a region; every response
type (JSON, text, binary and an SSE ByteStream); custom status codes; the
three FunctionException variants; and request aborting.

The suite drives a new echo test-support function that reflects the
request back in whatever shape a query parameter asks for. It is not used
by the example UI and has verify_jwt disabled like the other demo
functions.
@spydon
spydon force-pushed the examples/edge-functions-e2e branch from aecde9a to 3d9c10a Compare July 22, 2026 11:11
@spydon
spydon enabled auto-merge (squash) July 22, 2026 11:12
@spydon
spydon merged commit a95b869 into main Jul 22, 2026
24 checks passed
@spydon
spydon deleted the examples/edge-functions-e2e branch July 22, 2026 14:05
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.

2 participants