Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lack of url in openURL options output; Added test. #358

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Sources/Segment/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,11 @@ extension Analytics {

var jsonProperties: JSON? = nil
if let json = try? JSON(options) {
jsonProperties = json
_ = try? jsonProperties?.add(value: url.absoluteString, forKey: "url")
do {
jsonProperties = try json.add(value: url.absoluteString, forKey: "url")
} catch {
jsonProperties = json
}
} else {
if let json = try? JSON(["url": url.absoluteString]) {
jsonProperties = json
Expand Down
53 changes: 53 additions & 0 deletions Tests/Segment-Tests/Analytics_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,59 @@ final class Analytics_Tests: XCTestCase {
XCTAssertTrue(token?.count == 32) // it's a uuid w/o the dashes. 36 becomes 32.
}
#endif

func testOpenURL() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
let outputReader = OutputReaderPlugin()
analytics.add(plugin: outputReader)

waitUntilStarted(analytics: analytics)

let url = URL(string: "https://blah.com")!

// you ain't got no options Lt. Dan!
analytics.openURL(url)
let urlEvent: TrackEvent? = outputReader.lastEvent as? TrackEvent
XCTAssertEqual(urlEvent?.properties?.dictionaryValue!["url"] as! String, "https://blah.com")

// Anyway, like I was sayin' ...
let options = [
"Shrimp": [
"Description": "Fruit of the sea",
"CookingMethods": [
"barbecue",
"boil",
"broil",
"bake",
"saute",
"fried (implied)"
],
"Types": [
"shrimp kabobs",
"shrimp gumbo",
"pan fried",
"deep fried",
"stir fried",
"pineapple shrimp",
"lemon shrimp",
"coconut shrimp",
"pepper shrimp",
"shrimp soup",
"shrimp stew",
"shrimp salad",
"shrimp and potatoes",
"shrimp burger",
"shrimp sandwich",
"That- that's about it"
]
]
]

analytics.openURL(url, options: options)
let urlOptionEvent: TrackEvent? = outputReader.lastEvent as? TrackEvent
XCTAssertEqual(urlOptionEvent?.properties?.dictionaryValue!["url"] as! String, "https://blah.com")
XCTAssertNotNil(urlOptionEvent?.properties?.dictionaryValue!["Shrimp"])
}

func testTrack() {
let analytics = Analytics(configuration: Configuration(writeKey: "test"))
Expand Down
Loading