@@ -38,6 +38,24 @@ class SessionStartEventTests: XCTestCase {
38
38
appInfo = MockApplicationInfo ( )
39
39
}
40
40
41
+ var defaultSessionInfo : SessionInfo {
42
+ return SessionInfo (
43
+ sessionId: " test_session_id " ,
44
+ firstSessionId: " test_first_session_id " ,
45
+ dispatchEvents: true ,
46
+ sessionIndex: 0
47
+ )
48
+ }
49
+
50
+ var thirdSessionInfo : SessionInfo {
51
+ return SessionInfo (
52
+ sessionId: " test_third_session_id " ,
53
+ firstSessionId: " test_first_session_id " ,
54
+ dispatchEvents: true ,
55
+ sessionIndex: 2
56
+ )
57
+ }
58
+
41
59
/// This function runs the `testCase` twice, once for the proto object stored in
42
60
/// the event, and once after encoding and decoding the proto. This is useful for
43
61
/// testing cases where the proto hasn't been encoded correctly.
@@ -52,32 +70,28 @@ class SessionStartEventTests: XCTestCase {
52
70
testCase ( decodedProto)
53
71
}
54
72
55
- func test_init_setsSessionIDs( ) {
56
- let sessionInfo = SessionInfo (
57
- sessionId: " test_session_id " ,
58
- previousSessionId: " test_previous_session_id " ,
59
- dispatchEvents: true
60
- )
61
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
73
+ func test_init_setsSessionData( ) {
74
+ let event = SessionStartEvent ( sessionInfo: thirdSessionInfo, appInfo: appInfo, time: time)
62
75
63
76
testProtoAndDecodedProto ( sessionEvent: event) { proto in
64
77
assertEqualProtoString (
65
78
proto. session_data. session_id,
66
- expected: " test_session_id " ,
79
+ expected: " test_third_session_id " ,
67
80
fieldName: " session_id "
68
81
)
82
+ assertEqualProtoString (
83
+ proto. session_data. first_session_id,
84
+ expected: " test_first_session_id " ,
85
+ fieldName: " first_session_id "
86
+ )
87
+ XCTAssertEqual ( proto. session_data. session_index, 2 )
69
88
70
89
XCTAssertEqual ( proto. session_data. event_timestamp_us, 123 )
71
90
}
72
91
}
73
92
74
93
func test_init_setsApplicationInfo( ) {
75
- let sessionInfo = SessionInfo (
76
- sessionId: " session_id " ,
77
- previousSessionId: " previous_session_id " ,
78
- dispatchEvents: true
79
- )
80
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
94
+ let event = SessionStartEvent ( sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
81
95
82
96
testProtoAndDecodedProto ( sessionEvent: event) { proto in
83
97
assertEqualProtoString (
@@ -110,12 +124,7 @@ class SessionStartEventTests: XCTestCase {
110
124
}
111
125
112
126
func test_setInstallationID_setsInstallationID( ) {
113
- let sessionInfo = SessionInfo (
114
- sessionId: " session_id " ,
115
- previousSessionId: " previous_session_id " ,
116
- dispatchEvents: true
117
- )
118
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
127
+ let event = SessionStartEvent ( sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
119
128
120
129
event. setInstallationID ( installationId: " testInstallationID " )
121
130
@@ -143,12 +152,11 @@ class SessionStartEventTests: XCTestCase {
143
152
expectations. forEach { ( given: String , expected: firebase_appquality_sessions_OsName ) in
144
153
appInfo. osName = given
145
154
146
- let sessionInfo = SessionInfo (
147
- sessionId : " session_id " ,
148
- previousSessionId : " previous_session_id " ,
149
- dispatchEvents : true
155
+ let event = SessionStartEvent (
156
+ sessionInfo : self . defaultSessionInfo ,
157
+ appInfo : appInfo ,
158
+ time : time
150
159
)
151
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
152
160
153
161
testProtoAndDecodedProto ( sessionEvent: event) { proto in
154
162
XCTAssertEqual ( event. proto. application_info. apple_app_info. os_name, expected)
@@ -174,24 +182,18 @@ class SessionStartEventTests: XCTestCase {
174
182
expected: firebase_appquality_sessions_LogEnvironment ) in
175
183
appInfo. environment = given
176
184
177
- let sessionInfo = SessionInfo (
178
- sessionId : " session_id " ,
179
- previousSessionId : " previous_session_id " ,
180
- dispatchEvents : true
185
+ let event = SessionStartEvent (
186
+ sessionInfo : self . defaultSessionInfo ,
187
+ appInfo : appInfo ,
188
+ time : time
181
189
)
182
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
183
190
184
191
XCTAssertEqual ( event. proto. application_info. log_environment, expected)
185
192
}
186
193
}
187
194
188
195
func test_dataCollectionState_defaultIsUnknown( ) {
189
- let sessionInfo = SessionInfo (
190
- sessionId: " session_id " ,
191
- previousSessionId: " previous_session_id " ,
192
- dispatchEvents: true
193
- )
194
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
196
+ let event = SessionStartEvent ( sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
195
197
196
198
testProtoAndDecodedProto ( sessionEvent: event) { proto in
197
199
XCTAssertEqual (
@@ -217,12 +219,7 @@ class SessionStartEventTests: XCTestCase {
217
219
#endif
218
220
appInfo. networkInfo = mockNetworkInfo
219
221
220
- let sessionInfo = SessionInfo (
221
- sessionId: " session_id " ,
222
- previousSessionId: " previous_session_id " ,
223
- dispatchEvents: true
224
- )
225
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
222
+ let event = SessionStartEvent ( sessionInfo: defaultSessionInfo, appInfo: appInfo, time: time)
226
223
227
224
// These fields will not be filled in when Crashlytics is installed
228
225
event. set ( subscriber: . Crashlytics, isDataCollectionEnabled: true , appInfo: appInfo)
@@ -304,12 +301,11 @@ class SessionStartEventTests: XCTestCase {
304
301
mockNetworkInfo. networkType = given
305
302
appInfo. networkInfo = mockNetworkInfo
306
303
307
- let sessionInfo = SessionInfo (
308
- sessionId : " session_id " ,
309
- previousSessionId : " previous_session_id " ,
310
- dispatchEvents : true
304
+ let event = SessionStartEvent (
305
+ sessionInfo : self . defaultSessionInfo ,
306
+ appInfo : appInfo ,
307
+ time : time
311
308
)
312
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
313
309
314
310
// These fields will only be filled in when the Perf SDK is installed
315
311
event. set ( subscriber: . Performance, isDataCollectionEnabled: true , appInfo: appInfo)
@@ -389,12 +385,11 @@ class SessionStartEventTests: XCTestCase {
389
385
mockNetworkInfo. mobileSubtype = given
390
386
appInfo. networkInfo = mockNetworkInfo
391
387
392
- let sessionInfo = SessionInfo (
393
- sessionId : " session_id " ,
394
- previousSessionId : " previous_session_id " ,
395
- dispatchEvents : true
388
+ let event = SessionStartEvent (
389
+ sessionInfo : self . defaultSessionInfo ,
390
+ appInfo : appInfo ,
391
+ time : time
396
392
)
397
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
398
393
399
394
// These fields will only be filled in when the Perf SDK is installed
400
395
event. set ( subscriber: . Performance, isDataCollectionEnabled: true , appInfo: appInfo)
@@ -483,12 +478,11 @@ class SessionStartEventTests: XCTestCase {
483
478
mockNetworkInfo. mobileSubtype = given
484
479
appInfo. networkInfo = mockNetworkInfo
485
480
486
- let sessionInfo = SessionInfo (
487
- sessionId : " session_id " ,
488
- previousSessionId : " previous_session_id " ,
489
- dispatchEvents : true
481
+ let event = SessionStartEvent (
482
+ sessionInfo : self . defaultSessionInfo ,
483
+ appInfo : appInfo ,
484
+ time : time
490
485
)
491
- let event = SessionStartEvent ( sessionInfo: sessionInfo, appInfo: appInfo, time: time)
492
486
493
487
// These fields will only be filled in when the Perf SDK is installed
494
488
event. set ( subscriber: . Performance, isDataCollectionEnabled: true , appInfo: appInfo)
0 commit comments