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:
@@ -37,7 +37,9 @@ extension DatabaseClient.TrunkSizes: TestDependencyKey {
|
||||
id: trunk.requireID(),
|
||||
projectID: trunk.$project.id,
|
||||
type: .init(rawValue: trunk.type)!,
|
||||
rooms: roomProxies
|
||||
rooms: roomProxies,
|
||||
height: trunk.height,
|
||||
name: trunk.name
|
||||
)
|
||||
},
|
||||
delete: { id in
|
||||
@@ -198,9 +200,6 @@ final class TrunkRoomModel: Model, @unchecked Sendable {
|
||||
}
|
||||
|
||||
func toDTO() throws -> TrunkSize.RoomProxy {
|
||||
// guard let room = try await RoomModel.find($room.id, on: database) else {
|
||||
// throw NotFoundError()
|
||||
// }
|
||||
return .init(
|
||||
room: try room.toDTO(),
|
||||
registers: registers
|
||||
@@ -248,19 +247,6 @@ final class TrunkModel: Model, @unchecked Sendable {
|
||||
}
|
||||
|
||||
func toDTO() throws -> TrunkSize {
|
||||
// let rooms = try await withThrowingTaskGroup(of: TrunkSize.RoomProxy.self) { group in
|
||||
// for room in self.rooms {
|
||||
// group.addTask {
|
||||
// try await room.toDTO(on: database)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return try await group.reduce(into: [TrunkSize.RoomProxy]()) {
|
||||
// $0.append($1)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
let rooms = try rooms.reduce(into: [TrunkSize.RoomProxy]()) {
|
||||
$0.append(try $1.toDTO())
|
||||
}
|
||||
@@ -341,16 +327,9 @@ final class TrunkModel: Model, @unchecked Sendable {
|
||||
extension Array where Element == TrunkModel {
|
||||
|
||||
func toDTO() throws -> [TrunkSize] {
|
||||
// try await withThrowingTaskGroup(of: TrunkSize.self) { group in
|
||||
// for model in self {
|
||||
// group.addTask {
|
||||
// try await model.toDTO(on: database)
|
||||
// }
|
||||
// }
|
||||
|
||||
return try reduce(into: [TrunkSize]()) {
|
||||
$0.append(try $1.toDTO())
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
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