Skip to content

Commit

Permalink
Added upload test for multipart form data for custom boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed Mar 27, 2019
1 parent 9dc80ef commit 0351aeb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Tests/UploadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,39 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
}
}

func testThatCustomBoundaryCanBeSetWhenUploadingMultipartFormData() throws {
// Given
let urlRequest = try URLRequest(url: "https://httpbin.org/post", method: .post)
let uploadData = Data("upload_data".utf8)

let formData = MultipartFormData(fileManager: .default, boundary: "custom-test-boundary")
formData.append(uploadData, withName: "upload_data")

let expectation = self.expectation(description: "multipart form data upload should succeed")
var response: DataResponse<Data?>?

// When
AF.upload(multipartFormData: formData, with: urlRequest).response { resp in
response = resp
expectation.fulfill()
}

waitForExpectations(timeout: timeout, handler: nil)

// Then
XCTAssertNotNil(response?.request)
XCTAssertNotNil(response?.response)
XCTAssertNotNil(response?.data)
XCTAssertNil(response?.error)

if let request = response?.request, let contentType = request.value(forHTTPHeaderField: "Content-Type") {
XCTAssertEqual(contentType, formData.contentType)
XCTAssertTrue(contentType.contains("boundary=custom-test-boundary"))
} else {
XCTFail("Content-Type header value should not be nil")
}
}

func testThatUploadingMultipartFormDataSucceedsWithDefaultParameters() {
// Given
let urlString = "https://httpbin.org/post"
Expand Down

0 comments on commit 0351aeb

Please sign in to comment.