updated test cases for new Testing Framework macros.
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
6f7a43d15e
commit
8efd109a46
@ -6,7 +6,6 @@
|
||||
//
|
||||
|
||||
import Testing
|
||||
import XCTest
|
||||
|
||||
@testable import EmployeeDirectory
|
||||
|
||||
@ -14,36 +13,57 @@ struct EmployeeDirectoryTests {
|
||||
|
||||
@Test func getEmployeesValid() async throws {
|
||||
do {
|
||||
let wrapper = try await EmployeeService().getEmployees(.production)
|
||||
let wrapper = try await EmployeeService.shared.getEmployees(.production)
|
||||
#expect(wrapper.employees.count == 11)
|
||||
} catch {
|
||||
XCTFail("Unexpected error: \(error)")
|
||||
#expect(Bool(false), "Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func getEmployeesMalformed() async throws {
|
||||
do {
|
||||
let wrapper = try await EmployeeService().getEmployees(.malformed)
|
||||
XCTFail("Expected to throw, but got \(wrapper.employees.count) employees")
|
||||
_ = try await EmployeeService.shared.getEmployees(.malformed)
|
||||
#expect(Bool(false), "Expected invalidResponse error, but no error was thrown")
|
||||
} catch let error as NetworkServiceError {
|
||||
switch error {
|
||||
case .invalidResponse:
|
||||
XCTAssertTrue(true, "Correctly threw invalidResponse error")
|
||||
case .decodingError(let decodingError):
|
||||
#expect(Bool(true), "Expected NetworkServiceError.decodingError, but got \(decodingError)")
|
||||
default:
|
||||
XCTFail("Expected NetworkServiceError.invalidResponse, but got \(error)")
|
||||
#expect(Bool(false), "Expected NetworkServiceError.decodingError, but got \(error)")
|
||||
}
|
||||
} catch {
|
||||
XCTFail("Unexpected error: \(error)")
|
||||
#expect(Bool(false), "Unexpected error: \(error)")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test func getEmployeesEmpty() async throws {
|
||||
do {
|
||||
let wrapper = try await EmployeeService().getEmployees(.empty)
|
||||
let wrapper = try await EmployeeService.shared.getEmployees(.empty)
|
||||
#expect(wrapper.employees.count == 0)
|
||||
} catch {
|
||||
XCTFail("Unexpected error: \(error)")
|
||||
#expect(Bool(false), "Unexpected error: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Testing extension since this isn't needed in the code.
|
||||
extension NetworkServiceError: @retroactive Equatable {
|
||||
public static func == (lhs: NetworkServiceError, rhs: NetworkServiceError) -> Bool {
|
||||
switch (lhs, rhs) {
|
||||
case (.invalidResponse, .invalidResponse):
|
||||
return true
|
||||
case (.invalidURL, .invalidURL):
|
||||
return true
|
||||
case (.decodingError(let lhsError), .decodingError(let rhsError)):
|
||||
return lhsError.localizedDescription == rhsError.localizedDescription
|
||||
case (.networkError(let lhsError), .networkError(let rhsError)):
|
||||
return lhsError.code == rhsError.code
|
||||
case (.unknownError(let lhsError), .unknownError(let rhsError)):
|
||||
return lhsError.localizedDescription == rhsError.localizedDescription
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user