@@ -64,7 +64,8 @@ class PresenceTransitionTests: XCTestCase {
6464 configuration: PubNubConfiguration (
6565 publishKey: " publishKey " ,
6666 subscribeKey: " subscribeKey " ,
67- userId: " userId "
67+ userId: " userId " ,
68+ heartbeatInterval: 30
6869 )
6970 )
7071
@@ -87,7 +88,7 @@ class PresenceTransitionTests: XCTestCase {
8788 let state = Presence . HeartbeatInactive ( )
8889 let event = Presence . Event. joined ( channels: [ " c1 " , " c2 " ] , groups: [ " g1 " , " g2 " ] )
8990
90- XCTAssertFalse ( PresenceTransition ( configuration: configWithEmptyInterval) . canTransition ( from: state, dueTo: event) )
91+ XCTAssertTrue ( PresenceTransition ( configuration: configWithEmptyInterval) . canTransition ( from: state, dueTo: event) )
9192 XCTAssertTrue ( PresenceTransition ( configuration: configWithInterval) . canTransition ( from: state, dueTo: event) )
9293 }
9394
@@ -106,6 +107,32 @@ class PresenceTransitionTests: XCTestCase {
106107 XCTAssertTrue ( results. state. isEqual ( to: expectedState) )
107108 XCTAssertTrue ( results. invocations. elementsEqual ( expectedInvocations) )
108109 }
110+
111+ func testPresence_JoinedEventForHeartbeatInactiveState_EmptyInterval( ) {
112+ let configWithEmptyInterval = PubNubConfiguration (
113+ publishKey: " pubKey " ,
114+ subscribeKey: " subKey " ,
115+ userId: " userId " ,
116+ heartbeatInterval: 0
117+ )
118+
119+ let presenceTransition = PresenceTransition (
120+ configuration: configWithEmptyInterval
121+ )
122+ let results = presenceTransition. transition (
123+ from: Presence . HeartbeatInactive ( ) ,
124+ event: . joined( channels: [ " c3 " ] , groups: [ " g3 " ] )
125+ )
126+ let expectedInvocations : [ EffectInvocation < Presence . Invocation > ] = [
127+ . regular( . heartbeat( channels: [ " c3 " ] , groups: [ " g3 " ] ) )
128+ ]
129+ let expectedState = Presence . Heartbeating (
130+ input: PresenceInput ( channels: [ " c3 " ] , groups: [ " g3 " ] )
131+ )
132+
133+ XCTAssertTrue ( results. state. isEqual ( to: expectedState) )
134+ XCTAssertTrue ( results. invocations. elementsEqual ( expectedInvocations) )
135+ }
109136
110137 func testPresence_JoinedEventForHeartbeatingState( ) {
111138 let input = PresenceInput (
@@ -453,6 +480,26 @@ class PresenceTransitionTests: XCTestCase {
453480 XCTAssertTrue ( results. invocations. elementsEqual ( expectedInvocations) )
454481 }
455482
483+ func testPresence_HeartbeatSuccessForEmptyInterval( ) {
484+ let configWithEmptyInterval = PubNubConfiguration (
485+ publishKey: " pubKey " ,
486+ subscribeKey: " subKey " ,
487+ userId: " userId " ,
488+ heartbeatInterval: 0
489+ )
490+
491+ let presenceTransition = PresenceTransition ( configuration: configWithEmptyInterval)
492+ let input = PresenceInput ( channels: [ " c1 " , " c2 " ] , groups: [ " g1 " , " g2 " ] )
493+
494+ let results = presenceTransition. transition (
495+ from: Presence . Heartbeating ( input: input) ,
496+ event: . heartbeatSuccess
497+ )
498+
499+ XCTAssertTrue ( results. state. isEqual ( to: Presence . HeartbeatStopped ( input: input) ) )
500+ XCTAssertTrue ( results. invocations. isEmpty)
501+ }
502+
456503 // MARK: - Heartbeat Failed
457504
458505 func testPresence_HeartbeatFailedForHeartbeatingState( ) {
0 commit comments