-
Notifications
You must be signed in to change notification settings - Fork 0
feat: send user agent header Foresight PR for review and unit tests #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
50274f9
1e8a7dc
ce3f6d3
4b1c052
97a0dae
17621a2
4b9646d
1553f84
7df2d9e
c03685e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,44 @@ final class RouterTests: FlagsmithClientTestCase { | |||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(request.allHTTPHeaderFields?.contains(where: { $0.key == "X-Environment-Key" }) ?? false) | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertNil(request.httpBody) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| func testUserAgentHeader() throws { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let url = try XCTUnwrap(baseUrl) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let route = Router.getFlags | ||||||||||||||||||||||||||||||||||||||||||||||||
| let request = try route.request(baseUrl: url, apiKey: apiKey) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Verify User-Agent header is present | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(request.allHTTPHeaderFields?.contains(where: { $0.key == "User-Agent" }) ?? false) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Verify User-Agent header format | ||||||||||||||||||||||||||||||||||||||||||||||||
| let userAgent = request.allHTTPHeaderFields?["User-Agent"] | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertNotNil(userAgent) | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(userAgent?.hasPrefix("flagsmith-swift-ios-sdk/") ?? false) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Verify the format is correct (should end with a semantic version number) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let expectedPattern = "^flagsmith-swift-ios-sdk/[0-9]+\\.[0-9]+\\.[0-9]+$" | ||||||||||||||||||||||||||||||||||||||||||||||||
| let regex = try NSRegularExpression(pattern: expectedPattern) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let range = NSRange(location: 0, length: userAgent?.count ?? 0) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let match = regex.firstMatch(in: userAgent ?? "", options: [], range: range) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let message = "User-Agent should match pattern 'flagsmith-swift-ios-sdk/<version>', got: \(userAgent ?? "nil")" | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(match != nil, message) | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| func testUserAgentHeaderFormat() { | ||||||||||||||||||||||||||||||||||||||||||||||||
| // Test that the User-Agent format is correct | ||||||||||||||||||||||||||||||||||||||||||||||||
| let userAgent = Flagsmith.userAgent | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(userAgent.hasPrefix("flagsmith-swift-ios-sdk/")) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Should have a semantic version number (e.g., 3.8.4) | ||||||||||||||||||||||||||||||||||||||||||||||||
| let versionPart = String(userAgent.dropFirst("flagsmith-swift-ios-sdk/".count)) | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(versionPart.range(of: #"^\d+\.\d+\.\d+$"#, options: NSString.CompareOptions.regularExpression) != nil, | ||||||||||||||||||||||||||||||||||||||||||||||||
| "Version part should be a semantic version number (e.g., 3.8.4), got: \(versionPart)") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // Should be the expected SDK version | ||||||||||||||||||||||||||||||||||||||||||||||||
| // x-release-please-start-version | ||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(versionPart, "3.8.4", "Expected SDK version 3.8.4, got: \(versionPart)") | ||||||||||||||||||||||||||||||||||||||||||||||||
| // x-release-please-end | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+47
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove hardcoded version assertion. Line 57 asserts that the version must equal "3.8.4". This makes the test brittle—it will fail every time the SDK version is updated, requiring manual test maintenance. The purpose of having a dynamic version mechanism is to avoid such brittleness. Remove the hardcoded version check and rely on the semantic version format validation already performed on lines 52-54. Apply this diff: -
- // Should be the expected SDK version
- XCTAssertEqual(versionPart, "3.8.4", "Expected SDK version 3.8.4, got: \(versionPart)")Minor inconsistency: Line 53 uses Swift's native regex syntax ( 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| func testGetIdentityRequest() throws { | ||||||||||||||||||||||||||||||||||||||||||||||||
| let url = try XCTUnwrap(baseUrl) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.