Fix test infrastructure for Rooms feature and improve testability

- Update Plant test fixtures to use roomID instead of deprecated location
- Add URLDataFetcher protocol to ImageCache for dependency injection
- Update ImageCacheTests to use protocol-based mock instead of URLSession subclass
- Add missing cancelReminders(for:plantID:) method to MockNotificationService
- Add Equatable conformance to ImageCacheError for test assertions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-01-23 14:55:50 -06:00
parent 7786a40ae0
commit 08ced7dbbb
5 changed files with 89 additions and 43 deletions

View File

@@ -26,6 +26,7 @@ final actor MockNotificationService: NotificationServiceProtocol {
private(set) var scheduleReminderCallCount = 0
private(set) var cancelReminderCallCount = 0
private(set) var cancelAllRemindersCallCount = 0
private(set) var cancelRemindersForTypeCallCount = 0
private(set) var updateBadgeCountCallCount = 0
private(set) var getPendingNotificationsCallCount = 0
private(set) var removeAllDeliveredNotificationsCallCount = 0
@@ -50,6 +51,8 @@ final actor MockNotificationService: NotificationServiceProtocol {
private(set) var lastScheduledPlantID: UUID?
private(set) var lastCancelledTaskID: UUID?
private(set) var lastCancelledAllPlantID: UUID?
private(set) var lastCancelledTaskType: CareTaskType?
private(set) var lastCancelledTaskTypePlantID: UUID?
private(set) var lastBadgeCount: Int?
// MARK: - NotificationServiceProtocol
@@ -100,6 +103,20 @@ final actor MockNotificationService: NotificationServiceProtocol {
}
}
func cancelReminders(for taskType: CareTaskType, plantID: UUID) async {
cancelRemindersForTypeCallCount += 1
lastCancelledTaskType = taskType
lastCancelledTaskTypePlantID = plantID
// Remove all reminders matching this task type and plant
let keysToRemove = scheduledReminders.filter {
$0.value.plantID == plantID && $0.value.task.type == taskType
}.map { $0.key }
for key in keysToRemove {
scheduledReminders.removeValue(forKey: key)
}
}
func updateBadgeCount(_ count: Int) async {
updateBadgeCountCallCount += 1
lastBadgeCount = count
@@ -125,6 +142,7 @@ final actor MockNotificationService: NotificationServiceProtocol {
scheduleReminderCallCount = 0
cancelReminderCallCount = 0
cancelAllRemindersCallCount = 0
cancelRemindersForTypeCallCount = 0
updateBadgeCountCallCount = 0
getPendingNotificationsCallCount = 0
removeAllDeliveredNotificationsCallCount = 0
@@ -139,6 +157,8 @@ final actor MockNotificationService: NotificationServiceProtocol {
lastScheduledPlantID = nil
lastCancelledTaskID = nil
lastCancelledAllPlantID = nil
lastCancelledTaskType = nil
lastCancelledTaskTypePlantID = nil
lastBadgeCount = nil
}