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 Testing
|
||||||
import XCTest
|
|
||||||
|
|
||||||
@testable import EmployeeDirectory
|
@testable import EmployeeDirectory
|
||||||
|
|
||||||
@ -14,36 +13,57 @@ struct EmployeeDirectoryTests {
|
|||||||
|
|
||||||
@Test func getEmployeesValid() async throws {
|
@Test func getEmployeesValid() async throws {
|
||||||
do {
|
do {
|
||||||
let wrapper = try await EmployeeService().getEmployees(.production)
|
let wrapper = try await EmployeeService.shared.getEmployees(.production)
|
||||||
#expect(wrapper.employees.count == 11)
|
#expect(wrapper.employees.count == 11)
|
||||||
} catch {
|
} catch {
|
||||||
XCTFail("Unexpected error: \(error)")
|
#expect(Bool(false), "Unexpected error: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func getEmployeesMalformed() async throws {
|
@Test func getEmployeesMalformed() async throws {
|
||||||
do {
|
do {
|
||||||
let wrapper = try await EmployeeService().getEmployees(.malformed)
|
_ = try await EmployeeService.shared.getEmployees(.malformed)
|
||||||
XCTFail("Expected to throw, but got \(wrapper.employees.count) employees")
|
#expect(Bool(false), "Expected invalidResponse error, but no error was thrown")
|
||||||
} catch let error as NetworkServiceError {
|
} catch let error as NetworkServiceError {
|
||||||
switch error {
|
switch error {
|
||||||
case .invalidResponse:
|
case .decodingError(let decodingError):
|
||||||
XCTAssertTrue(true, "Correctly threw invalidResponse error")
|
#expect(Bool(true), "Expected NetworkServiceError.decodingError, but got \(decodingError)")
|
||||||
default:
|
default:
|
||||||
XCTFail("Expected NetworkServiceError.invalidResponse, but got \(error)")
|
#expect(Bool(false), "Expected NetworkServiceError.decodingError, but got \(error)")
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
XCTFail("Unexpected error: \(error)")
|
#expect(Bool(false), "Unexpected error: \(error)")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func getEmployeesEmpty() async throws {
|
@Test func getEmployeesEmpty() async throws {
|
||||||
do {
|
do {
|
||||||
let wrapper = try await EmployeeService().getEmployees(.empty)
|
let wrapper = try await EmployeeService.shared.getEmployees(.empty)
|
||||||
#expect(wrapper.employees.count == 0)
|
#expect(wrapper.employees.count == 0)
|
||||||
} catch {
|
} 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