-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from hotwired/user-agent-prefix
Breaking API change: applications can set a User-Agent prefix
- Loading branch information
Showing
5 changed files
with
47 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import Foundation | ||
|
||
public enum UserAgent { | ||
public static func userAgentSubstring(for componentTypes: [BridgeComponent.Type]) -> String { | ||
enum UserAgent { | ||
static func build(applicationPrefix: String?, componentTypes: [BridgeComponent.Type]) -> String { | ||
let components = componentTypes.map { $0.name }.joined(separator: " ") | ||
return "bridge-components: [\(components)]" | ||
let componentsSubstring = "bridge-components: [\(components)]" | ||
|
||
return [ | ||
applicationPrefix, | ||
"Hotwire Native iOS;", | ||
"Turbo Native iOS;", | ||
componentsSubstring | ||
].compactMap { $0 }.joined(separator: " ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
import Foundation | ||
import HotwireNative | ||
@testable import HotwireNative | ||
import XCTest | ||
|
||
class UserAgentTests: XCTestCase { | ||
func testUserAgentSubstringWithNoComponents() { | ||
let userAgentSubstring = UserAgent.build( | ||
applicationPrefix: nil, | ||
componentTypes: [] | ||
) | ||
XCTAssertEqual(userAgentSubstring, "Hotwire Native iOS; Turbo Native iOS; bridge-components: []") | ||
} | ||
|
||
func testUserAgentSubstringWithTwoComponents() { | ||
let userAgentSubstring = UserAgent.userAgentSubstring(for: [OneBridgeComponent.self, TwoBridgeComponent.self]) | ||
XCTAssertEqual(userAgentSubstring, "bridge-components: [one two]") | ||
let userAgentSubstring = UserAgent.build( | ||
applicationPrefix: nil, | ||
componentTypes: [OneBridgeComponent.self, TwoBridgeComponent.self] | ||
) | ||
XCTAssertEqual(userAgentSubstring, "Hotwire Native iOS; Turbo Native iOS; bridge-components: [one two]") | ||
} | ||
|
||
func testUserAgentSubstringWithNoComponents() { | ||
let userAgentSubstring = UserAgent.userAgentSubstring(for: []) | ||
XCTAssertEqual(userAgentSubstring, "bridge-components: []") | ||
func testUserAgentSubstringCustomPrefix() { | ||
let userAgentSubstring = UserAgent.build( | ||
applicationPrefix: "Hotwire Demo;", | ||
componentTypes: [OneBridgeComponent.self, TwoBridgeComponent.self] | ||
) | ||
XCTAssertEqual(userAgentSubstring, "Hotwire Demo; Hotwire Native iOS; Turbo Native iOS; bridge-components: [one two]") | ||
} | ||
} |