Skip to content

Commit 0ea1535

Browse files
authored
Synchronization improvements (#553)
1 parent 4d9200e commit 0ea1535

File tree

124 files changed

+3890
-7226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3890
-7226
lines changed

CareKit/CareKit/Shared/Extensions/OCKAnyEvent+Extension.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ extension OCKAnyEvent {
4040
!newOutcome.values.isEmpty else { return self }
4141

4242
let sortedValues = newOutcome.values.sorted {
43-
guard
44-
let date1 = $0.updatedDate ?? $0.createdDate,
45-
let date2 = $1.updatedDate ?? $0.createdDate else { return false }
46-
return date1 > date2
43+
$0.createdDate > $1.createdDate
4744
}
4845

4946
newOutcome.values = sortedValues

CareKit/CareKit/Shared/Task/Controller/OCKTaskController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ open class OCKTaskController: ObservableObject {
363363
/// - event: The event for which to create the outcome.
364364
/// - values: The outcome values to attach to the outcome.
365365
open func makeOutcomeFor(event: OCKAnyEvent, withValues values: [OCKOutcomeValue]) throws -> OCKAnyOutcome {
366-
guard
367-
let task = event.task as? OCKAnyVersionableTask,
368-
let taskID = task.uuid else { throw OCKTaskControllerError.cannotMakeOutcomeFor(event) }
369-
return OCKOutcome(taskUUID: taskID, taskOccurrenceIndex: event.scheduleEvent.occurrence, values: values)
366+
guard let task = event.task as? OCKAnyVersionableTask else {
367+
throw OCKTaskControllerError.cannotMakeOutcomeFor(event)
368+
}
369+
return OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: event.scheduleEvent.occurrence, values: values)
370370
}
371371

372372
/// Return an event for a particular index path. Customize this method to define the index path behavior used by other functions in this class.
@@ -452,7 +452,7 @@ open class OCKTaskController: ObservableObject {
452452

453453
private extension OCKSynchronizedStoreManager {
454454

455-
func fetchAnyTasksPublisher(query: OCKAnyTaskQuery) -> AnyPublisher<[OCKAnyTask], OCKStoreError> {
455+
func fetchAnyTasksPublisher(query: OCKTaskQuery) -> AnyPublisher<[OCKAnyTask], OCKStoreError> {
456456
Future { [unowned self] completion in
457457
self.store.fetchAnyTasks(query: query, callbackQueue: .main, completion: completion)
458458
}

CareKit/CareKit/iOS/Contact/Controllers/OCKContactController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ open class OCKContactController: ObservableObject {
8383
/// - query: Any contact query describing the contact to be fetched.
8484
///
8585
/// - Note: If the query matches multiple contacts, the first one returned will be used.
86-
open func fetchAndObserveContact(forQuery query: OCKAnyContactQuery) {
86+
open func fetchAndObserveContact(forQuery query: OCKContactQuery) {
8787

8888
// Fetch the contact to set as the view model value
8989
storeManager.store.fetchAnyContacts(query: query, callbackQueue: .main) { [weak self] result in

CareKit/CareKit/iOS/View Updaters/Task/OCKLogTaskView+Updatable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private extension OCKLogTaskView {
4747
clearItems(animated: animated)
4848
} else {
4949
for (index, outcomeValue) in outcomeValues.enumerated() {
50-
guard let date = outcomeValue.updatedDate ?? outcomeValue.createdDate else { continue }
50+
let date = outcomeValue.createdDate
5151
let dateString = OCKLogTaskView.timeFormatter.string(from: date).description
5252

5353
_ = index < items.count ?

CareKit/CareKitTests/Task/TestLabeledValueTaskViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private extension OCKTaskEvents {
121121
let outcome = underlyingValue.map { underlyingValue -> OCKOutcome in
122122
var outcomeValue = OCKOutcomeValue(underlyingValue)
123123
outcomeValue.units = units
124-
return OCKOutcome(taskUUID: task.uuid!, taskOccurrenceIndex: 0, values: [outcomeValue])
124+
return OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: 0, values: [outcomeValue])
125125
}
126126

127127
let scheduleEvent = task.schedule.event(forOccurrenceIndex: 0)!

CareKit/CareKitTests/Task/TestMockTaskEvents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extension OCKTaskEvents {
6262
if eventsHaveOutcomes {
6363
var outcomeValue = OCKOutcomeValue(true)
6464
outcomeValue.createdDate = Date()
65-
outcome = OCKOutcome(taskUUID: task.uuid!, taskOccurrenceIndex: $0, values: [outcomeValue])
65+
outcome = OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: $0, values: [outcomeValue])
6666
}
6767
let event = OCKAnyEvent(task: task, outcome: outcome, scheduleEvent: $1.event(forOccurrenceIndex: $0)!)
6868
taskEvents.append(event: event)

CareKit/CareKitTests/Task/TestNumericProgressTaskViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private extension OCKTaskEvents {
174174
task.instructions = "instructions"
175175

176176
let scheduleEvent = task.schedule.event(forOccurrenceIndex: 0)!
177-
let outcome = OCKOutcome(taskUUID: task.uuid!, taskOccurrenceIndex: 0, values: [.init(outcomeValue)])
177+
let outcome = OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: 0, values: [.init(outcomeValue)])
178178
let event = OCKAnyEvent(task: task, outcome: outcome, scheduleEvent: scheduleEvent)
179179
var taskEvents = OCKTaskEvents()
180180
taskEvents.append(event: event)

CareKit/CareKitTests/Task/TestTaskController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class TestTaskController: XCTestCase {
4343

4444
override func setUp() {
4545
super.setUp()
46-
store = OCKStore(name: "ockstore", type: .inMemory)
46+
store = OCKStore(name: UUID().uuidString, type: .inMemory)
4747
manager = OCKSynchronizedStoreManager(wrapping: store)
4848
cancellables = []
4949
}
@@ -537,7 +537,7 @@ private extension OCKAnyEvent {
537537
task.uuid = taskUUID
538538

539539
let outcome = hasOutcome ?
540-
OCKOutcome(taskUUID: task.uuid!, taskOccurrenceIndex: occurrence, values: []) :
540+
OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: occurrence, values: []) :
541541
nil
542542

543543
let event = OCKAnyEvent(task: task, outcome: outcome, scheduleEvent: schedule.event(forOccurrenceIndex: occurrence)!)
@@ -548,7 +548,7 @@ private extension OCKAnyEvent {
548548
private extension OCKEvent where Task == OCKTask, Outcome == OCKOutcome {
549549
func updatedWithOutcome() -> Self {
550550
var newEvent = self
551-
newEvent.outcome = OCKOutcome(taskUUID: newEvent.task.uuid!, taskOccurrenceIndex: newEvent.scheduleEvent.occurrence, values: [])
551+
newEvent.outcome = OCKOutcome(taskUUID: newEvent.task.uuid, taskOccurrenceIndex: newEvent.scheduleEvent.occurrence, values: [])
552552
return newEvent
553553
}
554554
}

CareKit/CareKitTests/Task/TestTaskEvents.swift

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,6 @@ class TestTaskEvents: XCTestCase {
170170
}
171171
}
172172

173-
func testAppendForEventWithNoTaskIdentity() {
174-
let events: [OCKAnyEvent] = [OCKAnyEvent.mock(taskUUID: nil, occurrence: 0)]
175-
var taskEvents = OCKTaskEvents()
176-
let results = events.map { taskEvents.append(event: $0) }
177-
178-
// Test the underlying data
179-
XCTAssertTrue(taskEvents.isEmpty)
180-
181-
// Test the data returned from the function call
182-
XCTAssertEqual(results.count, 1)
183-
if let result = results.first {
184-
XCTAssertNil(result.0?.id)
185-
XCTAssertFalse(result.1)
186-
}
187-
}
188-
189173
func testRemoveSucceeds() {
190174
let doxylamineUUID = UUID()
191175
let nauseauUUID = UUID()
@@ -251,15 +235,6 @@ class TestTaskEvents: XCTestCase {
251235
XCTAssertNotNil(updatedEvent?.outcome)
252236
}
253237

254-
func testUpdateFailsForEventWithNoTaskIdentity() {
255-
let doxylamineUUID = UUID()
256-
let event = OCKAnyEvent.mock(taskUUID: doxylamineUUID, occurrence: 0)
257-
let newEvent = OCKAnyEvent.mock(taskUUID: nil, occurrence: 0)
258-
var taskEvents = OCKTaskEvents(events: [event])
259-
let updatedEvent = taskEvents.update(event: newEvent)
260-
XCTAssertNil(updatedEvent)
261-
}
262-
263238
func testEventsForTaskReturnsEvents() {
264239
let doxylamineUUID = UUID()
265240
let nauseauUUID = UUID()
@@ -334,14 +309,14 @@ class TestTaskEvents: XCTestCase {
334309

335310
private extension OCKAnyEvent {
336311

337-
static func mock(taskUUID: UUID?, occurrence: Int, hasOutcome: Bool = false) -> Self {
312+
static func mock(taskUUID: UUID, occurrence: Int, hasOutcome: Bool = false) -> Self {
338313
let startOfDay = Calendar.current.startOfDay(for: Date())
339314
let schedule = OCKSchedule.dailyAtTime(hour: 1, minutes: 0, start: startOfDay, end: nil, text: nil)
340-
var task = OCKTask(id: taskUUID?.uuidString ?? "", title: nil, carePlanUUID: nil, schedule: schedule)
315+
var task = OCKTask(id: taskUUID.uuidString, title: nil, carePlanUUID: nil, schedule: schedule)
341316
task.uuid = taskUUID
342317

343318
let outcome = hasOutcome ?
344-
OCKOutcome(taskUUID: task.uuid!, taskOccurrenceIndex: occurrence, values: []) :
319+
OCKOutcome(taskUUID: task.uuid, taskOccurrenceIndex: occurrence, values: []) :
345320
nil
346321

347322
let event = OCKAnyEvent(task: task, outcome: outcome, scheduleEvent: schedule.event(forOccurrenceIndex: occurrence)!)

0 commit comments

Comments
 (0)