wrote test cases for the 3 endpoints based on what they return
Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
dc25bd490d
commit
16bdd05082
@ -6,17 +6,44 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Testing
|
import Testing
|
||||||
|
import XCTest
|
||||||
|
|
||||||
@testable import EmployeeDirectory
|
@testable import EmployeeDirectory
|
||||||
|
|
||||||
struct EmployeeDirectoryTests {
|
struct EmployeeDirectoryTests {
|
||||||
|
|
||||||
@Test func getEmployeesValid() async throws {
|
@Test func getEmployeesValid() async throws {
|
||||||
let employees = try await EmployeeService().getEmployees()
|
do {
|
||||||
#expect(employees.count == 11)
|
let wrapper = try await EmployeeService().getEmployees(.production)
|
||||||
|
#expect(wrapper.employees.count == 11)
|
||||||
|
} catch {
|
||||||
|
XCTFail("Unexpected error: \(error)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test func getEmployeesInValid() async throws {
|
@Test func getEmployeesMalformed() async throws {
|
||||||
let employees = try await EmployeeService().getEmployees()
|
do {
|
||||||
#expect(employees.count == 11)
|
let wrapper = try await EmployeeService().getEmployees(.malformed)
|
||||||
|
XCTFail("Expected to throw, but got \(wrapper.employees.count) employees")
|
||||||
|
} catch let error as NetworkServiceError {
|
||||||
|
switch error {
|
||||||
|
case .invalidResponse:
|
||||||
|
XCTAssertTrue(true, "Correctly threw invalidResponse error")
|
||||||
|
default:
|
||||||
|
XCTFail("Expected NetworkServiceError.invalidResponse, but got \(error)")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
XCTFail("Unexpected error: \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test func getEmployeesEmpty() async throws {
|
||||||
|
do {
|
||||||
|
let wrapper = try await EmployeeService().getEmployees(.empty)
|
||||||
|
#expect(wrapper.employees.count == 0)
|
||||||
|
} catch {
|
||||||
|
XCTFail("Unexpected error: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user