Skip to content

Commit

Permalink
More testing and CI update
Browse files Browse the repository at this point in the history
  • Loading branch information
donnywals committed Nov 28, 2024
1 parent 91557e6 commit 5f687a4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/transloaditkit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: ["macos-latest"]
swift: ["5.10"]
swift: ["6.0"]
runs-on: ${{ matrix.os }}
steps:
- name: Extract Branch Name
Expand Down
4 changes: 4 additions & 0 deletions Sources/TransloaditKit/Transloadit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public final class Transloadit {

public weak var fileDelegate: TransloaditFileDelegate?

public var isUsingBackgroundConfiguration: (transloadit: Bool, tus: Bool) {
return (api.configuration.identifier != nil, tusSessionConfig.identifier != nil)
}

/// Initialize Transloadit
/// - Parameters:
/// - credentials: The credentials with required key and secret.
Expand Down
20 changes: 20 additions & 0 deletions Tests/TransloaditKitTests/SessionCopyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,23 @@ func tusAndTransloaditHaveUniqueIdentifiersWhenProvidingSession() async throws {
#expect(transloadit.tusSessionConfig.identifier == expectedTUSClientConfigIdentifier)
#expect(transloadit.api.configuration.identifier == expectedTransloaditConfigIdentifier)
}

@Test("Checking session configurations should report correctly for background config")
func transloaditReportsCorrectSessionTypesBGConfig() async throws {
let config = URLSessionConfiguration.background(withIdentifier: transloaditConfigIdentifierForTesting)
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
#expect(transloadit.isUsingBackgroundConfiguration.transloadit)
#expect(transloadit.isUsingBackgroundConfiguration.tus)
}

@Test("Checking session configurations should report correctly for default config")
func transloaditReportsCorrectSessionTypesDefaultConfig() async throws {
let config = URLSessionConfiguration.default
let transloadit = Transloadit(
credentials: .init(key: "", secret: ""),
sessionConfiguration: config)
#expect(!transloadit.isUsingBackgroundConfiguration.transloadit)
#expect(!transloadit.isUsingBackgroundConfiguration.tus)
}
4 changes: 4 additions & 0 deletions TransloaditKitExample/TransloaditKitExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ struct ContentView: View {
PhotoPicker { [weak uploader, weak backgroundUploader] urls in
print(urls)
if uploadUsingBackgroundConfig {
assert(backgroundUploader?.transloadit.isUsingBackgroundConfiguration.transloadit == true)
assert(backgroundUploader?.transloadit.isUsingBackgroundConfiguration.tus == true)
backgroundUploader?.upload(urls)
} else {
assert(uploader?.transloadit.isUsingBackgroundConfiguration.transloadit == false)
assert(uploader?.transloadit.isUsingBackgroundConfiguration.tus == false)
uploader?.upload(urls)
}
}
Expand Down

0 comments on commit 5f687a4

Please sign in to comment.