feat: Adds trunk size database tests.
All checks were successful
CI / Linux Tests (push) Successful in 5m33s
All checks were successful
CI / Linux Tests (push) Successful in 5m33s
This commit is contained in:
67
Tests/DatabaseClientTests/TrunkSizeTests.swift
Normal file
67
Tests/DatabaseClientTests/TrunkSizeTests.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user