Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions uts/realtime/unit/connection/connectivity_check_test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Connectivity Check Tests (REC3)

Spec points: `REC3`, `REC3a`, `REC3b`

## Test Type
Unit test with mocked WebSocket client and HTTP client

## Mock Infrastructure

See `uts/realtime/unit/helpers/mock_websocket.md` for the full Mock WebSocket Infrastructure specification.
See `uts/rest/unit/helpers/mock_http.md` for Mock HTTP Client specification.

---

## REC3a - Default connectivity check URL

**Test ID**: `realtime/unit/REC3a/default-connectivity-check-url-0`

Tests that the default connectivity check URL is `https://internet-up.ably-realtime.com/is-the-internet-up.txt`.

### Note
The connectivity check URL is used to verify internet connectivity before attempting to connect.

### Setup
```pseudo
mock_http = MockHttpClient()
# Queue response for connectivity check
mock_http.queue_response_for_url(
"https://internet-up.ably-realtime.com/is-the-internet-up.txt",
200,
"yes"
)

client = Realtime(options: ClientOptions(key: "appId.keyId:keySecret"))
```

### Test Steps
```pseudo
# Trigger connectivity check (implementation-specific)
# Some libraries expose this, others do it internally
result = AWAIT client.connection.checkConnectivity()
# OR: observe that connectivity check request was made during connection
```

### Assertions
```pseudo
connectivity_requests = mock_http.captured_requests.filter(
r => r.url.path CONTAINS "is-the-internet-up"
)
ASSERT connectivity_requests.length >= 1
ASSERT connectivity_requests[0].url.toString() == "https://internet-up.ably-realtime.com/is-the-internet-up.txt"

CLOSE_CLIENT(client)
```

---

## REC3b - Custom connectivity check URL

**Test ID**: `realtime/unit/REC3b/custom-connectivity-check-url-0`

Tests that the `connectivityCheckUrl` option overrides the default.

### Setup
```pseudo
mock_http = MockHttpClient()
mock_http.queue_response_for_url(
"https://custom.example.com/connectivity",
200,
"ok"
)

client = Realtime(options: ClientOptions(
key: "appId.keyId:keySecret",
connectivityCheckUrl: "https://custom.example.com/connectivity"
))
```

### Test Steps
```pseudo
result = AWAIT client.connection.checkConnectivity()
```

### Assertions
```pseudo
connectivity_requests = mock_http.captured_requests.filter(
r => r.url.host == "custom.example.com"
)
ASSERT connectivity_requests.length >= 1
ASSERT connectivity_requests[0].url.toString() == "https://custom.example.com/connectivity"

# Should NOT request the default URL
default_requests = mock_http.captured_requests.filter(
r => r.url.host == "internet-up.ably-realtime.com"
)
ASSERT default_requests.length == 0

CLOSE_CLIENT(client)
```

---

## REC3 - Connectivity check response validation

**Test ID**: `realtime/unit/REC3/connectivity-check-validation-0`

Tests that the connectivity check expects a specific response.

### Test Cases

| ID | Response | Expected Result |
|----|----------|-----------------|
| 1 | HTTP 200 with body "yes" | Connected |
| 2 | HTTP 200 with body "no" | Not connected |
| 3 | HTTP 200 with empty body | Not connected |
| 4 | HTTP 404 | Not connected |
| 5 | Network error | Not connected |

### Setup (Case 1 - Success)
```pseudo
mock_http = MockHttpClient()
mock_http.queue_response_for_url(
"https://internet-up.ably-realtime.com/is-the-internet-up.txt",
200,
"yes"
)

client = Realtime(options: ClientOptions(key: "appId.keyId:keySecret"))
result = AWAIT client.connection.checkConnectivity()

ASSERT result == true

CLOSE_CLIENT(client)
```

### Setup (Case 2 - Wrong body)
```pseudo
mock_http = MockHttpClient()
mock_http.queue_response_for_url(
"https://internet-up.ably-realtime.com/is-the-internet-up.txt",
200,
"no"
)

client = Realtime(options: ClientOptions(key: "appId.keyId:keySecret"))
result = AWAIT client.connection.checkConnectivity()

ASSERT result == false

CLOSE_CLIENT(client)
```

### Setup (Case 4 - HTTP error)
```pseudo
mock_http = MockHttpClient()
mock_http.queue_response_for_url(
"https://internet-up.ably-realtime.com/is-the-internet-up.txt",
404,
"Not Found"
)

client = Realtime(options: ClientOptions(key: "appId.keyId:keySecret"))
result = AWAIT client.connection.checkConnectivity()

ASSERT result == false

CLOSE_CLIENT(client)
```
8 changes: 8 additions & 0 deletions uts/rest/unit/channel/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ ASSERT "id" NOT IN annotation

## RSAN2a — delete sends POST with ANNOTATION_DELETE

**Test ID**: `rest/unit/RSAN2a/delete-post-annotation-delete-0`

