This repository has been archived on 2026-02-12. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
swift-duct-calc/Tests/DatabaseClientTests/EquipmentTests.swift
Michael Housh 9276f88426
All checks were successful
CI / Linux Tests (push) Successful in 6m28s
feat: Updates to use swift-validations for database.
2026-02-01 00:55:44 -05:00

70 lines
1.9 KiB
Swift

import Dependencies
import Foundation
import ManualDCore
import Testing
@testable import DatabaseClient
@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))
}
}
}
@Test(
arguments: [
EquipmentModel(staticPressure: -1, heatingCFM: 1000, coolingCFM: 1000, projectID: UUID(0)),
EquipmentModel(staticPressure: 0.5, heatingCFM: -1, coolingCFM: 1000, projectID: UUID(0)),
EquipmentModel(staticPressure: 0.5, heatingCFM: 1000, coolingCFM: -1000, projectID: UUID(0)),
EquipmentModel(staticPressure: 1.1, heatingCFM: 1000, coolingCFM: -1000, projectID: UUID(0)),
]
)
func validations(model: EquipmentModel) {
#expect(throws: (any Error).self) {
try model.validate()
}
}
}