@@ -9,7 +9,7 @@ struct DefaultLiveCounterTests {
99 // @spec RTLC5b
1010 @Test ( arguments: [ . detached, . failed] as [ ARTRealtimeChannelState ] )
1111 func valueThrowsIfChannelIsDetachedOrFailed( channelState: ARTRealtimeChannelState ) async throws {
12- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: channelState) )
12+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: channelState) )
1313
1414 #expect {
1515 _ = try counter. value
@@ -25,7 +25,7 @@ struct DefaultLiveCounterTests {
2525 // @spec RTLC5c
2626 @Test
2727 func valueReturnsCurrentDataWhenChannelIsValid( ) throws {
28- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attached) )
28+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attached) )
2929
3030 // Set some test data
3131 counter. replaceData ( using: TestFactories . counterObjectState ( count: 42 ) )
@@ -39,7 +39,7 @@ struct DefaultLiveCounterTests {
3939 // @spec RTLC6a
4040 @Test
4141 func replacesSiteTimeserials( ) {
42- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attaching) )
42+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attaching) )
4343 let state = TestFactories . counterObjectState (
4444 siteTimeserials: [ " site1 " : " ts1 " ] , // Test value
4545 )
@@ -52,18 +52,35 @@ struct DefaultLiveCounterTests {
5252 // @spec RTLC6b - Tests the case without createOp, as RTLC6d2 takes precedence when createOp exists
5353 @Test
5454 func setsCreateOperationIsMergedToFalse( ) {
55- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attaching) )
55+ // Given: A counter whose createOperationIsMerged is true
56+ let counter = {
57+ let counter = DefaultLiveCounter . createZeroValued ( objectID: " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attaching) )
58+ // Test setup: Manipulate counter so that its createOperationIsMerged gets set to true (we need to do this since we want to later assert that it gets set to false, but the default is false).
59+ let state = TestFactories . counterObjectState (
60+ createOp: TestFactories . objectOperation (
61+ action: . known( . counterCreate) ,
62+ ) ,
63+ )
64+ counter. replaceData ( using: state)
65+ #expect( counter. testsOnly_createOperationIsMerged)
66+
67+ return counter
68+ } ( )
69+
70+ // When:
5671 let state = TestFactories . counterObjectState (
5772 createOp: nil , // Test value - must be nil to test RTLC6b
5873 )
5974 counter. replaceData ( using: state)
60- #expect( counter. testsOnly_createOperationIsMerged == false )
75+
76+ // Then:
77+ #expect( !counter. testsOnly_createOperationIsMerged)
6178 }
6279
6380 // @specOneOf(1/4) RTLC6c - count but no createOp
6481 @Test
6582 func setsDataToCounterCount( ) throws {
66- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attaching) )
83+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attaching) )
6784 let state = TestFactories . counterObjectState (
6885 count: 42 , // Test value
6986 )
@@ -74,7 +91,7 @@ struct DefaultLiveCounterTests {
7491 // @specOneOf(2/4) RTLC6c - no count, no createOp
7592 @Test
7693 func setsDataToZeroWhenCounterCountDoesNotExist( ) throws {
77- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attaching) )
94+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attaching) )
7895 counter. replaceData ( using: TestFactories . counterObjectState (
7996 count: nil , // Test value - must be nil
8097 ) )
@@ -88,7 +105,7 @@ struct DefaultLiveCounterTests {
88105 // @specOneOf(3/4) RTLC6c - count and createOp
89106 @Test
90107 func setsDataToCounterCountThenAddsCreateOpCounterCount( ) throws {
91- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attaching) )
108+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attaching) )
92109 let state = TestFactories . counterObjectState (
93110 createOp: TestFactories . counterCreateOperation ( count: 10 ) , // Test value - must exist
94111 count: 5 , // Test value - must exist
@@ -101,7 +118,7 @@ struct DefaultLiveCounterTests {
101118 // @specOneOf(4/4) RTLC6c - no count but createOp
102119 @Test
103120 func doesNotModifyDataWhenCreateOpCounterCountDoesNotExist( ) throws {
104- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attaching) )
121+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attaching) )
105122 let state = TestFactories . counterObjectState (
106123 createOp: TestFactories . objectOperation (
107124 action: . known( . counterCreate) ,
@@ -116,14 +133,14 @@ struct DefaultLiveCounterTests {
116133 // @spec RTLC6d2
117134 @Test
118135 func setsCreateOperationIsMergedToTrue( ) {
119- let counter = DefaultLiveCounter . createZeroValued ( coreSDK: MockCoreSDK ( channelState: . attaching) )
136+ let counter = DefaultLiveCounter . createZeroValued ( objectID : " arbitrary " , coreSDK: MockCoreSDK ( channelState: . attaching) )
120137 let state = TestFactories . counterObjectState (
121138 createOp: TestFactories . objectOperation ( // Test value - must be non-nil
122139 action: . known( . counterCreate) ,
123140 ) ,
124141 )
125142 counter. replaceData ( using: state)
126- #expect( counter. testsOnly_createOperationIsMerged == true )
143+ #expect( counter. testsOnly_createOperationIsMerged)
127144 }
128145 }
129146 }
0 commit comments