91 lines
2.9 KiB
Swift
91 lines
2.9 KiB
Swift
//
|
|
// UploadFileEndpoint+InitTests.swift
|
|
// APIServiceTests
|
|
//
|
|
// Created by Javier Cicchelli on 04/12/2022.
|
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import XCTest
|
|
|
|
@testable import APIService
|
|
|
|
final class UploadFileEndpoint_InitTests: XCTestCase {
|
|
|
|
// MARK: Properties
|
|
|
|
let itemId = UUID().uuidString
|
|
|
|
var endpoint: UploadFileEndpoint!
|
|
var fileName: String!
|
|
var fileData: Data!
|
|
var username: String!
|
|
var password: String!
|
|
|
|
// MARK: Test cases
|
|
|
|
func test_withItemId_someFileNameAndData_andProperUsernameAndPassword() throws {
|
|
// GIVEN
|
|
fileName = "some-filename.txt"
|
|
fileData = "This is some raw text data for testing...".data(using: .utf8)
|
|
username = "username"
|
|
password = "password"
|
|
|
|
// WHEN
|
|
endpoint = .init(
|
|
itemId: itemId,
|
|
fileName: fileName,
|
|
fileData: fileData,
|
|
username: username,
|
|
password: password
|
|
)
|
|
|
|
// THEN
|
|
XCTAssertEqual(endpoint.scheme, .Schemes.http)
|
|
XCTAssertEqual(endpoint.host, .Hosts.default)
|
|
XCTAssertEqual(endpoint.path, "/items/\(itemId)")
|
|
XCTAssertEqual(endpoint.method, .post)
|
|
XCTAssertEqual(endpoint.credentials.username, username)
|
|
XCTAssertEqual(endpoint.credentials.password, password)
|
|
XCTAssertEqual(endpoint.headers, [
|
|
.Header.Keys.contentType: .Header.Values.contentTypeOctet,
|
|
.Header.Keys.contentDisposition: "attachment;filename*=utf-8''" + fileName
|
|
])
|
|
XCTAssertEqual(endpoint.authorizationHeader, [.Header.Keys.authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ="])
|
|
XCTAssertEqual(endpoint.body, fileData)
|
|
}
|
|
|
|
func test_withItemId_someFileNameAndData_andEmptyUsernameOrPassword() throws {
|
|
// GIVEN
|
|
fileName = "some-filename.txt"
|
|
fileData = "This is some raw text data for testing...".data(using: .utf8)
|
|
username = "username"
|
|
password = ""
|
|
|
|
// WHEN
|
|
endpoint = .init(
|
|
itemId: itemId,
|
|
fileName: fileName,
|
|
fileData: fileData,
|
|
username: username,
|
|
password: password
|
|
)
|
|
|
|
// THEN
|
|
XCTAssertEqual(endpoint.scheme, .Schemes.http)
|
|
XCTAssertEqual(endpoint.host, .Hosts.default)
|
|
XCTAssertEqual(endpoint.path, "/items/\(itemId)")
|
|
XCTAssertEqual(endpoint.method, .post)
|
|
XCTAssertEqual(endpoint.credentials.username, username)
|
|
XCTAssertEqual(endpoint.credentials.password, password)
|
|
XCTAssertEqual(endpoint.headers, [
|
|
.Header.Keys.contentType: .Header.Values.contentTypeOctet,
|
|
.Header.Keys.contentDisposition: "attachment;filename*=utf-8''" + fileName
|
|
])
|
|
XCTAssertEqual(endpoint.authorizationHeader, [:])
|
|
XCTAssertEqual(endpoint.body, fileData)
|
|
}
|
|
|
|
}
|