Skip to content

Commit c7a3d4f

Browse files
author
Ruben Nine
committed
Using downloads directory for download tests, create directory if missing.
1 parent d78324a commit c7a3d4f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Tests/FilestackSDKTests/FileLinkTests.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import XCTest
1414
class FileLinkTests: XCTestCase {
1515
private let cdnStubConditions = isScheme(Constants.cdnURL.scheme!) && isHost(Constants.cdnURL.host!)
1616
private let apiStubConditions = isScheme(Constants.apiURL.scheme!) && isHost(Constants.apiURL.host!)
17-
private let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
17+
18+
private let downloadsDirectoryURL = try! FileManager.default.url(for: .downloadsDirectory,
19+
in: .userDomainMask,
20+
appropriateFor: nil,
21+
create: true)
1822

1923
override func tearDown() {
2024
super.tearDown()
@@ -273,7 +277,7 @@ class FileLinkTests: XCTestCase {
273277
let fileLink = client.fileLink(for: "MY-HANDLE")
274278
let expectation = self.expectation(description: "request should succeed")
275279

276-
let destinationURL = URL(fileURLWithPath: documentsPath, isDirectory: true)
280+
let destinationURL = downloadsDirectoryURL
277281
.appendingPathComponent(UUID().uuidString)
278282
.appendingPathExtension("jpg")
279283

@@ -319,7 +323,7 @@ class FileLinkTests: XCTestCase {
319323
let expectedRequestURL = Constants.cdnURL.appendingPathComponent("MY-HANDLE")
320324

321325
let expectation = self.expectation(description: "request should fail with a 404")
322-
let destinationURL = URL(fileURLWithPath: documentsPath, isDirectory: true).appendingPathComponent("sample.jpg")
326+
let destinationURL = downloadsDirectoryURL.appendingPathComponent("sample.jpg")
323327
var response: FilestackSDK.DownloadResponse?
324328

325329
fileLink.download(destinationURL: destinationURL) { resp in
@@ -341,7 +345,7 @@ class FileLinkTests: XCTestCase {
341345
let client = Client(apiKey: "MY-API-KEY")
342346
let fileLink = client.fileLink(for: "MY-HANDLE")
343347
let expectation = self.expectation(description: "request should succeed")
344-
let destinationURL = URL(fileURLWithPath: documentsPath, isDirectory: true).appendingPathComponent("sample.jpg")
348+
let destinationURL = downloadsDirectoryURL.appendingPathComponent("sample.jpg")
345349
var response: FilestackSDK.DownloadResponse?
346350

347351
fileLink.download(destinationURL: destinationURL, parameters: ["foo": "123", "bar": "321"]) { resp in
@@ -378,7 +382,7 @@ class FileLinkTests: XCTestCase {
378382

379383
let client = Client(apiKey: "MY-API-KEY")
380384
let fileLink = client.fileLink(for: "MY-HANDLE")
381-
let destinationURL = URL(fileURLWithPath: documentsPath, isDirectory: true).appendingPathComponent("sample.jpg")
385+
let destinationURL = downloadsDirectoryURL.appendingPathComponent("sample.jpg")
382386
let progressExpectation = expectation(description: "request should report progress")
383387

384388
let downloadProgress: ((Progress) -> Void) = { progress in

Tests/FilestackSDKTests/UploadTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ class UploadTests: XCTestCase {
1616
private let sampleFileSize: Int = 200_367
1717
private let sampleFileURL = Helpers.url(forResource: "sample", withExtension: "jpg", subdirectory: "Fixtures")!
1818
private let largeFileURL = Helpers.url(forResource: "large", withExtension: "jpg", subdirectory: "Fixtures")!
19-
20-
private let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
2119
private let chunkSize = 1 * Int(pow(Double(1024), Double(2)))
2220
private let partSize = 8 * Int(pow(Double(1024), Double(2)))
2321
private var currentPart = 1

0 commit comments

Comments
 (0)