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/TrunkSizeTests.swift
Michael Housh b359a3317f
All checks were successful
CI / Linux Tests (push) Successful in 5m33s
feat: Adds trunk size database tests.
2026-01-30 16:52:12 -05:00

68 lines
1.7 KiB
Swift

import DatabaseClient
import Dependencies
import Foundation
import ManualDCore
import Testing
@Suite
struct TrunkSizeTests {
@Test
func happyPath() async throws {
try await withTestUserAndProject { _, project in
@Dependency(\.database) var database
let room = try await database.rooms.create(
.init(
projectID: project.id, name: "Test", heatingLoad: 12345, coolingTotal: 12345,
coolingSensible: nil, registerCount: 5)
)
let trunk = try await database.trunkSizes.create(
.init(
projectID: project.id,
type: .supply,
rooms: [room.id: [1, 2, 3]],
height: 8,
name: "Test Trunk"
)
)
let fetched = try await database.trunkSizes.fetch(project.id)
#expect(fetched == [trunk])
let got = try await database.trunkSizes.get(trunk.id)
#expect(got == trunk)
let updated = try await database.trunkSizes.update(
trunk.id, .init(type: .return)
)
#expect(updated.type == .return)
#expect(updated.id == trunk.id)
try await database.trunkSizes.delete(trunk.id)
}
}
@Test
func notFound() async throws {
try await withTestUserAndProject { _, project in
@Dependency(\.database.trunkSizes) var trunks
await #expect(throws: NotFoundError.self) {
try await trunks.create(
.init(projectID: project.id, type: .supply, rooms: [UUID(0): [1]])
)
}
await #expect(throws: NotFoundError.self) {
try await trunks.delete(UUID(0))
}
await #expect(throws: NotFoundError.self) {
try await trunks.update(UUID(0), .init(type: .return))
}
}
}
}