```
refactor: 重命名项目名称从"体己"到"康康" 将整个项目的目录结构从"体己"重命名为"康康",包括所有源代码文件、 资源文件、测试文件以及Xcode项目配置文件。此更改涉及项目中所有的 文件路径和应用入口点(App/TijiApp.swift → App/KangkangApp.swift)。 ```
This commit is contained in:
79
康康Tests/ModelsSchemaTests.swift
Normal file
79
康康Tests/ModelsSchemaTests.swift
Normal file
@@ -0,0 +1,79 @@
|
||||
import Testing
|
||||
import SwiftData
|
||||
import Foundation
|
||||
@testable import 体己
|
||||
|
||||
struct ModelsSchemaTests {
|
||||
|
||||
private func makeContainer() throws -> ModelContainer {
|
||||
let schema = Schema([
|
||||
Indicator.self,
|
||||
Report.self,
|
||||
DiaryEntry.self,
|
||||
Asset.self,
|
||||
ChatTurn.self,
|
||||
])
|
||||
let config = ModelConfiguration(schema: schema, isStoredInMemoryOnly: true)
|
||||
return try ModelContainer(for: schema, configurations: [config])
|
||||
}
|
||||
|
||||
@Test func insertIndicatorWithReportRelationship() throws {
|
||||
let container = try makeContainer()
|
||||
let ctx = ModelContext(container)
|
||||
|
||||
let report = Report(title: "春检", type: .checkup, reportDate: .now)
|
||||
let indicator = Indicator(
|
||||
name: "ALT",
|
||||
value: "32",
|
||||
unit: "U/L",
|
||||
range: "9-50",
|
||||
status: .normal,
|
||||
report: report
|
||||
)
|
||||
ctx.insert(report)
|
||||
ctx.insert(indicator)
|
||||
try ctx.save()
|
||||
|
||||
#expect(report.indicators.count == 1)
|
||||
#expect(indicator.report?.title == "春检")
|
||||
}
|
||||
|
||||
@Test func cascadeDeleteReportRemovesIndicators() throws {
|
||||
let container = try makeContainer()
|
||||
let ctx = ModelContext(container)
|
||||
|
||||
let report = Report(title: "春检", type: .checkup, reportDate: .now)
|
||||
let indicator = Indicator(
|
||||
name: "ALT", value: "32", unit: "U/L", range: "9-50",
|
||||
status: .normal, report: report
|
||||
)
|
||||
ctx.insert(report)
|
||||
ctx.insert(indicator)
|
||||
try ctx.save()
|
||||
|
||||
ctx.delete(report)
|
||||
try ctx.save()
|
||||
|
||||
let remaining = try ctx.fetch(FetchDescriptor<Indicator>())
|
||||
#expect(remaining.isEmpty)
|
||||
}
|
||||
|
||||
@Test func chatTurnPersistsReferencedIDs() throws {
|
||||
let container = try makeContainer()
|
||||
let ctx = ModelContext(container)
|
||||
|
||||
let turn = ChatTurn(
|
||||
question: "我的 LDL 怎么样?",
|
||||
answer: "近 3 个月 LDL 偏高 [1]",
|
||||
referencedIndicatorIDs: ["abc"],
|
||||
referencedReportIDs: [],
|
||||
decodeRate: 24.3
|
||||
)
|
||||
ctx.insert(turn)
|
||||
try ctx.save()
|
||||
|
||||
let all = try ctx.fetch(FetchDescriptor<ChatTurn>())
|
||||
#expect(all.count == 1)
|
||||
#expect(all.first?.referencedIndicatorIDs == ["abc"])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user