**Spec requirement:** RSAN2a — Must be identical to RSAN1 `publish()` except that the `Annotation.action` is set to `ANNOTATION_DELETE`, not `ANNOTATION_CREATE`.

Tests that `annotations.delete()` sends a POST with the delete action.
Expand Down Expand Up @@ -330,6 +332,8 @@ ASSERT annotation["name"] == "like"

## RSAN3b — get sends GET to correct endpoint

**Test ID**: `rest/unit/RSAN3b/get-sends-get-0`

| Spec | Requirement |
|------|-------------|
| RSAN3b | Sends a GET request to `/channels/{channelName}/messages/{messageSerial}/annotations` |
Expand Down Expand Up @@ -381,6 +385,8 @@ ASSERT request.url.path == "/channels/" + encode_uri_component(channel_name) + "

## RSAN3c — get returns PaginatedResult of Annotations

**Test ID**: `rest/unit/RSAN3c/get-returns-paginated-result-0`

**Spec requirement:** RSAN3c — Returns a `PaginatedResult<Annotation>` page containing the first page of decoded `Annotation` objects.

Tests that the response is parsed into a paginated result of annotations with all fields.
Expand Down Expand Up @@ -458,6 +464,8 @@ ASSERT ann2.clientId == "user-2"

## RSAN3b — get passes params as querystring

**Test ID**: `rest/unit/RSAN3b/get-params-querystring-1`

**Spec requirement:** RSAN3b — Any `params` are sent in the querystring.

Tests that optional params are sent as query parameters.
Expand Down
2 changes: 1 addition & 1 deletion uts/rest/unit/channel/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Unit test with mocked HTTP client

## Mock HTTP Infrastructure

These tests use the mock HTTP infrastructure defined in `/Users/paddy/data/worknew/dev/dart-experiments/uts/rest/unit/rest_client.md`.
These tests use the mock HTTP infrastructure defined in `uts/rest/unit/rest_client.md`.

The mock must support:
- Handler-based configuration with `onConnectionAttempt` and `onRequest` callbacks
Expand Down
2 changes: 1 addition & 1 deletion uts/rest/unit/channel/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Unit test with mocked HTTP client

## Mock HTTP Infrastructure

These tests use the mock HTTP infrastructure defined in `/Users/paddy/data/worknew/dev/dart-experiments/uts/rest/unit/rest_client.md`.
These tests use the mock HTTP infrastructure defined in `uts/rest/unit/rest_client.md`.

The mock must support:
- Handler-based configuration with `onConnectionAttempt` and `onRequest` callbacks
Expand Down
2 changes: 1 addition & 1 deletion uts/rest/unit/channel/publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Unit test with mocked HTTP client

## Mock HTTP Infrastructure

These tests use the mock HTTP infrastructure defined in `/Users/paddy/data/worknew/dev/dart-experiments/uts/rest/unit/rest_client.md`.
These tests use the mock HTTP infrastructure defined in `uts/rest/unit/rest_client.md`.

The mock must support:
- Handler-based configuration with `onConnectionAttempt` and `onRequest` callbacks
Expand Down
2 changes: 1 addition & 1 deletion uts/rest/unit/channels_collection.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REST Channels Collection Tests

Spec points: `RSN1`, `RSN2`, `RSN3a`, `RSN3b`, `RSN3c`, `RSN4a`, `RSN4b`
Spec points: `RSN1`, `RSN2`, `RSN3a`, `RSN4a`, `RSN4b`

## Test Type
Unit test - no network calls required
Expand Down
2 changes: 1 addition & 1 deletion uts/rest/unit/encoding/message_encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Unit test with mocked HTTP client

## Mock HTTP Infrastructure

These tests use the mock HTTP infrastructure described in `/Users/paddy/data/worknew/dev/dart-experiments/uts/rest/unit/rest_client.md`.
These tests use the mock HTTP infrastructure described in `uts/rest/unit/rest_client.md`.

The mock supports:
- Intercepting HTTP requests and capturing details (URL, headers, method, body)
Expand Down
4 changes: 4 additions & 0 deletions uts/rest/unit/encoding/msgpack_interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ field in the fixture describes the expected decoded content of that message.

## RSL6a3 - Decode binary-encoded protocol messages using interop fixtures

**Test ID**: `rest/unit/RSL6a3/msgpack-fixtures-decode-0`

**Spec requirement:** A set of tests should exist to ensure that the client library
can successfully encode and decode binary encoded protocol messages.

Expand Down Expand Up @@ -82,6 +84,8 @@ END

## RSL6a3 - Re-encode decoded messages back to msgpack (round-trip)

**Test ID**: `rest/unit/RSL6a3/msgpack-fixtures-round-trip-1`

### Test: each fixture round-trips through encode/decode
```pseudo
FOR EACH fixture IN fixtures:
Expand Down
Loading
Loading