Skip to content
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
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
4 changes: 3 additions & 1 deletion IntegrationTests/Base/QuickSpec+RetentionPolicies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ extension QuickSpec {
type: RetentionPolicyType = .finite,
length: Int? = 1,
dispositionAction: DispositionAction = .permanentlyDelete,
canOwnerExtendRetention: Bool = false,
callback: @escaping (RetentionPolicy) -> Void
) {
waitUntil(timeout: .seconds(Constants.Timeout.default)) { done in
client.retentionPolicy.create(
name: name,
type: type,
length: length,
dispositionAction: dispositionAction
dispositionAction: dispositionAction,
canOwnerExtendRetention: canOwnerExtendRetention
) { result in
switch result {
case let .success(retention):
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTests/FileModuleIntegrationSpecs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class FileModuleIntegrationSpecs: QuickSpec {

beforeEach {
createFolder(client: client, name: NameGenerator.getUniqueFolderName(), parentId: rootFolder.id) { createdFolder in folder = createdFolder }
createRetention(client: client, name: NameGenerator.getUniqueName(for: "retention")) { createdRetention in retentionPolicy = createdRetention }
createRetention(client: client, name: NameGenerator.getUniqueName(for: "retention"), canOwnerExtendRetention: true) { createdRetention in retentionPolicy = createdRetention }
assignRetention(client: client, retention: retentionPolicy, assignedContentId: folder?.id) { _ in }
uploadFile(client: client, fileName: IntegrationTestResources.smallPdf.fileName, toFolder: folder?.id) { uploadedFile in file = uploadedFile }
}
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