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/ComponentLossTests.swift
Michael Housh 9276f88426
All checks were successful
CI / Linux Tests (push) Successful in 6m28s
feat: Updates to use swift-validations for database.
2026-02-01 00:55:44 -05:00

69 lines
1.9 KiB
Swift

import Dependencies
import Foundation
import ManualDCore
import Testing
@testable import DatabaseClient
@Suite
struct ComponentLossTests {
@Test
func happyPaths() async throws {
try await withTestUserAndProject { user, project 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"))
}
}
}
@Test(
arguments: [
ComponentLossModel(name: "", value: 0.2, projectID: UUID(0)),
ComponentLossModel(name: "Foo", value: -0.2, projectID: UUID(0)),
ComponentLossModel(name: "Foo", value: 1.2, projectID: UUID(0)),
ComponentLossModel(name: "", value: -0.2, projectID: UUID(0)),
]
)
func validations(model: ComponentLossModel) {
#expect(throws: (any Error).self) {
try model.validate()
}
}
}