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
2 changes: 2 additions & 0 deletions uts/docs/writing-test-specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ ASSERT request.url.path CONTAINS "/channels/"

Use `toJson()` and `fromJson()` as the portable pseudocode names for serializing to and deserializing from wire format. These are language-agnostic — implementations will map them to the appropriate mechanism (e.g., `toMap()`/`fromMap()` in Dart, `toJSON()`/`fromJSON()` in JavaScript, `to_dict()`/`from_dict()` in Python).

A `toJson()` assertion is made against the wire body, and `fromJson()` consumes the wire body. Assert fields using their wire encoding, not a language model's representation — for example, presence and message actions are asserted as their enum ordinal (e.g. `2` for `ENTER`), not the string name.

```pseudo
# Serializing to wire format
json_data = message.toJson()
Expand Down
13 changes: 3 additions & 10 deletions uts/rest/unit/presence/rest_presence.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mock_http = MockHttpClient(
captured_requests.push(req)
req.respond_with(200, [
{ "action": 2, "clientId": "client1", "data": "entered" },
{ "action": 4, "clientId": "client1", "data": "left" }
{ "action": 3, "clientId": "client1", "data": "left" }
])
}
)
Expand Down Expand Up @@ -1376,7 +1376,7 @@ mock_http = MockHttpClient(
headers: { "Link": "</channels/" + channel_name + "/presence/history?page=2>; rel=\"next\"" }
)
ELSE:
req.respond_with(200, body: [{ "action": 4, "clientId": "c1", "timestamp": 1000 }])
req.respond_with(200, body: [{ "action": 3, "clientId": "c1", "timestamp": 1000 }])
}
)
install_mock(mock_http)
Expand Down Expand Up @@ -1673,11 +1673,4 @@ ASSERT result.items[3].action == PresenceAction.leave
ASSERT result.items[4].action == PresenceAction.update
```

Note: Action values may vary by SDK. The wire protocol uses:
- 0 = absent
- 1 = present
- 2 = enter
- 3 = leave (some SDKs use 4)
- 4 = update (some SDKs use 3)

Verify against your SDK's specific mapping.
Note: The presence action is encoded on the wire as its enum ordinal, as specified in `specifications/protocol.md` (Presence Message): 0 = absent, 1 = present, 2 = enter, 3 = leave, 4 = update.
22 changes: 11 additions & 11 deletions uts/rest/unit/types/presence_message_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protocol_msg = ProtocolMessage(
action: PRESENCE,
connectionId: "proto-conn-1",
presence: [
{ "action": "enter", "clientId": "user-1" }
{ "action": 2, "clientId": "user-1" }
]
)

Expand All @@ -143,8 +143,8 @@ protocol_msg = ProtocolMessage(
action: PRESENCE,
id: "proto-msg-42",
presence: [
{ "action": "enter", "clientId": "alice" },
{ "action": "enter", "clientId": "bob" }
{ "action": 2, "clientId": "alice" },
{ "action": 2, "clientId": "bob" }
]
)

Expand All @@ -168,7 +168,7 @@ protocol_msg = ProtocolMessage(
action: PRESENCE,
timestamp: 9999999,
presence: [
{ "action": "enter", "clientId": "user-1" }
{ "action": 2, "clientId": "user-1" }
]
)

Expand All @@ -188,7 +188,7 @@ ASSERT presence_msg.timestamp == 9999999
```pseudo
json_data = {
"id": "pm-123",
"action": "enter",
"action": 2,
"clientId": "user-1",
"connectionId": "conn-1",
"data": "hello",
Expand Down Expand Up @@ -228,7 +228,7 @@ ASSERT msg.extras["headers"]["x-key"] == "x-value"
```pseudo
FOR EACH test_case IN test_cases:
json_data = {
"action": "enter",
"action": 2,
"clientId": "user-1",
"data": test_case.wire_data,
"encoding": test_case.encoding
Expand Down Expand Up @@ -259,7 +259,7 @@ msg = PresenceMessage(

json_data = msg.toJson()

ASSERT json_data["action"] == "enter"
ASSERT json_data["action"] == 2
ASSERT json_data["clientId"] == "user-1"
ASSERT json_data["data"] == "hello"
ASSERT json_data["extras"]["headers"]["x-key"] == "x-value"
Expand All @@ -280,7 +280,7 @@ msg = PresenceMessage(action: ENTER, clientId: "user-1")

json_data = msg.toJson()

ASSERT json_data["action"] == "enter"
ASSERT json_data["action"] == 2
ASSERT json_data["clientId"] == "user-1"
ASSERT "data" NOT IN json_data OR json_data["data"] IS null
ASSERT "encoding" NOT IN json_data OR json_data["encoding"] IS null
Expand All @@ -302,7 +302,7 @@ decoded and decrypted PresenceMessage(s). Behavior is the same as TM3.
```pseudo
# fromEncoded — single message
raw = {
"action": "enter",
"action": 2,
"clientId": "user-1",
"data": "{\"status\":\"online\"}",
"encoding": "json"
Expand All @@ -317,8 +317,8 @@ ASSERT msg.encoding IS null

# fromEncodedArray — array of messages
raw_array = [
{ "action": "enter", "clientId": "alice", "data": "hello" },
{ "action": "enter", "clientId": "bob", "data": "world" }
{ "action": 2, "clientId": "alice", "data": "hello" },
{ "action": 2, "clientId": "bob", "data": "world" }
]

messages = PresenceMessage.fromEncodedArray(raw_array)
Expand Down
Loading