Skip to content

Conversation

@grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Dec 11, 2025

Description

This PR adds comprehensive tests for nil ref scenarios to verify and document that optional ref and joinRef fields are properly handled in JSON encoding/decoding. The Swift SDK already has the correct implementation with optional types, but these tests prevent regressions and ensure SDK parity with other language implementations.

Context

The JavaScript SDK recently fixed an issue with message serialization in the Realtime library to properly handle null/undefined ref and join_ref fields when encoding messages (PR #1862).

The Swift SDK already has the correct implementation:

  • Both ref and joinRef are optional (String?)
  • Codable protocol properly encodes/decodes optionals as JSON null
  • Heartbeats already use nil for joinRef correctly

Changes

  • Added comprehensive test coverage for nil ref scenarios:
    • Messages with both refs as nil
    • Heartbeat messages with nil joinRef
    • JSON encoding/decoding with nil values
    • Messages with both ref and joinRef
    • Messages with ref but nil joinRef
  • Added documentation comments to RealtimeMessageV2 struct explaining why refs are optional

Testing

  • ✅ All new tests pass (5/5)
  • ✅ All existing tests pass (7/7 total in RealtimeMessageV2Tests)
  • ✅ No breaking changes - this is purely additive (tests and documentation)

Code Review Verification

  • ✅ No binary serialization paths exist that don't handle optional refs (only JSON encoding is used)
  • ✅ JSON encoding/decoding handles nil refs correctly (Codable does this automatically)
  • ✅ Heartbeats already use nil for joinRef (confirmed in RealtimeClientV2.swift:487)

Related

…lization

Add comprehensive tests for nil ref scenarios to verify and document
that optional ref and joinRef fields are properly handled in JSON
encoding/decoding. The Swift SDK already has the correct implementation
with optional types, but these tests prevent regressions and ensure
SDK parity with other language implementations.

- Added tests for messages with nil refs
- Added tests for heartbeat messages with nil joinRef
- Added tests for JSON encoding/decoding with nil values
- Added documentation comments to RealtimeMessageV2 struct

Closes SDK-532
@grdsdev grdsdev requested a review from a team December 11, 2025 21:49
@coveralls
Copy link

Pull Request Test Coverage Report for Build 20148490201

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 80.447%

Totals Coverage Status
Change from base Build 20096086835: 0.0%
Covered Lines: 6328
Relevant Lines: 7866

💛 - Coveralls

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.

3 participants