Compare commits
3 Commits
0b78950d14
...
b359a3317f
| Author | SHA1 | Date | |
|---|---|---|---|
|
b359a3317f
|
|||
|
e0ec15b91e
|
|||
|
44a0964181
|
@@ -27,6 +27,9 @@ extension DatabaseClient.Rooms: TestDependencyKey {
|
|||||||
model.rectangularSizes?.removeAll {
|
model.rectangularSizes?.removeAll {
|
||||||
$0.id == rectangularDuctID
|
$0.id == rectangularDuctID
|
||||||
}
|
}
|
||||||
|
if model.rectangularSizes?.count == 0 {
|
||||||
|
model.rectangularSizes = nil
|
||||||
|
}
|
||||||
if model.hasChanges {
|
if model.hasChanges {
|
||||||
try await model.save(on: database)
|
try await model.save(on: database)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,9 @@ extension DatabaseClient.TrunkSizes: TestDependencyKey {
|
|||||||
id: trunk.requireID(),
|
id: trunk.requireID(),
|
||||||
projectID: trunk.$project.id,
|
projectID: trunk.$project.id,
|
||||||
type: .init(rawValue: trunk.type)!,
|
type: .init(rawValue: trunk.type)!,
|
||||||
rooms: roomProxies
|
rooms: roomProxies,
|
||||||
|
height: trunk.height,
|
||||||
|
name: trunk.name
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
delete: { id in
|
delete: { id in
|
||||||
@@ -198,9 +200,6 @@ final class TrunkRoomModel: Model, @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func toDTO() throws -> TrunkSize.RoomProxy {
|
func toDTO() throws -> TrunkSize.RoomProxy {
|
||||||
// guard let room = try await RoomModel.find($room.id, on: database) else {
|
|
||||||
// throw NotFoundError()
|
|
||||||
// }
|
|
||||||
return .init(
|
return .init(
|
||||||
room: try room.toDTO(),
|
room: try room.toDTO(),
|
||||||
registers: registers
|
registers: registers
|
||||||
@@ -248,19 +247,6 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func toDTO() throws -> TrunkSize {
|
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]()) {
|
let rooms = try rooms.reduce(into: [TrunkSize.RoomProxy]()) {
|
||||||
$0.append(try $1.toDTO())
|
$0.append(try $1.toDTO())
|
||||||
}
|
}
|
||||||
@@ -341,16 +327,9 @@ final class TrunkModel: Model, @unchecked Sendable {
|
|||||||
extension Array where Element == TrunkModel {
|
extension Array where Element == TrunkModel {
|
||||||
|
|
||||||
func toDTO() throws -> [TrunkSize] {
|
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]()) {
|
return try reduce(into: [TrunkSize]()) {
|
||||||
$0.append(try $1.toDTO())
|
$0.append(try $1.toDTO())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
79
Tests/DatabaseClientTests/EquivalentLengthTests.swift
Normal file
79
Tests/DatabaseClientTests/EquivalentLengthTests.swift
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import DatabaseClient
|
||||||
|
import Dependencies
|
||||||
|
import Foundation
|
||||||
|
import ManualDCore
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@Suite
|
||||||
|
struct EquivalentLengthTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func happyPath() async throws {
|
||||||
|
try await withTestUserAndProject { user, project in
|
||||||
|
@Dependency(\.database.equivalentLengths) var equivalentLengths
|
||||||
|
|
||||||
|
let equivalentLength = try await equivalentLengths.create(
|
||||||
|
.init(
|
||||||
|
projectID: project.id,
|
||||||
|
name: "Test",
|
||||||
|
type: .supply,
|
||||||
|
straightLengths: [10],
|
||||||
|
groups: [
|
||||||
|
.init(group: 1, letter: "a", value: 20),
|
||||||
|
.init(group: 2, letter: "a", value: 30, quantity: 2),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
let fetched = try await equivalentLengths.fetch(project.id)
|
||||||
|
#expect(fetched == [equivalentLength])
|
||||||
|
|
||||||
|
let got = try await equivalentLengths.get(equivalentLength.id)
|
||||||
|
#expect(got == equivalentLength)
|
||||||
|
|
||||||
|
var max = try await equivalentLengths.fetchMax(project.id)
|
||||||
|
#expect(max.supply == equivalentLength)
|
||||||
|
#expect(max.return == nil)
|
||||||
|
|
||||||
|
let returnLength = try await equivalentLengths.create(
|
||||||
|
.init(
|
||||||
|
projectID: project.id,
|
||||||
|
name: "Test",
|
||||||
|
type: .return,
|
||||||
|
straightLengths: [10],
|
||||||
|
groups: [
|
||||||
|
.init(group: 1, letter: "a", value: 20),
|
||||||
|
.init(group: 2, letter: "a", value: 30, quantity: 2),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
max = try await equivalentLengths.fetchMax(project.id)
|
||||||
|
#expect(max.supply == equivalentLength)
|
||||||
|
#expect(max.return == returnLength)
|
||||||
|
|
||||||
|
let updated = try await equivalentLengths.update(
|
||||||
|
equivalentLength.id, .init(name: "Supply Test")
|
||||||
|
)
|
||||||
|
#expect(updated.name == "Supply Test")
|
||||||
|
#expect(updated.id == equivalentLength.id)
|
||||||
|
|
||||||
|
try await equivalentLengths.delete(equivalentLength.id)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func notFound() async throws {
|
||||||
|
try await withDatabase {
|
||||||
|
@Dependency(\.database.equivalentLengths) var equivalentLengths
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await equivalentLengths.delete(UUID(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await equivalentLengths.update(UUID(0), .init())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
66
Tests/DatabaseClientTests/RoomTests.swift
Normal file
66
Tests/DatabaseClientTests/RoomTests.swift
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import DatabaseClient
|
||||||
|
import Dependencies
|
||||||
|
import Foundation
|
||||||
|
import ManualDCore
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@Suite
|
||||||
|
struct RoomTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func happyPath() async throws {
|
||||||
|
try await withTestUserAndProject { _, project in
|
||||||
|
@Dependency(\.database.rooms) var rooms
|
||||||
|
|
||||||
|
let room = try await rooms.create(
|
||||||
|
.init(projectID: project.id, name: "Test", heatingLoad: 1234, coolingTotal: 1234)
|
||||||
|
)
|
||||||
|
|
||||||
|
let fetched = try await rooms.fetch(project.id)
|
||||||
|
#expect(fetched == [room])
|
||||||
|
|
||||||
|
let got = try await rooms.get(room.id)
|
||||||
|
#expect(got == room)
|
||||||
|
|
||||||
|
let updated = try await rooms.update(
|
||||||
|
room.id,
|
||||||
|
.init(rectangularSizes: [.init(id: UUID(0), register: 1, height: 8)])
|
||||||
|
)
|
||||||
|
#expect(updated.id == room.id)
|
||||||
|
|
||||||
|
let updatedSize = try await rooms.updateRectangularSize(
|
||||||
|
room.id, .init(id: UUID(0), register: 1, height: 10)
|
||||||
|
)
|
||||||
|
#expect(updatedSize.id == room.id)
|
||||||
|
|
||||||
|
let deletedSize = try await rooms.deleteRectangularSize(room.id, UUID(0))
|
||||||
|
#expect(deletedSize.rectangularSizes == nil)
|
||||||
|
|
||||||
|
try await rooms.delete(room.id)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func notFound() async throws {
|
||||||
|
try await withDatabase {
|
||||||
|
@Dependency(\.database.rooms) var rooms
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await rooms.delete(UUID(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await rooms.deleteRectangularSize(UUID(0), UUID(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await rooms.update(UUID(0), .init())
|
||||||
|
}
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await rooms.updateRectangularSize(UUID(0), .init(height: 8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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