feat: Adds equipment info database tests.
All checks were successful
CI / Linux Tests (push) Successful in 5m26s
All checks were successful
CI / Linux Tests (push) Successful in 5m26s
This commit is contained in:
@@ -9,10 +9,10 @@ struct ComponentLossTests {
|
||||
|
||||
@Test
|
||||
func happyPaths() async throws {
|
||||
try await withTestUser { user in
|
||||
try await withTestUserAndProject { user, project in
|
||||
@Dependency(\.database) var database
|
||||
|
||||
let project = try await database.projects.create(user.id, .mock)
|
||||
// let project = try await database.projects.create(user.id, .mock)
|
||||
|
||||
let componentLoss = try await database.componentLosses.create(
|
||||
.init(projectID: project.id, name: "Test", value: 0.2)
|
||||
|
||||
54
Tests/DatabaseClientTests/EquipmentTests.swift
Normal file
54
Tests/DatabaseClientTests/EquipmentTests.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
import DatabaseClient
|
||||
import Dependencies
|
||||
import Foundation
|
||||
import ManualDCore
|
||||
import Testing
|
||||
|
||||
@Suite
|
||||
struct EquipmentTests {
|
||||
|
||||
@Test
|
||||
func happyPath() async throws {
|
||||
try await withTestUserAndProject { user, project in
|
||||
@Dependency(\.database) var database
|
||||
|
||||
let equipment = try await database.equipment.create(
|
||||
.init(projectID: project.id, heatingCFM: 1000, coolingCFM: 1000)
|
||||
)
|
||||
|
||||
let fetched = try await database.equipment.fetch(project.id)
|
||||
#expect(fetched == equipment)
|
||||
|
||||
let got = try await database.equipment.get(equipment.id)
|
||||
#expect(got == equipment)
|
||||
|
||||
let updated = try await database.equipment.update(
|
||||
equipment.id, .init(heatingCFM: 900)
|
||||
)
|
||||
#expect(updated.heatingCFM == 900)
|
||||
#expect(updated.id == equipment.id)
|
||||
|
||||
try await database.equipment.delete(equipment.id)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
func notFound() async throws {
|
||||
try await withTestUserAndProject { _, project in
|
||||
@Dependency(\.database.equipment) var equipment
|
||||
|
||||
let fetched = try await equipment.fetch(project.id)
|
||||
#expect(fetched == nil)
|
||||
|
||||
await #expect(throws: NotFoundError.self) {
|
||||
try await equipment.delete(UUID(0))
|
||||
}
|
||||
|
||||
await #expect(throws: NotFoundError.self) {
|
||||
try await equipment.update(UUID(0), .init(staticPressure: 0.3))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,6 +54,22 @@ func withTestUser(
|
||||
}
|
||||
}
|
||||
|
||||
/// Set's up the database and a test user for running tests that require a
|
||||
/// a user.
|
||||
func withTestUserAndProject(
|
||||
setupDependencies: (inout DependencyValues) -> Void = { _ in },
|
||||
operation: (User, Project) async throws -> Void
|
||||
) async throws {
|
||||
try await withDatabase(setupDependencies: setupDependencies) {
|
||||
@Dependency(\.database) var database
|
||||
let user = try await database.users.create(
|
||||
.init(email: "testy@example.com", password: "super-secret", confirmPassword: "super-secret")
|
||||
)
|
||||
let project = try await database.projects.create(user.id, .mock)
|
||||
try await operation(user, project)
|
||||
}
|
||||
}
|
||||
|
||||
extension Project.Create {
|
||||
|
||||
static let mock = Self(
|
||||
|
||||
Reference in New Issue
Block a user