@@ -95,6 +95,31 @@ class BatchEventBuilderTests_Region: XCTestCase {
95
95
let eventForDispatch = getFirstEvent ( dispatcher: eventDispatcher) !
96
96
XCTAssertEqual ( eventForDispatch. url. absoluteString, EventForDispatch . getEndpoint ( for: . EU) )
97
97
}
98
+
99
+ func testCreateImpressionEventWithInvalidRegion( ) {
100
+ // Set the region to invalid ZZ
101
+ optimizely. config? . project. region = . ZZ
102
+
103
+ let attributes : [ String : Any ] = [
104
+ " s_foo " : " foo " ,
105
+ " b_true " : true ,
106
+ " i_42 " : 42 ,
107
+ " d_4_2 " : 4.2
108
+ ]
109
+
110
+ _ = try ! optimizely. activate ( experimentKey: experimentKey,
111
+ userId: userId,
112
+ attributes: attributes)
113
+
114
+ let event = getFirstEventJSON ( dispatcher: eventDispatcher) !
115
+
116
+ // Check if the region is correctly set to default US in the event
117
+ XCTAssertEqual ( event [ " region " ] as! String , " US " )
118
+
119
+ // Check if the event was sent to the correct endpoint
120
+ let eventForDispatch = getFirstEvent ( dispatcher: eventDispatcher) !
121
+ XCTAssertEqual ( eventForDispatch. url. absoluteString, EventForDispatch . getEndpoint ( for: . US) )
122
+ }
98
123
99
124
// MARK: - Test Conversion Event with Region
100
125
@@ -143,6 +168,29 @@ class BatchEventBuilderTests_Region: XCTestCase {
143
168
let eventForDispatch = getFirstEvent ( dispatcher: eventDispatcher) !
144
169
XCTAssertEqual ( eventForDispatch. url. absoluteString, EventForDispatch . getEndpoint ( for: . EU) )
145
170
}
171
+
172
+ func testCreateConversionEventWithInvalidRegion( ) {
173
+ // Set the region to invalid ZZ
174
+ optimizely. config? . project. region = . ZZ
175
+
176
+ let eventKey = " event_single_targeted_exp "
177
+ let attributes : [ String : Any ] = [ " s_foo " : " bar " ]
178
+ let eventTags : [ String : Any ] = [ " browser " : " chrome " ]
179
+
180
+ try ! optimizely. track ( eventKey: eventKey,
181
+ userId: userId,
182
+ attributes: attributes,
183
+ eventTags: eventTags)
184
+
185
+ let event = getFirstEventJSON ( dispatcher: eventDispatcher) !
186
+
187
+ // Check if the region is correctly set to default US in the event
188
+ XCTAssertEqual ( event [ " region " ] as! String , " US " )
189
+
190
+ // Check if the event was sent to the correct endpoint
191
+ let eventForDispatch = getFirstEvent ( dispatcher: eventDispatcher) !
192
+ XCTAssertEqual ( eventForDispatch. url. absoluteString, EventForDispatch . getEndpoint ( for: . US) )
193
+ }
146
194
147
195
// MARK: - Test Direct Event Creation with Region
148
196
0 commit comments