File tree Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Expand file tree Collapse file tree 2 files changed +58
-2
lines changed Original file line number Diff line number Diff line change @@ -386,8 +386,11 @@ extension Analytics {
386386
387387 var jsonProperties : JSON ? = nil
388388 if let json = try ? JSON ( options) {
389- jsonProperties = json
390- _ = try ? jsonProperties? . add ( value: url. absoluteString, forKey: " url " )
389+ do {
390+ jsonProperties = try json. add ( value: url. absoluteString, forKey: " url " )
391+ } catch {
392+ jsonProperties = json
393+ }
391394 } else {
392395 if let json = try ? JSON ( [ " url " : url. absoluteString] ) {
393396 jsonProperties = json
Original file line number Diff line number Diff line change @@ -275,6 +275,59 @@ final class Analytics_Tests: XCTestCase {
275275 XCTAssertTrue ( token? . count == 32 ) // it's a uuid w/o the dashes. 36 becomes 32.
276276 }
277277#endif
278+
279+ func testOpenURL( ) {
280+ let analytics = Analytics ( configuration: Configuration ( writeKey: " test " ) )
281+ let outputReader = OutputReaderPlugin ( )
282+ analytics. add ( plugin: outputReader)
283+
284+ waitUntilStarted ( analytics: analytics)
285+
286+ let url = URL ( string: " https://blah.com " ) !
287+
288+ // you ain't got no options Lt. Dan!
289+ analytics. openURL ( url)
290+ let urlEvent : TrackEvent ? = outputReader. lastEvent as? TrackEvent
291+ XCTAssertEqual ( urlEvent? . properties? . dictionaryValue![ " url " ] as! String , " https://blah.com " )
292+
293+ // Anyway, like I was sayin' ...
294+ let options = [
295+ " Shrimp " : [
296+ " Description " : " Fruit of the sea " ,
297+ " CookingMethods " : [
298+ " barbecue " ,
299+ " boil " ,
300+ " broil " ,
301+ " bake " ,
302+ " saute " ,
303+ " fried (implied) "
304+ ] ,
305+ " Types " : [
306+ " shrimp kabobs " ,
307+ " shrimp gumbo " ,
308+ " pan fried " ,
309+ " deep fried " ,
310+ " stir fried " ,
311+ " pineapple shrimp " ,
312+ " lemon shrimp " ,
313+ " coconut shrimp " ,
314+ " pepper shrimp " ,
315+ " shrimp soup " ,
316+ " shrimp stew " ,
317+ " shrimp salad " ,
318+ " shrimp and potatoes " ,
319+ " shrimp burger " ,
320+ " shrimp sandwich " ,
321+ " That- that's about it "
322+ ]
323+ ]
324+ ]
325+
326+ analytics. openURL ( url, options: options)
327+ let urlOptionEvent : TrackEvent ? = outputReader. lastEvent as? TrackEvent
328+ XCTAssertEqual ( urlOptionEvent? . properties? . dictionaryValue![ " url " ] as! String , " https://blah.com " )
329+ XCTAssertNotNil ( urlOptionEvent? . properties? . dictionaryValue![ " Shrimp " ] )
330+ }
278331
279332 func testTrack( ) {
280333 let analytics = Analytics ( configuration: Configuration ( writeKey: " test " ) )
You can’t perform that action at this time.
0 commit comments