-
Notifications
You must be signed in to change notification settings - Fork 465
Expand file tree
/
Copy pathTestStore+Tasks.swift
More file actions
454 lines (371 loc) · 21.6 KB
/
Copy pathTestStore+Tasks.swift
File metadata and controls
454 lines (371 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
/*
Copyright (c) 2016-2025, Apple Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder(s) nor the names of any contributors
may be used to endorse or promote products derived from this software without
specific prior written permission. No license is granted to the trademarks of
the copyright holders even if such marks are included in this software.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@testable import CareKitStore
import HealthKit
import XCTest
class TestStoreTasks: XCTestCase {
var store: OCKStore!
override func setUp() {
super.setUp()
store = OCKStore(name: UUID().uuidString, type: .inMemory)
}
// MARK: Insertion
func testAddTask() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil, targetValues: [OCKOutcomeValue(11.1)])
var task = OCKTask(id: "squats", title: "Front Squats", carePlanUUID: nil, schedule: schedule)
task = try await store.addTask(task)
XCTAssertNotNil(task.uuid)
XCTAssertNotNil(task.schemaVersion)
}
func testScheduleDurationIsPersisted() async throws {
let schedule = OCKSchedule.dailyAtTime(hour: 8, minutes: 0, start: Date(), end: nil, text: nil, duration: .seconds(123), targetValues: [])
var task = OCKTask(id: "lunges", title: "Lunges", carePlanUUID: nil, schedule: schedule)
task = try await store.addTask(task)
XCTAssert(task.schedule.elements.allSatisfy { $0.duration == .seconds(123) })
}
func testAddTaskFailsIfIdentifierAlreadyExists() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task = OCKTask(id: "exercise", title: "Push Ups", carePlanUUID: nil, schedule: schedule)
try await store.addTask(task)
do {
try await store.addTask(task)
XCTFail("Expected to fail")
} catch {
// no-op
}
}
func testAllDaySchedulesArePersistedCorrectly() async throws {
let element = OCKScheduleElement(start: Date(), end: nil, interval: DateComponents(day: 1), duration: .allDay)
let schedule = OCKSchedule(composing: [element])
var task = OCKTask(id: "benadryl", title: "Benadryl", carePlanUUID: nil, schedule: schedule)
task = try await store.addTask(task)
guard let fetchedElement = task.schedule.elements.first else { XCTFail("Bad schedule"); return }
XCTAssertEqual(fetchedElement.duration, .allDay)
}
// MARK: Querying
func testQueryTaskByIdentifier() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task1 = OCKTask(id: "squats", title: "Front Squats", carePlanUUID: nil, schedule: schedule)
let task2 = OCKTask(id: "lunges", title: "Forward Lunges", carePlanUUID: nil, schedule: schedule)
try await store.addTasks([task1, task2])
let tasks = try await store.fetchTasks(query: OCKTaskQuery(id: task1.id))
XCTAssertEqual(tasks.count, 1)
XCTAssertEqual(tasks.first?.id, task1.id)
}
func testQueryTaskByCarePlanIdentifier() async throws {
let carePlan = try await store.addCarePlan(OCKCarePlan(id: "plan", title: "Plan", patientUUID: nil))
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task = try await store.addTask(OCKTask(id: "A", title: "Task", carePlanUUID: carePlan.uuid, schedule: schedule))
var query = OCKTaskQuery()
query.carePlanIDs = [carePlan.id]
let fetched = try await store.fetchTasks(query: query)
XCTAssertEqual(fetched, [task])
}
func testQueryTaskByCarePlanVersionID() async throws {
let carePlan = try await store.addCarePlan(OCKCarePlan(id: "plan", title: "Plan", patientUUID: nil))
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task = try await store.addTask(OCKTask(id: "A", title: "Task", carePlanUUID: carePlan.uuid, schedule: schedule))
var query = OCKTaskQuery()
query.carePlanUUIDs = [carePlan.uuid]
let fetched = try await store.fetchTasks(query: query)
XCTAssertEqual(fetched, [task])
}
func testTaskQueryGroupIdentifier() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
var task1 = OCKTask(id: "squats", title: "Front Squats", carePlanUUID: nil, schedule: schedule)
let task2 = OCKTask(id: "lunges", title: "Forward Lunges", carePlanUUID: nil, schedule: schedule)
task1.groupIdentifier = "group1"
try await store.addTasks([task1, task2])
let interval = DateInterval(start: Date(), end: Calendar.current.date(byAdding: .day, value: 2, to: Date())!)
var query = OCKTaskQuery(dateInterval: interval)
query.groupIdentifiers = ["group1"]
let tasks = try await store.fetchTasks(query: query)
XCTAssertEqual(tasks.count, 1)
XCTAssertEqual(tasks.first?.id, task1.id)
}
func testTaskQueryForNilGroupIdentifier() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
var task1 = OCKTask(id: "squats", title: "Front Squats", carePlanUUID: nil, schedule: schedule)
let task2 = OCKTask(id: "lunges", title: "Forward Lunges", carePlanUUID: nil, schedule: schedule)
task1.groupIdentifier = "group1"
try await store.addTasks([task1, task2])
let interval = DateInterval(start: Date(), end: Calendar.current.date(byAdding: .day, value: 2, to: Date())!)
var query = OCKTaskQuery(dateInterval: interval)
query.groupIdentifiers = [nil]
let tasks = try await store.fetchTasks(query: query)
XCTAssertEqual(tasks.count, 1)
XCTAssertEqual(tasks.first?.id, task2.id)
}
func testTaskQueryOrdered() async throws {
let today = Calendar.current.startOfDay(for: Date())
let schedule1 = OCKSchedule.mealTimesEachDay(start: today, end: nil)
let schedule2 = OCKSchedule.mealTimesEachDay(start: today, end: Calendar.current.date(byAdding: .day, value: 1, to: today)!)
let task1 = OCKTask(id: "aa", title: "aa", carePlanUUID: nil, schedule: schedule2)
let task2 = OCKTask(id: "bb", title: "bb", carePlanUUID: nil, schedule: schedule1)
let task3 = OCKTask(id: "cc", title: nil, carePlanUUID: nil, schedule: schedule2)
try await store.addTasks([task1, task2, task3])
let interval = DateInterval(start: Date(), end: Calendar.current.date(byAdding: .day, value: 10, to: today)!)
var query = OCKTaskQuery(dateInterval: interval)
query.sortDescriptors = [.title(ascending: true)]
let fetched = try await store.fetchTasks(query: query)
XCTAssertEqual(fetched.map { $0.title }, [nil, "aa", "bb"])
}
func testTaskQueryLimited() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task1 = OCKTask(id: "a", title: "a", carePlanUUID: nil, schedule: schedule)
let task2 = OCKTask(id: "b", title: "b", carePlanUUID: nil, schedule: schedule)
let task3 = OCKTask(id: "c", title: "c", carePlanUUID: nil, schedule: schedule)
try await store.addTasks([task1, task2, task3])
let interval = DateInterval(start: Date(), end: Calendar.current.date(byAdding: .day, value: 2, to: Date())!)
var query = OCKTaskQuery(dateInterval: interval)
query.sortDescriptors = [.title(ascending: true)]
query.limit = 2
let tasks = try await store.fetchTasks(query: query)
XCTAssertEqual(tasks.map { $0.id }, ["a", "b"])
}
func testTaskQueryTags() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
var task1 = OCKTask(id: "a", title: "a", carePlanUUID: nil, schedule: schedule)
task1.tags = ["A"]
var task2 = OCKTask(id: "b", title: "b", carePlanUUID: nil, schedule: schedule)
task2.tags = ["A", "B"]
var task3 = OCKTask(id: "c", title: "c", carePlanUUID: nil, schedule: schedule)
task3.tags = ["A", "B", "C"]
try await store.addTasks([task1, task2, task3])
let interval = DateInterval(start: Date(), end: Calendar.current.date(byAdding: .day, value: 2, to: Date())!)
var query = OCKTaskQuery(dateInterval: interval)
query.tags = ["B"]
query.sortDescriptors = [.title(ascending: true)]
let fetched = try await store.fetchTasks(query: query)
let titles = fetched.map { $0.title }
XCTAssertEqual(titles, ["b", "c"], "Expected [b, c], but got \(titles)")
}
func testTaskQueryWithNilQueryReturnsAllTasks() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task1 = OCKTask(id: "a", title: "a", carePlanUUID: nil, schedule: schedule)
let task2 = OCKTask(id: "b", title: "b", carePlanUUID: nil, schedule: schedule)
let task3 = OCKTask(id: "c", title: "c", carePlanUUID: nil, schedule: schedule)
try await store.addTasks([task1, task2, task3])
let tasks = try await store.fetchTasks(query: OCKTaskQuery())
XCTAssertEqual(tasks.count, 3)
}
func testQueryTaskByRemoteID() async throws {
var task = OCKTask(id: "A", title: nil, carePlanUUID: nil, schedule: .mealTimesEachDay(start: Date(), end: nil))
task.remoteID = "abc"
task = try await store.addTask(task)
var query = OCKTaskQuery(for: Date())
query.remoteIDs = ["abc"]
let fetched = try await store.fetchTasks(query: query).first
XCTAssertEqual(fetched, task)
}
func testQueryTaskByCarePlanRemoteID() async throws {
var plan = OCKCarePlan(id: "A", title: "B", patientUUID: nil)
plan.remoteID = "abc"
plan = try await store.addCarePlan(plan)
var task = OCKTask(id: "B", title: "C", carePlanUUID: plan.uuid, schedule: .mealTimesEachDay(start: Date(), end: nil))
task = try await store.addTask(task)
var query = OCKTaskQuery(for: Date())
query.carePlanRemoteIDs = ["abc"]
let fetched = try await store.fetchTasks(query: query).first
XCTAssertEqual(fetched, task)
}
// MARK: Versioning
func testUpdateTaskCreateNewVersion() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task = try await store.addTask(OCKTask(id: "meds", title: "Medication", carePlanUUID: nil, schedule: schedule))
let updatedTask = try await store.updateTask(OCKTask(id: "meds", title: "New Medication", carePlanUUID: nil, schedule: schedule))
XCTAssertEqual(updatedTask.title, "New Medication")
XCTAssertEqual(updatedTask.previousVersionUUIDs.first, task.uuid)
}
func testCanFetchEventsWhenCurrentTaskVersionStartsAtSameTimeOrEarlierThanThePreviousVersion() async throws {
let thisMorning = Calendar.current.startOfDay(for: Date())
let aFewDaysAgo = Calendar.current.date(byAdding: .day, value: -4, to: thisMorning)!
let manyDaysAgo = Calendar.current.date(byAdding: .day, value: -10, to: thisMorning)!
let scheduleV1 = OCKSchedule.dailyAtTime(hour: 8, minutes: 0, start: manyDaysAgo, end: nil, text: nil)
let scheduleV2 = OCKSchedule.dailyAtTime(hour: 8, minutes: 0, start: aFewDaysAgo, end: nil, text: nil)
let scheduleV3 = OCKSchedule.dailyAtTime(hour: 8, minutes: 0, start: aFewDaysAgo, end: nil, text: nil)
var nausea = OCKTask(id: "nausea", title: "V1", carePlanUUID: nil, schedule: scheduleV1)
let v1 = try await store.addTask(nausea)
XCTAssertEqual(v1.effectiveDate, scheduleV1.startDate())
nausea.title = "V2"
nausea.schedule = scheduleV2
nausea.effectiveDate = scheduleV2.startDate()
let v2 = try await store.updateTask(nausea)
XCTAssertEqual(v2.effectiveDate, scheduleV2.startDate())
nausea.title = "V3"
nausea.schedule = scheduleV3
nausea.effectiveDate = scheduleV3.startDate()
let v3 = try await store.updateTask(nausea)
XCTAssertEqual(v3.effectiveDate, scheduleV3.startDate())
var query = OCKEventQuery(dateInterval: DateInterval(start: manyDaysAgo, end: thisMorning))
query.taskIDs = ["nausea"]
let events = try await store.fetchEvents(query: query)
XCTAssertEqual(events.count, 10, "Expected 10, but got \(events.count)")
XCTAssertEqual(events.first?.task.title, "V1")
XCTAssertEqual(events.last?.task.title, "V3")
}
func testCannotUpdateTaskIfItResultsInImplicitDataLoss() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task = try await store.addTask(OCKTask(id: "meds", title: "Medication", carePlanUUID: nil, schedule: schedule))
let outcome = OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: 5, values: [OCKOutcomeValue(1)])
try await store.addOutcomes([outcome])
do {
try await store.updateTask(task)
XCTFail("Expected to fail")
} catch {
// no-op
}
}
func testCanUpdateTaskWithOutcomesIfDoesNotCauseDataLoss() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
var task = try await store.addTask(OCKTask(id: "meds", title: "Medication", carePlanUUID: nil, schedule: schedule))
let outcome = OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: 0, values: [OCKOutcomeValue(1)])
try await store.addOutcomes([outcome])
task.effectiveDate = task.schedule[5].start
try await store.updateTask(task)
}
func testQueryUpdatedTasksEvents() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil) // 7:30AM, 12:00PM, 5:30PM
let original = try await store.addTask(OCKTask(id: "meds", title: "Original", carePlanUUID: nil, schedule: schedule))
var updated = original
updated.effectiveDate = schedule[5].start // 5:30PM tomorrow
updated.title = "Updated"
updated = try await store.updateTask(updated)
var query = OCKEventQuery(for: schedule[5].start) // 0:00AM - 23:59.99PM tomorrow
query.taskIDs = ["meds"]
let events = try await store.fetchEvents(query: query)
XCTAssertEqual(events.count, 3)
XCTAssertEqual(events[0].task.uuid, original.uuid)
XCTAssertEqual(events[1].task.uuid, original.uuid)
XCTAssertEqual(events[2].task.uuid, updated.uuid)
}
func testUpdateFailsForUnsavedTasks() async {
let task = OCKTask(id: "meds", title: "Medication", carePlanUUID: nil, schedule: .mealTimesEachDay(start: Date(), end: nil))
do {
try await store.updateTask(task)
XCTFail("Expected to fail")
} catch {
// no-op
}
}
func testVersioningReturnsOldVersionForOldQueryRange() async throws {
let today = Calendar.current.startOfDay(for: Date())
let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: today)!
let lastWeek = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: today)!
let schedule1 = OCKSchedule.mealTimesEachDay(start: lastWeek, end: nil, targetValues: [OCKOutcomeValue(11.1)])
let task1 = OCKTask(id: "squats", title: "Front Squats", carePlanUUID: nil, schedule: schedule1)
let schedule2 = OCKSchedule.mealTimesEachDay(start: tomorrow, end: nil)
let task2 = OCKTask(id: "lunges", title: "Forward Lunges", carePlanUUID: nil, schedule: schedule2)
try await store.addTasks([task1, task2])
let tasks = try await store.fetchTasks(query: OCKTaskQuery(for: Date()))
XCTAssertEqual(tasks.count, 1)
XCTAssertEqual(tasks.first?.id, task1.id)
}
func testTaskQueryOnPastDateReturnsPastVersionOfATask() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let dateA = Date().addingTimeInterval(-100)
var taskA = OCKTask(id: "A", title: "a", carePlanUUID: nil, schedule: schedule)
taskA.effectiveDate = dateA
taskA = try await store.addTask(taskA)
let dateB = dateA.addingTimeInterval(100)
var taskB = OCKTask(id: "A", title: "b", carePlanUUID: nil, schedule: schedule)
taskB.effectiveDate = dateB
taskB = try await store.updateTask(taskB)
let interval = DateInterval(start: dateA.addingTimeInterval(10), end: dateB.addingTimeInterval(-10))
let query = OCKTaskQuery(dateInterval: interval)
let fetched = try await store.fetchTasks(query: query)
XCTAssertEqual(fetched.count, 1, "Expected to get 1 task, but got \(fetched.count)")
XCTAssertEqual(fetched.first?.title, taskA.title)
}
func testFetchTaskByIdConvenienceMethodReturnsNewestVersionOfTask() async throws {
let coordinator = OCKStoreCoordinator()
let store = OCKStore(name: "test", type: .inMemory)
coordinator.attach(store: store)
let schedule = OCKSchedule.dailyAtTime(hour: 0, minutes: 0, start: Date(), end: nil, text: nil)
var taskV1 = OCKTask(id: "task", title: "V1", carePlanUUID: nil, schedule: schedule)
taskV1 = try await store.addTask(taskV1)
var taskV2 = taskV1
taskV2.title = "V2"
taskV2 = try await store.updateTask(taskV2)
let task = try await store.fetchTask(withID: "task")
XCTAssertEqual(task.title, taskV2.title)
}
func testFetchAnyTaskByIdConvenienceMethodReturnsNewestVersionOfTask() async throws {
let coordinator = OCKStoreCoordinator()
let store = OCKStore(name: "test", type: .inMemory)
coordinator.attach(store: store)
let schedule = OCKSchedule.dailyAtTime(hour: 0, minutes: 0, start: Date(), end: nil, text: nil)
var taskV1 = OCKTask(id: "task", title: "V1", carePlanUUID: nil, schedule: schedule)
taskV1 = try await store.addTask(taskV1)
var taskV2 = taskV1
taskV2.title = "V2"
taskV2 = try await store.updateTask(taskV2)
let fetchedTask = try await store.fetchAnyTask(withID: "task")
XCTAssertEqual(fetchedTask.title, taskV2.title)
}
func testTaskQueryStartingExactlyOnEffectiveDateOfNewVersion() async throws {
let schedule = OCKSchedule.dailyAtTime(hour: 0, minutes: 0, start: Date(), end: nil, text: nil)
let query = OCKTaskQuery(dateInterval: DateInterval(start: schedule[5].start, end: schedule[5].end))
var task = try await store.addTask(OCKTask(id: "meds", title: "Medication", carePlanUUID: nil, schedule: schedule))
task.effectiveDate = task.schedule[5].start
task = try await store.updateTask(task)
let fetched = try await store.fetchTasks(query: query)
XCTAssertEqual(fetched.first, task)
}
func testTaskQuerySpanningVersionsReturnsNewestVersionOnly() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let dateA = Date().addingTimeInterval(-100)
var taskA = OCKTask(id: "A", title: "a", carePlanUUID: nil, schedule: schedule)
taskA.effectiveDate = dateA
taskA = try await store.addTask(OCKTask(id: "A", title: "a", carePlanUUID: nil, schedule: schedule))
let dateB = Date().addingTimeInterval(100)
var taskB = OCKTask(id: "A", title: "b", carePlanUUID: nil, schedule: schedule)
taskB.effectiveDate = dateB
taskB = try await store.updateTask(taskB)
let interval = DateInterval(start: dateA.addingTimeInterval(10), end: dateB.addingTimeInterval(10))
let query = OCKTaskQuery(dateInterval: interval)
let fetched = try await store.fetchTasks(query: query)
XCTAssertEqual(fetched.count, 1, "Expected to get 1 task, but got \(fetched.count)")
XCTAssertEqual(fetched.first?.title, taskB.title, "Expected title to be \(taskB.title ?? "nil"), but got \(fetched.first?.title ?? "nil")")
}
// MARK: Deletion
func testDeleteTask() async throws {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task = try await store.addTask(OCKTask(id: "meds", title: "Medication", carePlanUUID: nil, schedule: schedule))
try await store.deleteTask(task)
let fetched = try await store.fetchTasks(query: .init(for: Date()))
XCTAssert(fetched.isEmpty)
}
func testDeleteTaskFailsIfTaskDoesntExist() async {
let schedule = OCKSchedule.mealTimesEachDay(start: Date(), end: nil)
let task = OCKTask(id: "meds", title: "Medication", carePlanUUID: nil, schedule: schedule)
do {
try await store.deleteTask(task)
XCTFail("Expected to fail")
} catch {
// no-op
}
}
}