feat: Adds component loss database tests.
All checks were successful
CI / Linux Tests (push) Successful in 5m26s
All checks were successful
CI / Linux Tests (push) Successful in 5m26s
This commit is contained in:
53
Tests/DatabaseClientTests/ComponentLossTests.swift
Normal file
53
Tests/DatabaseClientTests/ComponentLossTests.swift
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import DatabaseClient
|
||||||
|
import Dependencies
|
||||||
|
import Foundation
|
||||||
|
import ManualDCore
|
||||||
|
import Testing
|
||||||
|
|
||||||
|
@Suite
|
||||||
|
struct ComponentLossTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func happyPaths() async throws {
|
||||||
|
try await withTestUser { user in
|
||||||
|
@Dependency(\.database) var database
|
||||||
|
|
||||||
|
let project = try await database.projects.create(user.id, .mock)
|
||||||
|
|
||||||
|
let componentLoss = try await database.componentLosses.create(
|
||||||
|
.init(projectID: project.id, name: "Test", value: 0.2)
|
||||||
|
)
|
||||||
|
|
||||||
|
let fetched = try await database.componentLosses.fetch(project.id)
|
||||||
|
#expect(fetched == [componentLoss])
|
||||||
|
|
||||||
|
let got = try await database.componentLosses.get(componentLoss.id)
|
||||||
|
#expect(got == componentLoss)
|
||||||
|
|
||||||
|
let updated = try await database.componentLosses.update(
|
||||||
|
componentLoss.id, .init(name: "Updated", value: nil)
|
||||||
|
)
|
||||||
|
#expect(updated.id == componentLoss.id)
|
||||||
|
#expect(updated.value == componentLoss.value)
|
||||||
|
#expect(updated.name == "Updated")
|
||||||
|
|
||||||
|
try await database.componentLosses.delete(componentLoss.id)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
func notFound() async throws {
|
||||||
|
try await withDatabase {
|
||||||
|
@Dependency(\.database.componentLosses) var componentLosses
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await componentLosses.delete(UUID(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
await #expect(throws: NotFoundError.self) {
|
||||||
|
try await componentLosses.update(UUID(0), .init(name: "Updated"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,3 +53,15 @@ func withTestUser(
|
|||||||
try await operation(user)
|
try await operation(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Project.Create {
|
||||||
|
|
||||||
|
static let mock = Self(
|
||||||
|
name: "Testy McTestface",
|
||||||
|
streetAddress: "1234 Sesame St",
|
||||||
|
city: "Nowhere",
|
||||||
|
state: "MN",
|
||||||
|
zipCode: "55555",
|
||||||
|
sensibleHeatRatio: 0.83
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -152,15 +152,3 @@ struct ProjectTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Project.Create {
|
|
||||||
|
|
||||||
static let mock = Self(
|
|
||||||
name: "Testy McTestface",
|
|
||||||
streetAddress: "1234 Sesame St",
|
|
||||||
city: "Nowhere",
|
|
||||||
state: "MN",
|
|
||||||
zipCode: "55555",
|
|
||||||
sensibleHeatRatio: 0.83
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user