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

fix: tests on iOS 17 #136

Merged
merged 1 commit into from
Mar 15, 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
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ on:

jobs:
lint:
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Xcode 14
- name: Set Xcode 15
run: |
sudo xcode-select -switch /Applications/Xcode_14.1.app
sudo xcode-select -switch /Applications/Xcode_15.2.app
- name: Lint
run: swiftlint --strict # force to fix warnings too
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
authorize:
name: Authorize
runs-on: macos-12
runs-on: macos-13
steps:
- name: ${{ github.actor }} permission check to do a release
uses: octokit/[email protected]
Expand All @@ -23,20 +23,20 @@ jobs:

release:
name: Release
runs-on: macos-12
runs-on: macos-13
needs: [authorize]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Xcode 14
- name: Set Xcode 15
run: |
sudo xcode-select -switch /Applications/Xcode_14.1.app
sudo xcode-select -switch /Applications/Xcode_15.2.app
- name: iOS Tests
run: |
xcodebuild test \
-scheme Amplitude-Swift-Package \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 14'
-destination 'platform=iOS Simulator,name=iPhone 15'
- name: macOS Tests
run: |
xcodebuild test \
Expand All @@ -63,7 +63,7 @@ jobs:
xcodebuild test \
-scheme AmplitudeObjCExample \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 14'
-destination 'platform=iOS Simulator,name=iPhone 15'

- name: Validate Podfile
run: pod lib lint --allow-warnings
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ on:

jobs:
test:
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set Xcode 14
- name: Set Xcode 15
run: |
sudo xcode-select -switch /Applications/Xcode_14.1.app
sudo xcode-select -switch /Applications/Xcode_15.2.app
- name: List Simulators
run: |
xcrun simctl list
Expand All @@ -27,7 +27,7 @@ jobs:
xcodebuild test \
-scheme Amplitude-Swift-Package \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 14'
-destination 'platform=iOS Simulator,name=iPhone 15'
- name: macOS Tests
run: |
xcodebuild test \
Expand All @@ -54,4 +54,4 @@ jobs:
xcodebuild test \
-scheme AmplitudeObjCExample \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 14'
-destination 'platform=iOS Simulator,name=iPhone 15'
2 changes: 1 addition & 1 deletion Amplitude-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXAggregateTarget section */
Expand Down
1 change: 1 addition & 0 deletions Sources/Amplitude/Events/BaseEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ extension BaseEvent {
var returnString = ""
do {
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys
let json = try encoder.encode(self)
if let printed = String(data: json, encoding: .utf8) {
returnString = printed
Expand Down
1 change: 1 addition & 0 deletions Sources/Amplitude/Storages/PersistentStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ extension PersistentStorage {
var result = ""
do {
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys
let json = try encoder.encode(events)
if let printed = String(data: json, encoding: .utf8) {
result = printed
Expand Down
10 changes: 9 additions & 1 deletion Sources/Amplitude/Utilities/HttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ class HttpClient {

func getRequest() throws -> URLRequest {
let url = getUrl()
guard let requestUrl = URL(string: url) else {

let requestUrl: URL?
if #available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *) {
requestUrl = URL(string: url, encodingInvalidCharacters: false)
} else {
requestUrl = URL(string: url)
}

guard let requestUrl else {
throw Exception.invalidUrl(url: url)
}
var request = URLRequest(url: requestUrl, timeoutInterval: 60)
Expand Down
6 changes: 3 additions & 3 deletions Tests/AmplitudeTests/AmplitudeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ final class AmplitudeTests: XCTestCase {
func testFilterAndEnrichmentPlugin() {
let apiKey = "testFilterAndEnrichmentPlugin"
let enrichedEventType = "Enriched Event"
storageTest = TestPersistentStorage(storagePrefix: "storage-\(apiKey)", logger: self.logger, diagonostics: self.diagonostics)
let storage = FakeInMemoryStorage()
let amplitude = Amplitude(configuration: Configuration(
apiKey: apiKey,
storageProvider: storageTest
storageProvider: storage
))

class TestFilterAndEnrichmentPlugin: EnrichmentPlugin {
Expand All @@ -110,7 +110,7 @@ final class AmplitudeTests: XCTestCase {
amplitude.track(event: BaseEvent(eventType: enrichedEventType))
amplitude.track(event: BaseEvent(eventType: "Other Event"))

let events = storageTest.events()
let events = storage.events()
XCTAssertEqual(events[0].eventType, enrichedEventType)
XCTAssertEqual(getDictionary(events[0].eventProperties!), [
"testPropertyKey": "testPropertyValue"
Expand Down
Loading