Skip to content

Commit

Permalink
Merge dad7bc6 into daffd86
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski committed Mar 6, 2024
2 parents daffd86 + dad7bc6 commit c9684a7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ identifier_name:
- id
- by

empty_count: warning

trailing_whitespace:
ignores_empty_lines: no

Expand Down
13 changes: 10 additions & 3 deletions Sources/Core/BoxJSONDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

import Foundation

// swiftlint:disable:next convenience_type
class BoxJSONDecoder {
enum BoxJSONDecoder {

static func extractJSON<T>(json: [String: Any], key: String) throws -> T {
guard let objectJSON = json[key] else {
Expand Down Expand Up @@ -144,10 +143,18 @@ class BoxJSONDecoder {
return nil
}

#if compiler(>=5.9)
if #available(iOS 17.0, *) {
guard let url = URL(string: value, encodingInvalidCharacters: false) else {
throw BoxCodingError(message: .invalidValueFormat(key: key))
}
return url
}
#endif

guard let url = URL(string: value) else {
throw BoxCodingError(message: .invalidValueFormat(key: key))
}

return url
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Requests/AnalyticsHeaderGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class AnalyticsHeaderGenerator {
return WKInterfaceDevice.current().model
#elseif os(OSX)
return "macOS"
#elseif os(visionOS)
return "visionOS"
#endif
}()

Expand All @@ -48,7 +50,7 @@ class AnalyticsHeaderGenerator {
return UIDevice.current.systemVersion
#elseif os(watchOS)
return WKInterfaceDevice.current().systemVersion
#elseif os(OSX)
#elseif os(OSX) || os(visionOS)
let version = ProcessInfo.processInfo.operatingSystemVersion
let versionString = "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
return versionString
Expand Down
23 changes: 23 additions & 0 deletions Tests/Helpers/OHTTPStubs+JSONComparer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,27 @@ public extension QuickSpec {
return match
}
}

static func compareComplexQueryParam(_ key: String, _ partValues: [String], checkClosure _: CheckClosureType? = nil) -> HTTPStubsTestBlock {
return { req in
if let url = req.url {
let comps = NSURLComponents(url: url, resolvingAgainstBaseURL: true)
guard let queryItems = comps?.queryItems else {
return false
}

guard let item = queryItems.first(where: { $0.name == key }) else {
return false
}

guard let value = item.value else {
return false
}

return partValues.allSatisfy { value.contains($0) }
}

return false
}
}
}
8 changes: 4 additions & 4 deletions Tests/Modules/FilesModuleSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ class FilesModuleSpecs: QuickSpec {

waitUntil(timeout: .seconds(200)) { done in
let data = "This is upload test file content".data(using: .utf8)!
var progressed: Double?
var progressed: Double? = 0
let task = sut.files.upload(
data: data,
name: "tigers.jpeg",
Expand Down Expand Up @@ -667,7 +667,7 @@ class FilesModuleSpecs: QuickSpec {

waitUntil(timeout: .seconds(200)) { done in
let data = "This is upload test file content".data(using: .utf8)!
var progressed: Double?
var progressed: Double? = 0
var task: BoxUploadTask?
task = sut.files.upload(
data: data,
Expand Down Expand Up @@ -1657,7 +1657,7 @@ class FilesModuleSpecs: QuickSpec {
waitUntil(timeout: .seconds(10)) { done in
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent("doc.txt")
var progressed: Double?
var progressed: Double? = 0
let task = sut.files.download(
fileId: "12345",
destinationURL: fileURL,
Expand All @@ -1670,7 +1670,7 @@ class FilesModuleSpecs: QuickSpec {
case .success:
fail("Expected download to be cancelled, but instead suceeded")
case let .failure(error):
expect(progressed).to(equal(0.05))
expect(progressed).to(beLessThan(1.0))
expect(error.message.description).to(equal("cancelled"))
}
done()
Expand Down
20 changes: 16 additions & 4 deletions Tests/Modules/SearchModuleSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ class SearchModuleSpecs: QuickSpec {
stub(
condition:
isHost("api.box.com") && isPath("/2.0/search")
&& containsQueryParams(["mdfilters": "[{\"scope\":\"global\",\"templateKey\":\"marketingCollateral\",\"filters\":{\"date\":{\"gt\":\"2019-07-24T12:00:00Z\"}}}]"])
&& compareComplexQueryParam("mdfilters", ["\"filters\":{\"date\":{\"gt\":\"2019-07-24T12:00:00Z\"}}",
"\"templateKey\":\"marketingCollateral\"",
"\"scope\":\"global\""
])
) { _ in
HTTPStubsResponse(
fileAtPath: TestAssets.path(forResource: "Search200.json")!,
Expand Down Expand Up @@ -97,7 +100,10 @@ class SearchModuleSpecs: QuickSpec {
stub(
condition:
isHost("api.box.com") && isPath("/2.0/search")
&& containsQueryParams(["mdfilters": "[{\"scope\":\"enterprise\",\"templateKey\":\"marketingCollateral\",\"filters\":{\"date\":{\"lt\":\"2019-07-24T12:00:00Z\"}}}]"])
&& compareComplexQueryParam("mdfilters", ["\"filters\":{\"date\":{\"lt\":\"2019-07-24T12:00:00Z\"}}",
"\"templateKey\":\"marketingCollateral\"",
"\"scope\":\"enterprise\""
])
) { _ in
HTTPStubsResponse(
fileAtPath: TestAssets.path(forResource: "Search200.json")!,
Expand Down Expand Up @@ -125,7 +131,10 @@ class SearchModuleSpecs: QuickSpec {
stub(
condition:
isHost("api.box.com") && isPath("/2.0/search")
&& containsQueryParams(["mdfilters": "[{\"scope\":\"enterprise\",\"templateKey\":\"marketingCollateral\",\"filters\":{\"documentType\":\"dataSheet\"}}]"])
&& compareComplexQueryParam("mdfilters", ["\"filters\":{\"documentType\":\"dataSheet\"}",
"\"templateKey\":\"marketingCollateral\"",
"\"scope\":\"enterprise\""
])
) { _ in
HTTPStubsResponse(
fileAtPath: TestAssets.path(forResource: "Search200.json")!,
Expand Down Expand Up @@ -153,7 +162,10 @@ class SearchModuleSpecs: QuickSpec {
stub(
condition:
isHost("api.box.com") && isPath("/2.0/search")
&& containsQueryParams(["mdfilters": "[{\"scope\":\"global\",\"templateKey\":\"marketingCollateral\",\"filters\":{\"documentType\":\"dataSheet\"}}]"])
&& compareComplexQueryParam("mdfilters", ["\"filters\":{\"documentType\":\"dataSheet\"}",
"\"templateKey\":\"marketingCollateral\"",
"\"scope\":\"global\""
])
) { _ in
HTTPStubsResponse(
fileAtPath: TestAssets.path(forResource: "Search200.json")!,
Expand Down

0 comments on commit c9684a7

Please sign in to comment.