Skip to content

Commit 187eadc

Browse files
committed
Add test cases for invalid region
1 parent 572ba7f commit 187eadc

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Tests/OptimizelyTests-Common/BatchEventBuilderTests_Region.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,31 @@ class BatchEventBuilderTests_Region: XCTestCase {
9595
let eventForDispatch = getFirstEvent(dispatcher: eventDispatcher)!
9696
XCTAssertEqual(eventForDispatch.url.absoluteString, EventForDispatch.getEndpoint(for: .EU))
9797
}
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+
}
98123

99124
// MARK: - Test Conversion Event with Region
100125

@@ -143,6 +168,29 @@ class BatchEventBuilderTests_Region: XCTestCase {
143168
let eventForDispatch = getFirstEvent(dispatcher: eventDispatcher)!
144169
XCTAssertEqual(eventForDispatch.url.absoluteString, EventForDispatch.getEndpoint(for: .EU))
145170
}
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+
}
146194

147195
// MARK: - Test Direct Event Creation with Region
148196

0 commit comments

Comments
 (0)